brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.5 KiB · e669900 Raw
302 lines · cpp
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 %s4//5// Test with serialization:6// RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations -emit-pch -o %t %s7// 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 %s11 12int TestLocation13__attribute__((unused));14// CHECK:      VarDecl{{.*}}TestLocation15// CHECK-NEXT:   UnusedAttr 0x{{[^ ]*}} <line:[[@LINE-2]]:16>16 17int TestIndent18__attribute__((unused));19// CHECK:      {{^}}VarDecl{{.*TestIndent[^()]*$}}20// CHECK-NEXT: {{^}}`-UnusedAttr{{[^()]*$}}21 22void TestAttributedStmt() {23  switch (1) {24  case 1:25    [[clang::fallthrough]];26  case 2:27    ;28  }29}30// CHECK:      FunctionDecl{{.*}}TestAttributedStmt31// CHECK:      AttributedStmt32// CHECK-NEXT:   FallThroughAttr33// CHECK-NEXT:   NullStmt34 35[[clang::warn_unused_result]] int TestCXX11DeclAttr();36// CHECK:      FunctionDecl{{.*}}TestCXX11DeclAttr37// CHECK-NEXT:   WarnUnusedResultAttr38 39int TestAlignedNull __attribute__((aligned));40// CHECK:      VarDecl{{.*}}TestAlignedNull41// CHECK-NEXT:   AlignedAttr {{.*}} aligned42// CHECK-NEXT:     <<<NULL>>>43 44int TestAlignedExpr __attribute__((aligned(4)));45// CHECK:      VarDecl{{.*}}TestAlignedExpr46// CHECK-NEXT:   AlignedAttr {{.*}} aligned47// CHECK-NEXT:     ConstantExpr48// CHECK-NEXT:       value: Int 449// CHECK-NEXT:       IntegerLiteral50 51int TestEnum __attribute__((visibility("default")));52// CHECK:      VarDecl{{.*}}TestEnum53// CHECK-NEXT:   VisibilityAttr{{.*}} Default54 55class __attribute__((lockable)) Mutex {56} mu1, mu2;57int TestExpr __attribute__((guarded_by(mu1)));58// CHECK:      VarDecl{{.*}}TestExpr59// CHECK-NEXT:   GuardedByAttr60// CHECK-NEXT:     DeclRefExpr{{.*}}mu161 62class Mutex TestVariadicExpr __attribute__((acquired_after(mu1, mu2)));63// CHECK:      VarDecl{{.*}}TestVariadicExpr64// CHECK:        AcquiredAfterAttr65// CHECK-NEXT:     DeclRefExpr{{.*}}mu166// CHECK-NEXT:     DeclRefExpr{{.*}}mu267 68void function1(void *) {69  int TestFunction __attribute__((cleanup(function1)));70}71// CHECK:      VarDecl{{.*}}TestFunction72// CHECK-NEXT:   CleanupAttr{{.*}} Function{{.*}}function173 74void TestIdentifier(void *, int)75__attribute__((pointer_with_type_tag(ident1,1,2)));76// CHECK: FunctionDecl{{.*}}TestIdentifier77// CHECK:   ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag ident178 79void TestBool(void *, int)80__attribute__((pointer_with_type_tag(bool1,1,2)));81// CHECK: FunctionDecl{{.*}}TestBool82// CHECK:   ArgumentWithTypeTagAttr{{.*}}pointer_with_type_tag bool1 1 2 IsPointer83 84void TestUnsigned(void *, int)85__attribute__((pointer_with_type_tag(unsigned1,1,2)));86// CHECK: FunctionDecl{{.*}}TestUnsigned87// CHECK:   ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag unsigned1 1 288 89void TestInt(void) __attribute__((constructor(123)));90// CHECK:      FunctionDecl{{.*}}TestInt91// CHECK-NEXT:   ConstructorAttr92// CHECK-NEXT:   ConstantExpr93// CHECK-NEXT:   value: Int 12394// CHECK-NEXT:   IntegerLiteral{{.*}} 12395 96static int TestString __attribute__((alias("alias1")));97// CHECK:      VarDecl{{.*}}TestString98// CHECK-NEXT:   AliasAttr{{.*}} "alias1"99 100extern struct s1 TestType101__attribute__((type_tag_for_datatype(ident1,int)));102// CHECK:      VarDecl{{.*}}TestType103// CHECK-NEXT:   TypeTagForDatatypeAttr{{.*}} int104 105void TestLabel() {106L: __attribute__((unused)) int i;107// CHECK: LabelStmt{{.*}}'L'108// CHECK: VarDecl{{.*}}i 'int'109// CHECK-NEXT: UnusedAttr{{.*}}110 111M: __attribute(()) int j;112// CHECK: LabelStmt {{.*}} 'M'113// CHECK-NEXT: DeclStmt114// CHECK-NEXT: VarDecl {{.*}} j 'int'115 116N: __attribute(()) ;117// CHECK: LabelStmt {{.*}} 'N'118// CHECK-NEXT: NullStmt119}120 121namespace Test {122extern "C" int printf(const char *format, ...);123// CHECK: FunctionDecl{{.*}}printf124// CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *'125// CHECK-NEXT: BuiltinAttr{{.*}}Implicit126// CHECK-NEXT: FormatAttr{{.*}}Implicit printf 1 2127 128alignas(8) extern int x;129extern int x;130// CHECK: VarDecl{{.*}} x 'int'131// CHECK: VarDecl{{.*}} x 'int'132// CHECK-NEXT: AlignedAttr{{.*}} Inherited133}134 135namespace TestAligns {136 137template<typename...T> struct my_union {138  alignas(T...) char buffer[1024];139};140 141template<typename...T> struct my_union2 {142  _Alignas(T...) char buffer[1024];143};144 145struct alignas(8) A { char c; };146struct alignas(4) B { short s; };147struct C { char a[16]; };148 149// CHECK: ClassTemplateSpecializationDecl {{.*}} struct my_union150// CHECK: CXXRecordDecl {{.*}} implicit struct my_union151// 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'155my_union<A, B, C> my_union_val;156 157// CHECK: ClassTemplateSpecializationDecl {{.*}} struct my_union2158// CHECK: CXXRecordDecl {{.*}} implicit struct my_union2159// 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'163my_union2<A, B, C> my_union2_val;164 165} // namespace TestAligns166 167int __attribute__((cdecl)) TestOne(void), TestTwo(void);168// CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl))169// CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl))170 171void func() {172  auto Test = []() __attribute__((no_thread_safety_analysis)) {};173  // CHECK: CXXMethodDecl{{.*}}operator() 'void () const'174  // CHECK: NoThreadSafetyAnalysisAttr175 176  // Because GNU's noreturn applies to the function type, and this lambda does177  // not have a capture list, the call operator and the function pointer178  // conversion should both be noreturn, but the method should not contain a179  // 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: NoReturnAttr183  // CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn))184}185 186namespace PR20930 {187struct S {188  struct { int Test __attribute__((deprecated)); };189  // CHECK: FieldDecl{{.*}}Test 'int'190  // CHECK-NEXT: DeprecatedAttr191};192 193void f() {194  S s;195  s.Test = 1;196  // CHECK: IndirectFieldDecl{{.*}}Test 'int'197  // CHECK: DeprecatedAttr198}199}200 201struct __attribute__((objc_bridge_related(NSParagraphStyle,,))) TestBridgedRef;202// CHECK: CXXRecordDecl{{.*}} struct TestBridgedRef203// CHECK-NEXT: ObjCBridgeRelatedAttr{{.*}} NSParagraphStyle204 205void TestExternalSourceSymbolAttr1()206__attribute__((external_source_symbol(language="Swift", defined_in="module", generated_declaration)));207// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr1208// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration209 210void TestExternalSourceSymbolAttr2()211__attribute__((external_source_symbol(defined_in="module", language="Swift")));212// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr2213// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" ""{{$}}214 215void TestExternalSourceSymbolAttr3()216__attribute__((external_source_symbol(generated_declaration, language="Objective-C++", defined_in="module")));217// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr3218// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Objective-C++" "module" GeneratedDeclaration219 220void TestExternalSourceSymbolAttr4()221__attribute__((external_source_symbol(defined_in="Some external file.cs", generated_declaration, language="C Sharp")));222// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr4223// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "C Sharp" "Some external file.cs" GeneratedDeclaration224 225void TestExternalSourceSymbolAttr5()226__attribute__((external_source_symbol(generated_declaration, defined_in="module", language="Swift")));227// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr5228// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration229 230void TestExternalSourceSymbolAttr6()231__attribute__((external_source_symbol(generated_declaration, defined_in="module", language="Swift", USR="testUSR")));232// CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr6233// CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration "testUSR"234 235namespace TestNoEscape {236  void noescapeFunc(int *p0, __attribute__((noescape)) int *p1) {}237  // CHECK: `-FunctionDecl{{.*}} noescapeFunc 'void (int *, __attribute__((noescape)) int *)'238  // CHECK-NEXT: ParmVarDecl239  // CHECK-NEXT: ParmVarDecl240  // CHECK-NEXT: NoEscapeAttr241}242 243namespace TestSuppress {244  [[gsl::suppress("at-namespace")]];245  // CHECK: NamespaceDecl{{.*}} TestSuppress246  // CHECK-NEXT: EmptyDecl{{.*}}247  // CHECK-NEXT: SuppressAttr{{.*}} at-namespace248  [[gsl::suppress("on-decl")]]249  void TestSuppressFunction();250  // CHECK: FunctionDecl{{.*}} TestSuppressFunction251  // CHECK-NEXT: SuppressAttr{{.*}} on-decl252 253  void f() {254      int *i;255 256      [[gsl::suppress("on-stmt")]] {257      // CHECK: AttributedStmt258      // CHECK-NEXT: SuppressAttr{{.*}} on-stmt259      // CHECK-NEXT: CompoundStmt260        i = reinterpret_cast<int*>(7);261      }262    }263}264 265namespace TestLifetimeCategories {266class [[gsl::Owner(int)]] AOwner{};267// CHECK: CXXRecordDecl{{.*}} class AOwner268// CHECK: OwnerAttr {{.*}} int269class [[gsl::Pointer(int)]] APointer{};270// CHECK: CXXRecordDecl{{.*}} class APointer271// CHECK: PointerAttr {{.*}} int272 273class [[gsl::Pointer]] PointerWithoutArgument{};274// CHECK: CXXRecordDecl{{.*}} class PointerWithoutArgument275// CHECK: PointerAttr276 277class [[gsl::Owner]] OwnerWithoutArgument{};278// CHECK: CXXRecordDecl{{.*}} class OwnerWithoutArgument279// CHECK: OwnerAttr280} // namespace TestLifetimeCategories281 282// Verify the order of attributes in the Ast. It must reflect the order283// in the parsed source.284int mergeAttrTest() __attribute__((deprecated)) __attribute__((warn_unused_result));285int mergeAttrTest() __attribute__((annotate("test")));286int mergeAttrTest() __attribute__((unused,no_thread_safety_analysis));287// CHECK: FunctionDecl{{.*}} mergeAttrTest288// CHECK-NEXT: DeprecatedAttr289// CHECK-NEXT: WarnUnusedResultAttr290 291// CHECK: FunctionDecl{{.*}} mergeAttrTest292// CHECK-NEXT: DeprecatedAttr{{.*}} Inherited293// CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited294// CHECK-NEXT: AnnotateAttr{{.*}}295 296// CHECK: FunctionDecl{{.*}} mergeAttrTest297// CHECK-NEXT: DeprecatedAttr{{.*}} Inherited298// CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited299// CHECK-NEXT: AnnotateAttr{{.*}} Inherited300// CHECK-NEXT: UnusedAttr301// CHECK-NEXT: NoThreadSafetyAnalysisAttr302