ast-dump-attr.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations -ast-dump -ast-dump-filter Test %s | FileCheck --strict-whitespace %s
  2. int TestLocation
  3. __attribute__((unused));
  4. // CHECK: VarDecl{{.*}}TestLocation
  5. // CHECK-NEXT: UnusedAttr 0x{{[^ ]*}} <line:[[@LINE-2]]:16>
  6. int TestIndent
  7. __attribute__((unused));
  8. // CHECK: {{^}}VarDecl{{.*TestIndent[^()]*$}}
  9. // CHECK-NEXT: {{^}}`-UnusedAttr{{[^()]*$}}
  10. void TestAttributedStmt() {
  11. switch (1) {
  12. case 1:
  13. [[clang::fallthrough]];
  14. case 2:
  15. ;
  16. }
  17. }
  18. // CHECK: FunctionDecl{{.*}}TestAttributedStmt
  19. // CHECK: AttributedStmt
  20. // CHECK-NEXT: FallThroughAttr
  21. // CHECK-NEXT: NullStmt
  22. [[clang::warn_unused_result]] int TestCXX11DeclAttr();
  23. // CHECK: FunctionDecl{{.*}}TestCXX11DeclAttr
  24. // CHECK-NEXT: WarnUnusedResultAttr
  25. int TestAlignedNull __attribute__((aligned));
  26. // CHECK: VarDecl{{.*}}TestAlignedNull
  27. // CHECK-NEXT: AlignedAttr {{.*}} aligned
  28. // CHECK-NEXT: <<<NULL>>>
  29. int TestAlignedExpr __attribute__((aligned(4)));
  30. // CHECK: VarDecl{{.*}}TestAlignedExpr
  31. // CHECK-NEXT: AlignedAttr {{.*}} aligned
  32. // CHECK-NEXT: IntegerLiteral
  33. int TestEnum __attribute__((visibility("default")));
  34. // CHECK: VarDecl{{.*}}TestEnum
  35. // CHECK-NEXT: VisibilityAttr{{.*}} Default
  36. class __attribute__((lockable)) Mutex {
  37. } mu1, mu2;
  38. int TestExpr __attribute__((guarded_by(mu1)));
  39. // CHECK: VarDecl{{.*}}TestExpr
  40. // CHECK-NEXT: GuardedByAttr
  41. // CHECK-NEXT: DeclRefExpr{{.*}}mu1
  42. class Mutex TestVariadicExpr __attribute__((acquired_after(mu1, mu2)));
  43. // CHECK: VarDecl{{.*}}TestVariadicExpr
  44. // CHECK: AcquiredAfterAttr
  45. // CHECK-NEXT: DeclRefExpr{{.*}}mu1
  46. // CHECK-NEXT: DeclRefExpr{{.*}}mu2
  47. void function1(void *) {
  48. int TestFunction __attribute__((cleanup(function1)));
  49. }
  50. // CHECK: VarDecl{{.*}}TestFunction
  51. // CHECK-NEXT: CleanupAttr{{.*}} Function{{.*}}function1
  52. void TestIdentifier(void *, int)
  53. __attribute__((pointer_with_type_tag(ident1,1,2)));
  54. // CHECK: FunctionDecl{{.*}}TestIdentifier
  55. // CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag ident1
  56. void TestBool(void *, int)
  57. __attribute__((pointer_with_type_tag(bool1,1,2)));
  58. // CHECK: FunctionDecl{{.*}}TestBool
  59. // CHECK: ArgumentWithTypeTagAttr{{.*}}pointer_with_type_tag bool1 0 1 IsPointer
  60. void TestUnsigned(void *, int)
  61. __attribute__((pointer_with_type_tag(unsigned1,1,2)));
  62. // CHECK: FunctionDecl{{.*}}TestUnsigned
  63. // CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag unsigned1 0 1
  64. void TestInt(void) __attribute__((constructor(123)));
  65. // CHECK: FunctionDecl{{.*}}TestInt
  66. // CHECK-NEXT: ConstructorAttr{{.*}} 123
  67. static int TestString __attribute__((alias("alias1")));
  68. // CHECK: VarDecl{{.*}}TestString
  69. // CHECK-NEXT: AliasAttr{{.*}} "alias1"
  70. extern struct s1 TestType
  71. __attribute__((type_tag_for_datatype(ident1,int)));
  72. // CHECK: VarDecl{{.*}}TestType
  73. // CHECK-NEXT: TypeTagForDatatypeAttr{{.*}} int
  74. void TestLabel() {
  75. L: __attribute__((unused)) int i;
  76. // CHECK: LabelStmt{{.*}}'L'
  77. // CHECK: VarDecl{{.*}}i 'int'
  78. // CHECK-NEXT: UnusedAttr{{.*}}
  79. M: __attribute(()) int j;
  80. // CHECK: LabelStmt {{.*}} 'M'
  81. // CHECK-NEXT: DeclStmt
  82. // CHECK-NEXT: VarDecl {{.*}} j 'int'
  83. N: __attribute(()) ;
  84. // CHECK: LabelStmt {{.*}} 'N'
  85. // CHECK-NEXT: NullStmt
  86. }
  87. namespace Test {
  88. extern "C" int printf(const char *format, ...);
  89. // CHECK: FunctionDecl{{.*}}printf
  90. // CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *'
  91. // CHECK-NEXT: FormatAttr{{.*}}Implicit printf 1 2
  92. alignas(8) extern int x;
  93. extern int x;
  94. // CHECK: VarDecl{{.*}} x 'int'
  95. // CHECK: VarDecl{{.*}} x 'int'
  96. // CHECK-NEXT: AlignedAttr{{.*}} Inherited
  97. }
  98. int __attribute__((cdecl)) TestOne(void), TestTwo(void);
  99. // CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl))
  100. // CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl))
  101. void func() {
  102. auto Test = []() __attribute__((no_thread_safety_analysis)) {};
  103. // CHECK: CXXMethodDecl{{.*}}operator() 'void (void) const'
  104. // CHECK: NoThreadSafetyAnalysisAttr
  105. // Because GNU's noreturn applies to the function type, and this lambda does
  106. // not have a capture list, the call operator and the function pointer
  107. // conversion should both be noreturn, but the method should not contain a
  108. // NoReturnAttr because the attribute applied to the type.
  109. auto Test2 = []() __attribute__((noreturn)) { while(1); };
  110. // CHECK: CXXMethodDecl{{.*}}operator() 'void (void) __attribute__((noreturn)) const'
  111. // CHECK-NOT: NoReturnAttr
  112. // CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn))
  113. }
  114. namespace PR20930 {
  115. struct S {
  116. struct { int Test __attribute__((deprecated)); };
  117. // CHECK: FieldDecl{{.*}}Test 'int'
  118. // CHECK-NEXT: DeprecatedAttr
  119. };
  120. void f() {
  121. S s;
  122. s.Test = 1;
  123. // CHECK: IndirectFieldDecl{{.*}}Test 'int'
  124. // CHECK: DeprecatedAttr
  125. }
  126. }