1 // Test without serialization: 2 // RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations -ast-dump -ast-dump-filter Test %s \ 3 // RUN: | FileCheck --strict-whitespace %s 4 // 5 // Test with serialization: 6 // RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations -emit-pch -o %t %s 7 // RUN: %clang_cc1 -x c++ -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations \ 8 // RUN: -include-pch %t -ast-dump-all -ast-dump-filter Test /dev/null \ 9 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \ 10 // RUN: | FileCheck --strict-whitespace %s 11 12 int TestLocation 13 __attribute__((unused)); 14 // CHECK: VarDecl{{.*}}TestLocation 15 // CHECK-NEXT: UnusedAttr 0x{{[^ ]*}} <line:[[@LINE-2]]:16> 16 17 int TestIndent 18 __attribute__((unused)); 19 // CHECK: {{^}}VarDecl{{.*TestIndent[^()]*$}} 20 // CHECK-NEXT: {{^}}`-UnusedAttr{{[^()]*$}} 21 22 void TestAttributedStmt() { 23 switch (1) { 24 case 1: 25 [[clang::fallthrough]]; 26 case 2: 27 ; 28 } 29 } 30 // CHECK: FunctionDecl{{.*}}TestAttributedStmt 31 // CHECK: AttributedStmt 32 // CHECK-NEXT: FallThroughAttr 33 // CHECK-NEXT: NullStmt 34 35 [[clang::warn_unused_result]] int TestCXX11DeclAttr(); 36 // CHECK: FunctionDecl{{.*}}TestCXX11DeclAttr 37 // CHECK-NEXT: WarnUnusedResultAttr 38 39 int TestAlignedNull __attribute__((aligned)); 40 // CHECK: VarDecl{{.*}}TestAlignedNull 41 // CHECK-NEXT: AlignedAttr {{.*}} aligned 42 // CHECK-NEXT: <<<NULL>>> 43 44 int TestAlignedExpr __attribute__((aligned(4))); 45 // CHECK: VarDecl{{.*}}TestAlignedExpr 46 // CHECK-NEXT: AlignedAttr {{.*}} aligned 47 // CHECK-NEXT: ConstantExpr 48 // CHECK-NEXT: value: Int 4 49 // CHECK-NEXT: IntegerLiteral 50 51 int TestEnum __attribute__((visibility("default"))); 52 // CHECK: VarDecl{{.*}}TestEnum 53 // CHECK-NEXT: VisibilityAttr{{.*}} Default 54 55 class __attribute__((lockable)) Mutex { 56 } mu1, mu2; 57 int TestExpr __attribute__((guarded_by(mu1))); 58 // CHECK: VarDecl{{.*}}TestExpr 59 // CHECK-NEXT: GuardedByAttr 60 // CHECK-NEXT: DeclRefExpr{{.*}}mu1 61 62 class Mutex TestVariadicExpr __attribute__((acquired_after(mu1, mu2))); 63 // CHECK: VarDecl{{.*}}TestVariadicExpr 64 // CHECK: AcquiredAfterAttr 65 // CHECK-NEXT: DeclRefExpr{{.*}}mu1 66 // CHECK-NEXT: DeclRefExpr{{.*}}mu2 67 68 void function1(void *) { 69 int TestFunction __attribute__((cleanup(function1))); 70 } 71 // CHECK: VarDecl{{.*}}TestFunction 72 // CHECK-NEXT: CleanupAttr{{.*}} Function{{.*}}function1 73 74 void TestIdentifier(void *, int) 75 __attribute__((pointer_with_type_tag(ident1,1,2))); 76 // CHECK: FunctionDecl{{.*}}TestIdentifier 77 // CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag ident1 78 79 void TestBool(void *, int) 80 __attribute__((pointer_with_type_tag(bool1,1,2))); 81 // CHECK: FunctionDecl{{.*}}TestBool 82 // CHECK: ArgumentWithTypeTagAttr{{.*}}pointer_with_type_tag bool1 1 2 IsPointer 83 84 void TestUnsigned(void *, int) 85 __attribute__((pointer_with_type_tag(unsigned1,1,2))); 86 // CHECK: FunctionDecl{{.*}}TestUnsigned 87 // CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag unsigned1 1 2 88 89 void TestInt(void) __attribute__((constructor(123))); 90 // CHECK: FunctionDecl{{.*}}TestInt 91 // CHECK-NEXT: ConstructorAttr{{.*}} 123 92 93 static int TestString __attribute__((alias("alias1"))); 94 // CHECK: VarDecl{{.*}}TestString 95 // CHECK-NEXT: AliasAttr{{.*}} "alias1" 96 97 extern struct s1 TestType 98 __attribute__((type_tag_for_datatype(ident1,int))); 99 // CHECK: VarDecl{{.*}}TestType 100 // CHECK-NEXT: TypeTagForDatatypeAttr{{.*}} int 101 102 void TestLabel() { 103 L: __attribute__((unused)) int i; 104 // CHECK: LabelStmt{{.*}}'L' 105 // CHECK: VarDecl{{.*}}i 'int' 106 // CHECK-NEXT: UnusedAttr{{.*}} 107 108 M: __attribute(()) int j; 109 // CHECK: LabelStmt {{.*}} 'M' 110 // CHECK-NEXT: DeclStmt 111 // CHECK-NEXT: VarDecl {{.*}} j 'int' 112 113 N: __attribute(()) ; 114 // CHECK: LabelStmt {{.*}} 'N' 115 // CHECK-NEXT: NullStmt 116 } 117 118 namespace Test { 119 extern "C" int printf(const char *format, ...); 120 // CHECK: FunctionDecl{{.*}}printf 121 // CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *' 122 // CHECK-NEXT: BuiltinAttr{{.*}}Implicit 123 // CHECK-NEXT: FormatAttr{{.*}}Implicit printf 1 2 124 125 alignas(8) extern int x; 126 extern int x; 127 // CHECK: VarDecl{{.*}} x 'int' 128 // CHECK: VarDecl{{.*}} x 'int' 129 // CHECK-NEXT: AlignedAttr{{.*}} Inherited 130 } 131 132 int __attribute__((cdecl)) TestOne(void), TestTwo(void); 133 // CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl)) 134 // CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl)) 135 136 void func() { 137 auto Test = []() __attribute__((no_thread_safety_analysis)) {}; 138 // CHECK: CXXMethodDecl{{.*}}operator() 'void () const' 139 // CHECK: NoThreadSafetyAnalysisAttr 140 141 // Because GNU's noreturn applies to the function type, and this lambda does 142 // not have a capture list, the call operator and the function pointer 143 // conversion should both be noreturn, but the method should not contain a 144 // NoReturnAttr because the attribute applied to the type. 145 auto Test2 = []() __attribute__((noreturn)) { while(1); }; 146 // CHECK: CXXMethodDecl{{.*}}operator() 'void () __attribute__((noreturn)) const' 147 // CHECK-NOT: NoReturnAttr 148 // CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn)) 149 } 150 151 namespace PR20930 { 152 struct S { 153 struct { int Test __attribute__((deprecated)); }; 154 // CHECK: FieldDecl{{.*}}Test 'int' 155 // CHECK-NEXT: DeprecatedAttr 156 }; 157 158 void f() { 159 S s; 160 s.Test = 1; 161 // CHECK: IndirectFieldDecl{{.*}}Test 'int' 162 // CHECK: DeprecatedAttr 163 } 164 } 165 166 struct __attribute__((objc_bridge_related(NSParagraphStyle,,))) TestBridgedRef; 167 // CHECK: CXXRecordDecl{{.*}} struct TestBridgedRef 168 // CHECK-NEXT: ObjCBridgeRelatedAttr{{.*}} NSParagraphStyle 169 170 void TestExternalSourceSymbolAttr1() 171 __attribute__((external_source_symbol(language="Swift", defined_in="module", generated_declaration))); 172 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr1 173 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration 174 175 void TestExternalSourceSymbolAttr2() 176 __attribute__((external_source_symbol(defined_in="module", language="Swift"))); 177 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr2 178 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module"{{$}} 179 180 void TestExternalSourceSymbolAttr3() 181 __attribute__((external_source_symbol(generated_declaration, language="Objective-C++", defined_in="module"))); 182 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr3 183 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Objective-C++" "module" GeneratedDeclaration 184 185 void TestExternalSourceSymbolAttr4() 186 __attribute__((external_source_symbol(defined_in="Some external file.cs", generated_declaration, language="C Sharp"))); 187 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr4 188 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "C Sharp" "Some external file.cs" GeneratedDeclaration 189 190 void TestExternalSourceSymbolAttr5() 191 __attribute__((external_source_symbol(generated_declaration, defined_in="module", language="Swift"))); 192 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr5 193 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration 194 195 namespace TestNoEscape { 196 void noescapeFunc(int *p0, __attribute__((noescape)) int *p1) {} 197 // CHECK: `-FunctionDecl{{.*}} noescapeFunc 'void (int *, __attribute__((noescape)) int *)' 198 // CHECK-NEXT: ParmVarDecl 199 // CHECK-NEXT: ParmVarDecl 200 // CHECK-NEXT: NoEscapeAttr 201 } 202 203 namespace TestSuppress { 204 [[gsl::suppress("at-namespace")]]; 205 // CHECK: NamespaceDecl{{.*}} TestSuppress 206 // CHECK-NEXT: EmptyDecl{{.*}} 207 // CHECK-NEXT: SuppressAttr{{.*}} at-namespace 208 [[gsl::suppress("on-decl")]] 209 void TestSuppressFunction(); 210 // CHECK: FunctionDecl{{.*}} TestSuppressFunction 211 // CHECK-NEXT: SuppressAttr{{.*}} on-decl 212 213 void f() { 214 int *i; 215 216 [[gsl::suppress("on-stmt")]] { 217 // CHECK: AttributedStmt 218 // CHECK-NEXT: SuppressAttr{{.*}} on-stmt 219 // CHECK-NEXT: CompoundStmt 220 i = reinterpret_cast<int*>(7); 221 } 222 } 223 } 224 225 namespace TestLifetimeCategories { 226 class [[gsl::Owner(int)]] AOwner{}; 227 // CHECK: CXXRecordDecl{{.*}} class AOwner 228 // CHECK: OwnerAttr {{.*}} int 229 class [[gsl::Pointer(int)]] APointer{}; 230 // CHECK: CXXRecordDecl{{.*}} class APointer 231 // CHECK: PointerAttr {{.*}} int 232 233 class [[gsl::Pointer]] PointerWithoutArgument{}; 234 // CHECK: CXXRecordDecl{{.*}} class PointerWithoutArgument 235 // CHECK: PointerAttr 236 237 class [[gsl::Owner]] OwnerWithoutArgument{}; 238 // CHECK: CXXRecordDecl{{.*}} class OwnerWithoutArgument 239 // CHECK: OwnerAttr 240 } // namespace TestLifetimeCategories 241 242 // Verify the order of attributes in the Ast. It must reflect the order 243 // in the parsed source. 244 int mergeAttrTest() __attribute__((deprecated)) __attribute__((warn_unused_result)); 245 int mergeAttrTest() __attribute__((annotate("test"))); 246 int mergeAttrTest() __attribute__((unused,no_thread_safety_analysis)); 247 // CHECK: FunctionDecl{{.*}} mergeAttrTest 248 // CHECK-NEXT: DeprecatedAttr 249 // CHECK-NEXT: WarnUnusedResultAttr 250 251 // CHECK: FunctionDecl{{.*}} mergeAttrTest 252 // CHECK-NEXT: DeprecatedAttr{{.*}} Inherited 253 // CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited 254 // CHECK-NEXT: AnnotateAttr{{.*}} 255 256 // CHECK: FunctionDecl{{.*}} mergeAttrTest 257 // CHECK-NEXT: DeprecatedAttr{{.*}} Inherited 258 // CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited 259 // CHECK-NEXT: AnnotateAttr{{.*}} Inherited 260 // CHECK-NEXT: UnusedAttr 261 // CHECK-NEXT: NoThreadSafetyAnalysisAttr 262