From: Aaron Ballman Date: Fri, 30 Nov 2018 14:43:21 +0000 (+0000) Subject: Adding tests for -ast-dump; NFC. X-Git-Tag: llvmorg-8.0.0-rc1~3200 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7278cc7d73f62f2008e813643bd14c99e55d911b;p=platform%2Fupstream%2Fllvm.git Adding tests for -ast-dump; NFC. This adds tests for the majority of the functionality around FunctionDecl and CXXMethodDecl. llvm-svn: 347994 --- diff --git a/clang/test/Misc/ast-dump-funcs.cpp b/clang/test/Misc/ast-dump-funcs.cpp new file mode 100644 index 0000000..cbd430d --- /dev/null +++ b/clang/test/Misc/ast-dump-funcs.cpp @@ -0,0 +1,124 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck -strict-whitespace %s + +struct R { + R() = default; + // CHECK: CXXConstructorDecl 0x{{[^ ]*}} col:3 used constexpr R 'void () noexcept' default trivial + ~R() {} // not trivial + // CHECK: CXXDestructorDecl 0x{{[^ ]*}} col:3 used ~R 'void () noexcept' + R(const R&) = delete; + // CHECK: CXXConstructorDecl 0x{{[^ ]*}} col:3 R 'void (const R &)' delete trivial + R(R&&) = default; + // CHECK: CXXConstructorDecl 0x{{[^ ]*}} col:3 constexpr R 'void (R &&)' default trivial noexcept-unevaluated + + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 implicit operator= 'R &(const R &)' inline default_delete trivial noexcept-unevaluated +}; + +struct S { + int i, j; + R r; + + S() : i(0), j(0) {} + // CHECK: CXXConstructorDecl 0x{{[^ ]*}} col:3 S 'void ()' + // CHECK-NEXT: CXXCtorInitializer Field 0x{{[^ ]*}} 'i' 'int' + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 0 + // CHECK-NEXT: CXXCtorInitializer Field 0x{{[^ ]*}} 'j' 'int' + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 0 + // CHECK-NEXT: CXXCtorInitializer Field 0x{{[^ ]*}} 'r' 'R' + // CHECK-NEXT: CXXConstructExpr 0x{{[^ ]*}} 'R' 'void () noexcept' + // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} + + void a(); + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 a 'void ()' + void b() const; + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 b 'void () const' + void c() volatile; + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 c 'void () volatile' + void d() &; + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 d 'void () &' + void e() &&; + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 e 'void () &&' + virtual void f(float, int = 12); + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:16 f 'void (float, int)' virtual + // CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:23 'float' + // CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:29 'int' cinit + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 12 + + virtual void g() = 0; + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:16 g 'void ()' virtual pure + + // CHECK: CXXConstructorDecl 0x{{[^ ]*}} col:8 implicit S 'void (const S &)' inline default_delete noexcept-unevaluated + // CHECK: CXXConstructorDecl 0x{{[^ ]*}} col:8 implicit constexpr S 'void (S &&)' inline default noexcept-unevaluated + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 implicit operator= 'S &(const S &)' inline default_delete noexcept-unevaluated + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 implicit operator= 'S &(S &&)' inline default_delete noexcept-unevaluated + // CHECK: CXXDestructorDecl 0x{{[^ ]*}} col:8 implicit ~S 'void ()' inline default noexcept-unevaluated +}; + +struct T : S { // T is not referenced, but S is + void f(float, int = 100) override; + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 f 'void (float, int)' + // CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:15 'float' + // CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:21 'int' cinit + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 100 + // CHECK-NEXT: Overrides: [ 0x{{[^ ]*}} S::f 'void (float, int)' ] + // CHECK-NEXT: OverrideAttr + + // CHECK: CXXConstructorDecl 0x{{[^ ]*}} col:8 implicit T 'void (const T &)' inline default_delete noexcept-unevaluated + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 implicit operator= 'T &(const T &)' inline default_delete noexcept-unevaluated + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 implicit operator= 'T &(T &&)' inline default_delete noexcept-unevaluated + // CHECK: CXXDestructorDecl 0x{{[^ ]*}} col:8 implicit ~T 'void ()' inline default noexcept-unevaluated +}; + +struct U { + void f(); + // CHECK: CXXMethodDecl 0x{{[^ ]*}} col:8 f 'void ()' +}; +void U::f() {} // parent +// CHECK: CXXMethodDecl 0x{{[^ ]*}} parent 0x{{[^ ]*}} prev 0x{{[^ ]*}} col:9 f 'void ()' +// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} + +void a1(); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:6 used a1 'void ()' +void a2(void); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:6 a2 'void ()' +void b(int a, int b); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:6 b 'void (int, int)' +// CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:12 a 'int' +// CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:19 b 'int' +void c(int a, int b = 12); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:6 c 'void (int, int)' +// CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:12 a 'int' +// CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:19 b 'int' cinit +// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 12 +constexpr void d(void); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:16 constexpr d 'void ()' +static void e(void); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:13 e 'void ()' static +extern void f(void); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:13 f 'void ()' extern +extern "C" void g(void); +// CHECK: LinkageSpecDecl 0x{{[^ ]*}} col:8 C +// CHECK: FunctionDecl 0x{{[^ ]*}} col:17 g 'void ()' +inline void h(void); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:13 h 'void ()' inline +void i(void) noexcept; +// CHECK: FunctionDecl 0x{{[^ ]*}} col:6 i 'void () noexcept' +void j(void) noexcept(false); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:6 j 'void () noexcept(false)' +void k(void) noexcept(1); +// CHECK: FunctionDecl 0x{{[^ ]*}} col:6 k 'void () noexcept(1)' +template +T l(T&); +// CHECK: FunctionTemplateDecl 0x{{[^ ]*}} col:3 l +// CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}} col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: FunctionDecl 0x{{[^ ]*}} col:3 l 'T (T &)' +// CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:7 'T &' + +void m(int) {} +// CHECK: FunctionDecl 0x{{[^ ]*}} col:6 m 'void (int)' +// CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} col:11 'int' +// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} + +int main() { + // CHECK: FunctionDecl 0x{{[^ ]*}} line:[[@LINE-1]]:5 main 'int ()' + a1(); // Causes this to be marked 'used' +}