1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=namespace" %s | FileCheck --check-prefix=CHECK-NAMESPACE %s
2 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=type_alias" %s | FileCheck --check-prefix=CHECK-TYPE_ALIAS %s
3 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=enum" %s | FileCheck --check-prefix=CHECK-ENUM %s
4 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=enum_constant" %s | FileCheck --check-prefix=CHECK-ENUM_CONSTANT %s
5 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=record" %s | FileCheck --check-prefix=CHECK-RECORD %s
6 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=record(unless(is_union))" %s | FileCheck --check-prefix=CHECK-RECORD_UNLESS_IS_UNION %s
7 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=field" %s | FileCheck --check-prefix=CHECK-FIELD %s
8 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=function" %s | FileCheck --check-prefix=CHECK-FUNCTION %s
9 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=hasType(functionType)" %s | FileCheck --check-prefix=CHECK-HAS_TYPE_FUNCTION_TYPE %s
10 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=function(is_member)" %s | FileCheck --check-prefix=CHECK-FUNCTION_IS_MEMBER %s
11 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=variable" %s | FileCheck --check-prefix=CHECK-VARIABLE %s
12 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=variable(is_global)" %s | FileCheck --check-prefix=CHECK-VARIABLE_IS_GLOBAL %s
13 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=variable(is_parameter)" %s | FileCheck --check-prefix=CHECK-VARIABLE_IS_PARAMETER %s
14 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -ast-dump -ast-dump-filter test "-DSUBJECT=variable(unless(is_parameter))" %s | FileCheck --check-prefix=CHECK-VARIABLE_UNLESS_IS_PARAMETER %s
15 
16 #pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(SUBJECT))
17 
18 namespace testNamespace {
19 // CHECK-NAMESPACE: NamespaceDecl{{.*}} testNamespace
20 // CHECK-NAMESPACE-NEXT: AnnotateAttr{{.*}} "test"
21 
22 typedef int testTypedef;
23 // CHECK-TYPE_ALIAS: TypedefDecl{{.*}} testTypedef
24 // CHECK-TYPE_ALIAS-NEXT: BuiltinType
25 // CHECK-TYPE_ALIAS-NEXT: AnnotateAttr{{.*}} "test"
26 
27 using testTypeAlias = double;
28 // CHECK-TYPE_ALIAS: TypeAliasDecl{{.*}} testTypeAlias
29 // CHECK-TYPE_ALIAS-NEXT: BuiltinType
30 // CHECK-TYPE_ALIAS-NEXT: AnnotateAttr{{.*}} "test"
31 
32 enum testEnum {
33   testEnumCase1,
34   testEnumCase2
35 };
36 // CHECK-ENUM: EnumDecl{{.*}} testEnum
37 // CHECK-ENUM-NEXT: AnnotateAttr{{.*}} "test"
38 // CHECK-ENUM_CONSTANT: EnumConstantDecl{{.*}} testEnumCase1
39 // CHECK-ENUM_CONSTANT-NEXT: AnnotateAttr{{.*}} "test"
40 // CHECK-ENUM_CONSTANT: EnumConstantDecl{{.*}} testEnumCase2
41 // CHECK-ENUM_CONSTANT-NEXT: AnnotateAttr{{.*}} "test"
42 
43 struct testStructRecord {
44   int testStructRecordField;
45 };
46 // CHECK-RECORD: CXXRecordDecl{{.*}} testStructRecord
47 // CHECK-RECORD:   AnnotateAttr{{.*}} "test"
48 // CHECK-RECORD_UNLESS_IS_UNION-LABEL: CXXRecordDecl{{.*}} testStructRecord
49 // CHECK-RECORD_UNLESS_IS_UNION:         AnnotateAttr{{.*}} "test"
50 // CHECK-FIELD: FieldDecl{{.*}} testStructRecordField
51 // CHECK-FIELD-NEXT: AnnotateAttr{{.*}} "test"
52 
53 class testClassRecord {
54   int testClassRecordField;
55 };
56 // CHECK-RECORD: CXXRecordDecl{{.*}} testClassRecord
57 // CHECK-RECORD:   AnnotateAttr{{.*}} "test"
58 // CHECK-RECORD_UNLESS_IS_UNION-LABEL: CXXRecordDecl{{.*}} testClassRecord
59 // CHECK-RECORD_UNLESS_IS_UNION:         AnnotateAttr{{.*}} "test"
60 // CHECK-FIELD: FieldDecl{{.*}} testClassRecordField
61 // CHECK-FIELD-NEXT: AnnotateAttr{{.*}} "test"
62 
63 union testUnionRecord {
64   int testUnionRecordField;
65 };
66 // CHECK-RECORD: CXXRecordDecl{{.*}} testUnionRecord
67 // CHECK-RECORD:   AnnotateAttr{{.*}} "test"
68 // CHECK-RECORD_UNLESS_IS_UNION-LABEL: CXXRecordDecl{{.*}} testUnionRecord
69 // CHECK-RECORD_UNLESS_IS_UNION-NOT: AnnotateAttr{{.*}} "test"
70 // CHECK-FIELD: FieldDecl{{.*}} testUnionRecordField
71 // CHECK-FIELD-NEXT: AnnotateAttr{{.*}} "test"
72 
73 // CHECK-RECORD_UNLESS_IS_UNION-LABEL: CXXRecordDecl
74 void testFunctionDecl();
75 // CHECK-FUNCTION: FunctionDecl{{.*}} testFunctionDecl
76 // CHECK-FUNCTION-NEXT: AnnotateAttr{{.*}} "test"
77 // CHECK-HAS_TYPE_FUNCTION_TYPE: FunctionDecl{{.*}} testFunctionDecl
78 // CHECK-HAS_TYPE_FUNCTION_TYPE-NEXT: AnnotateAttr{{.*}} "test"
79 
testFunctionDecl()80 void testFunctionDecl() { }
81 // CHECK-FUNCTION: FunctionDecl{{.*}} testFunctionDecl
82 // CHECK-FUNCTION-NEXT: CompoundStmt
83 // CHECK-FUNCTION-NEXT: AnnotateAttr{{.*}} "test"
84 // CHECK-HAS_TYPE_FUNCTION_TYPE: FunctionDecl{{.*}} testFunctionDecl
85 // CHECK-HAS_TYPE_FUNCTION_TYPE-NEXT: CompoundStmt
86 // CHECK-HAS_TYPE_FUNCTION_TYPE-NEXT: AnnotateAttr{{.*}} "test"
87 
88 void (*testFunctionVar)();
89 // CHECK-HAS_TYPE_FUNCTION_TYPE: VarDecl{{.*}} testFunctionVar
90 // CHECK-HAS_TYPE_FUNCTION_TYPE-NEXT: AnnotateAttr{{.*}} "test"
91 // 'function' should not apply to variables with a function type!
92 // CHECK-FUNCTION: VarDecl{{.*}} testFunctionVar
93 // CHECK-FUNCTION-NOT: AnnotateAttr{{.*}} "test"
94 
95 class testMethods {
96   testMethods();
97   void testMethod();
98 };
testMethod()99 void testMethods::testMethod() { }
100 void testFunctionNotMethod();
101 // CHECK-FUNCTION-LABEL: CXXConstructorDecl{{.*}} testMethods
102 // CHECK-FUNCTION-NEXT: AnnotateAttr{{.*}} "test"
103 // CHECK-FUNCTION_IS_MEMBER: CXXConstructorDecl{{.*}} testMethods
104 // CHECK-FUNCTION_IS_MEMBER-NEXT: AnnotateAttr{{.*}} "test"
105 // CHECK-HAS_TYPE_FUNCTION_TYPE: CXXConstructorDecl{{.*}} testMethods
106 // CHECK-HAS_TYPE_FUNCTION_TYPE-NEXT: AnnotateAttr{{.*}} "test"
107 // CHECK-FUNCTION: CXXMethodDecl{{.*}} testMethod
108 // CHECK-FUNCTION-NEXT: AnnotateAttr{{.*}} "test"
109 // CHECK-FUNCTION_IS_MEMBER: CXXMethodDecl{{.*}} testMethod
110 // CHECK-FUNCTION_IS_MEMBER-NEXT: AnnotateAttr{{.*}} "test"
111 // CHECK-HAS_TYPE_FUNCTION_TYPE: CXXMethodDecl{{.*}} testMethod
112 // CHECK-HAS_TYPE_FUNCTION_TYPE-NEXT: AnnotateAttr{{.*}} "test"
113 // CHECK-FUNCTION: CXXMethodDecl{{.*}} testMethod
114 // CHECK-FUNCTION-NEXT: CompoundStmt
115 // CHECK-FUNCTION-NEXT: AnnotateAttr{{.*}} "test"
116 // CHECK-FUNCTION_IS_MEMBER: CXXMethodDecl{{.*}} testMethod
117 // CHECK-FUNCTION_IS_MEMBER-NEXT: CompoundStmt
118 // CHECK-CXX_METHOD-NEXT: AnnotateAttr{{.*}} "test"
119 // CHECK-HAS_TYPE_FUNCTION_TYPE: CXXMethodDecl{{.*}} testMethod
120 // CHECK-HAS_TYPE_FUNCTION_TYPE-NEXT: CompoundStmt
121 // CHECK-HAS_TYPE_FUNCTION_TYPE-NEXT: AnnotateAttr{{.*}} "test"
122 // CHECK-FUNCTION_IS_MEMBER: FunctionDecl{{.*}} testFunctionNotMethod
123 // CHECK-FUNCTION_IS_MEMBER-NOT: AnnotateAttr{{.*}} "test"
124 
125 int testVariable;
126 // CHECK-VARIABLE: VarDecl{{.*}} testVariable
127 // CHECK-VARIABLE-NEXT: AnnotateAttr{{.*}} "test"
128 // CHECK-VARIABLE_IS_GLOBAL-LABEL: VarDecl{{.*}} testVariable
129 // CHECK-VARIABLE_IS_GLOBAL-NEXT: AnnotateAttr{{.*}} "test"
130 // CHECK-VARIABLE_IS_PARAMETER-LABEL: VarDecl{{.*}} testVariable
131 // CHECK-VARIABLE_IS_PARAMETER-NOT: AnnotateAttr{{.*}} "test"
132 // CHECK-VARIABLE_UNLESS_IS_PARAMETER-LABEL: VarDecl{{.*}} testVariable
133 // CHECK-VARIABLE_UNLESS_IS_PARAMETER-NEXT: AnnotateAttr{{.*}} "test"
testVarFunction(int testParam)134 void testVarFunction(int testParam) {
135 // CHECK-VARIABLE: VarDecl{{.*}} testParam
136 // CHECK-VARIABLE-NEXT: AnnotateAttr{{.*}} "test"
137 // CHECK-VARIABLE_IS_GLOBAL-LABEL: VarDecl{{.*}} testParam
138 // CHECK-VARIABLE_IS_GLOBAL-NOT: AnnotateAttr{{.*}} "test"
139 // CHECK-VARIABLE_IS_PARAMETER-LABEL: VarDecl{{.*}} testParam
140 // CHECK-VARIABLE_IS_PARAMETER-NEXT: AnnotateAttr{{.*}} "test"
141 // CHECK-VARIABLE_UNLESS_IS_PARAMETER-LABEL: VarDecl{{.*}} testParam
142 // CHECK-VARIABLE_UNLESS_IS_PARAMETER-NOT: AnnotateAttr{{.*}} "test"
143 
144   int testLocalVariable;
145 // CHECK-VARIABLE: VarDecl{{.*}} testLocalVariable
146 // CHECK-VARIABLE-NEXT: AnnotateAttr{{.*}} "test"
147 // CHECK-VARIABLE_IS_GLOBAL-LABEL: VarDecl{{.*}} testLocalVariable
148 // CHECK-VARIABLE_IS_GLOBAL-NOT: AnnotateAttr{{.*}} "test"
149 // CHECK-VARIABLE_IS_PARAMETER-LABEL: VarDecl{{.*}} testLocalVariable
150 // CHECK-VARIABLE_IS_PARAMETER-NOT: AnnotateAttr{{.*}} "test"
151 // CHECK-VARIABLE_UNLESS_IS_PARAMETER-LABEL: VarDecl{{.*}} testLocalVariable
152 // CHECK-VARIABLE_UNLESS_IS_PARAMETER-NEXT: AnnotateAttr{{.*}} "test"
153 }
154 class testVarClass {
155   static int testStaticVar;
156 };
157 // CHECK-VARIABLE: VarDecl{{.*}} testStaticVar
158 // CHECK-VARIABLE-NEXT: AnnotateAttr{{.*}} "test"
159 // CHECK-VARIABLE_IS_GLOBAL-LABEL: VarDecl{{.*}} testStaticVar
160 // CHECK-VARIABLE_IS_GLOBAL-NEXT: AnnotateAttr{{.*}} "test"
161 // CHECK-VARIABLE_IS_PARAMETER-LABEL: VarDecl{{.*}} testStaticVar
162 // CHECK-VARIABLE_IS_PARAMETER-NOT: AnnotateAttr{{.*}} "test"
163 // CHECK-VARIABLE_UNLESS_IS_PARAMETER-LABEL: VarDecl{{.*}} testStaticVar
164 // CHECK-VARIABLE_UNLESS_IS_PARAMETER-NEXT: AnnotateAttr{{.*}} "test"
165 
166 
167 }
168 
169 #pragma clang attribute pop
170