| 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 |
| 92 |
// CHECK-NEXT: ConstantExpr |
| 93 |
// CHECK-NEXT: value: Int 123 |
| 94 |
// CHECK-NEXT: IntegerLiteral{{.*}} 123 |
| 95 |
|
| 96 |
static int TestString __attribute__((alias("alias1"))); |
| 97 |
// CHECK: VarDecl{{.*}}TestString |
| 98 |
// CHECK-NEXT: AliasAttr{{.*}} "alias1" |
| 99 |
|
| 100 |
extern struct s1 TestType |
| 101 |
__attribute__((type_tag_for_datatype(ident1,int))); |
| 102 |
// CHECK: VarDecl{{.*}}TestType |
| 103 |
// CHECK-NEXT: TypeTagForDatatypeAttr{{.*}} int |
| 104 |
|
| 105 |
void TestLabel() { |
| 106 |
L: __attribute__((unused)) int i; |
| 107 |
// CHECK: LabelStmt{{.*}}'L' |
| 108 |
// CHECK: VarDecl{{.*}}i 'int' |
| 109 |
// CHECK-NEXT: UnusedAttr{{.*}} |
| 110 |
|
| 111 |
M: __attribute(()) int j; |
| 112 |
// CHECK: LabelStmt {{.*}} 'M' |
| 113 |
// CHECK-NEXT: DeclStmt |
| 114 |
// CHECK-NEXT: VarDecl {{.*}} j 'int' |
| 115 |
|
| 116 |
N: __attribute(()) ; |
| 117 |
// CHECK: LabelStmt {{.*}} 'N' |
| 118 |
// CHECK-NEXT: NullStmt |
| 119 |
} |
| 120 |
|
| 121 |
namespace Test { |
| 122 |
extern "C" int printf(const char *format, ...); |
| 123 |
// CHECK: FunctionDecl{{.*}}printf |
| 124 |
// CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *' |
| 125 |
// CHECK-NEXT: BuiltinAttr{{.*}}Implicit |
| 126 |
// CHECK-NEXT: FormatAttr{{.*}}Implicit printf 1 2 |
| 127 |
|
| 128 |
alignas(8) extern int x; |
| 129 |
extern int x; |
| 130 |
// CHECK: VarDecl{{.*}} x 'int' |
| 131 |
// CHECK: VarDecl{{.*}} x 'int' |
| 132 |
// CHECK-NEXT: AlignedAttr{{.*}} Inherited |
| 133 |
} |
| 134 |
|
| 135 |
namespace TestAligns { |
| 136 |
|
| 137 |
template<typename...T> struct my_union { |
| 138 |
alignas(T...) char buffer[1024]; |
| 139 |
}; |
| 140 |
|
| 141 |
template<typename...T> struct my_union2 { |
| 142 |
_Alignas(T...) char buffer[1024]; |
| 143 |
}; |
| 144 |
|
| 145 |
struct alignas(8) A { char c; }; |
| 146 |
struct alignas(4) B { short s; }; |
| 147 |
struct C { char a[16]; }; |
| 148 |
|
| 149 |
// CHECK: ClassTemplateSpecializationDecl {{.*}} struct my_union |
| 150 |
// CHECK: CXXRecordDecl {{.*}} implicit struct my_union |
| 151 |
// CHECK: FieldDecl {{.*}} buffer 'char[1024]' |
| 152 |
// CHECK-NEXT: AlignedAttr {{.*}} alignas 'TestAligns::A' |
| 153 |
// CHECK-NEXT: AlignedAttr {{.*}} alignas 'TestAligns::B' |
| 154 |
// CHECK-NEXT: AlignedAttr {{.*}} alignas 'TestAligns::C' |
| 155 |
my_union<A, B, C> my_union_val; |
| 156 |
|
| 157 |
// CHECK: ClassTemplateSpecializationDecl {{.*}} struct my_union2 |
| 158 |
// CHECK: CXXRecordDecl {{.*}} implicit struct my_union2 |
| 159 |
// CHECK: FieldDecl {{.*}} buffer 'char[1024]' |
| 160 |
// CHECK-NEXT: AlignedAttr {{.*}} _Alignas 'TestAligns::A' |
| 161 |
// CHECK-NEXT: AlignedAttr {{.*}} _Alignas 'TestAligns::B' |
| 162 |
// CHECK-NEXT: AlignedAttr {{.*}} _Alignas 'TestAligns::C' |
| 163 |
my_union2<A, B, C> my_union2_val; |
| 164 |
|
| 165 |
} // namespace TestAligns |
| 166 |
|
| 167 |
int __attribute__((cdecl)) TestOne(void), TestTwo(void); |
| 168 |
// CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl)) |
| 169 |
// CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl)) |
| 170 |
|
| 171 |
void func() { |
| 172 |
auto Test = []() __attribute__((no_thread_safety_analysis)) {}; |
| 173 |
// CHECK: CXXMethodDecl{{.*}}operator() 'void () const' |
| 174 |
// CHECK: NoThreadSafetyAnalysisAttr |
| 175 |
|
| 176 |
// Because GNU's noreturn applies to the function type, and this lambda does |
| 177 |
// not have a capture list, the call operator and the function pointer |
| 178 |
// conversion should both be noreturn, but the method should not contain a |
| 179 |
// NoReturnAttr because the attribute applied to the type. |
| 180 |
auto Test2 = []() __attribute__((noreturn)) { while(1); }; |
| 181 |
// CHECK: CXXMethodDecl{{.*}}operator() 'void () __attribute__((noreturn)) const' |
| 182 |
// CHECK-NOT: NoReturnAttr |
| 183 |
// CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn)) |
| 184 |
} |
| 185 |
|
| 186 |
namespace PR20930 { |
| 187 |
struct S { |
| 188 |
struct { int Test __attribute__((deprecated)); }; |
| 189 |
// CHECK: FieldDecl{{.*}}Test 'int' |
| 190 |
// CHECK-NEXT: DeprecatedAttr |
| 191 |
}; |
| 192 |
|
| 193 |
void f() { |
| 194 |
S s; |
| 195 |
s.Test = 1; |
| 196 |
// CHECK: IndirectFieldDecl{{.*}}Test 'int' |
| 197 |
// CHECK: DeprecatedAttr |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
struct __attribute__((objc_bridge_related(NSParagraphStyle,,))) TestBridgedRef; |
| 202 |
// CHECK: CXXRecordDecl{{.*}} struct TestBridgedRef |
| 203 |
// CHECK-NEXT: ObjCBridgeRelatedAttr{{.*}} NSParagraphStyle |
| 204 |
|
| 205 |
void TestExternalSourceSymbolAttr1() |
| 206 |
__attribute__((external_source_symbol(language="Swift", defined_in="module", generated_declaration))); |
| 207 |
// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr1 |
| 208 |
// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration |
| 209 |
|
| 210 |
void TestExternalSourceSymbolAttr2() |
| 211 |
__attribute__((external_source_symbol(defined_in="module", language="Swift"))); |
| 212 |
// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr2 |
| 213 |
// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" ""{{$}} |
| 214 |
|
| 215 |
void TestExternalSourceSymbolAttr3() |
| 216 |
__attribute__((external_source_symbol(generated_declaration, language="Objective-C++", defined_in="module"))); |
| 217 |
// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr3 |
| 218 |
// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Objective-C++" "module" GeneratedDeclaration |
| 219 |
|
| 220 |
void TestExternalSourceSymbolAttr4() |
| 221 |
__attribute__((external_source_symbol(defined_in="Some external file.cs", generated_declaration, language="C Sharp"))); |
| 222 |
// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr4 |
| 223 |
// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "C Sharp" "Some external file.cs" GeneratedDeclaration |
| 224 |
|
| 225 |
void TestExternalSourceSymbolAttr5() |
| 226 |
__attribute__((external_source_symbol(generated_declaration, defined_in="module", language="Swift"))); |
| 227 |
// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr5 |
| 228 |
// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration |
| 229 |
|
| 230 |
void TestExternalSourceSymbolAttr6() |
| 231 |
__attribute__((external_source_symbol(generated_declaration, defined_in="module", language="Swift", USR="testUSR"))); |
| 232 |
// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr6 |
| 233 |
// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration "testUSR" |
| 234 |
|
| 235 |
namespace TestNoEscape { |
| 236 |
void noescapeFunc(int *p0, __attribute__((noescape)) int *p1) {} |
| 237 |
// CHECK: `-FunctionDecl{{.*}} noescapeFunc 'void (int *, __attribute__((noescape)) int *)' |
| 238 |
// CHECK-NEXT: ParmVarDecl |
| 239 |
// CHECK-NEXT: ParmVarDecl |
| 240 |
// CHECK-NEXT: NoEscapeAttr |
| 241 |
} |
| 242 |
|
| 243 |
namespace TestSuppress { |
| 244 |
[[gsl::suppress("at-namespace")]]; |
| 245 |
// CHECK: NamespaceDecl{{.*}} TestSuppress |
| 246 |
// CHECK-NEXT: EmptyDecl{{.*}} |
| 247 |
// CHECK-NEXT: SuppressAttr{{.*}} at-namespace |
| 248 |
[[gsl::suppress("on-decl")]] |
| 249 |
void TestSuppressFunction(); |
| 250 |
// CHECK: FunctionDecl{{.*}} TestSuppressFunction |
| 251 |
// CHECK-NEXT: SuppressAttr{{.*}} on-decl |
| 252 |
|
| 253 |
void f() { |
| 254 |
int *i; |
| 255 |
|
| 256 |
[[gsl::suppress("on-stmt")]] { |
| 257 |
// CHECK: AttributedStmt |
| 258 |
// CHECK-NEXT: SuppressAttr{{.*}} on-stmt |
| 259 |
// CHECK-NEXT: CompoundStmt |
| 260 |
i = reinterpret_cast<int*>(7); |
| 261 |
} |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
namespace TestLifetimeCategories { |
| 266 |
class [[gsl::Owner(int)]] AOwner{}; |
| 267 |
// CHECK: CXXRecordDecl{{.*}} class AOwner |
| 268 |
// CHECK: OwnerAttr {{.*}} int |
| 269 |
class [[gsl::Pointer(int)]] APointer{}; |
| 270 |
// CHECK: CXXRecordDecl{{.*}} class APointer |
| 271 |
// CHECK: PointerAttr {{.*}} int |
| 272 |
|
| 273 |
class [[gsl::Pointer]] PointerWithoutArgument{}; |
| 274 |
// CHECK: CXXRecordDecl{{.*}} class PointerWithoutArgument |
| 275 |
// CHECK: PointerAttr |
| 276 |
|
| 277 |
class [[gsl::Owner]] OwnerWithoutArgument{}; |
| 278 |
// CHECK: CXXRecordDecl{{.*}} class OwnerWithoutArgument |
| 279 |
// CHECK: OwnerAttr |
| 280 |
} // namespace TestLifetimeCategories |
| 281 |
|
| 282 |
// Verify the order of attributes in the Ast. It must reflect the order |
| 283 |
// in the parsed source. |
| 284 |
int mergeAttrTest() __attribute__((deprecated)) __attribute__((warn_unused_result)); |
| 285 |
int mergeAttrTest() __attribute__((annotate("test"))); |
| 286 |
int mergeAttrTest() __attribute__((unused,no_thread_safety_analysis)); |
| 287 |
// CHECK: FunctionDecl{{.*}} mergeAttrTest |
| 288 |
// CHECK-NEXT: DeprecatedAttr |
| 289 |
// CHECK-NEXT: WarnUnusedResultAttr |
| 290 |
|
| 291 |
// CHECK: FunctionDecl{{.*}} mergeAttrTest |
| 292 |
// CHECK-NEXT: DeprecatedAttr{{.*}} Inherited |
| 293 |
// CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited |
| 294 |
// CHECK-NEXT: AnnotateAttr{{.*}} |
| 295 |
|
| 296 |
// CHECK: FunctionDecl{{.*}} mergeAttrTest |
| 297 |
// CHECK-NEXT: DeprecatedAttr{{.*}} Inherited |
| 298 |
// CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited |
| 299 |
// CHECK-NEXT: AnnotateAttr{{.*}} Inherited |
| 300 |
// CHECK-NEXT: UnusedAttr |
| 301 |
// CHECK-NEXT: NoThreadSafetyAnalysisAttr |