2012-12-20 11:30:30 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump -ast-dump-filter Test %s | FileCheck -check-prefix CHECK -strict-whitespace %s
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck -check-prefix CHECK-TU -strict-whitespace %s
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
int TestLocation;
|
2014-04-02 13:48:29 +08:00
|
|
|
// CHECK: VarDecl 0x{{[^ ]*}} <{{.*}}:4:1, col:5> col:5 TestLocation
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
struct TestIndent {
|
|
|
|
int x;
|
|
|
|
};
|
2013-01-31 09:44:26 +08:00
|
|
|
// CHECK: {{^}}RecordDecl{{.*TestIndent[^()]*$}}
|
|
|
|
// CHECK-NEXT: {{^}}`-FieldDecl{{.*x[^()]*$}}
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
struct TestChildren {
|
|
|
|
int x;
|
|
|
|
struct y {
|
|
|
|
int z;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// CHECK: RecordDecl{{.*}}TestChildren
|
|
|
|
// CHECK-NEXT: FieldDecl{{.*}}x
|
|
|
|
// CHECK-NEXT: RecordDecl{{.*}}y
|
|
|
|
// CHECK-NEXT: FieldDecl{{.*}}z
|
|
|
|
|
|
|
|
// CHECK-TU: TranslationUnitDecl
|
|
|
|
|
|
|
|
void testLabelDecl() {
|
|
|
|
__label__ TestLabelDecl;
|
|
|
|
TestLabelDecl: goto TestLabelDecl;
|
|
|
|
}
|
|
|
|
// CHECK: LabelDecl{{.*}} TestLabelDecl
|
|
|
|
|
|
|
|
typedef int TestTypedefDecl;
|
|
|
|
// CHECK: TypedefDecl{{.*}} TestTypedefDecl 'int'
|
|
|
|
|
|
|
|
__module_private__ typedef int TestTypedefDeclPrivate;
|
|
|
|
// CHECK: TypedefDecl{{.*}} TestTypedefDeclPrivate 'int' __module_private__
|
|
|
|
|
|
|
|
enum TestEnumDecl {
|
|
|
|
testEnumDecl
|
|
|
|
};
|
|
|
|
// CHECK: EnumDecl{{.*}} TestEnumDecl
|
|
|
|
// CHECK-NEXT: EnumConstantDecl{{.*}} testEnumDecl
|
|
|
|
|
|
|
|
struct TestEnumDeclAnon {
|
|
|
|
enum {
|
|
|
|
testEnumDeclAnon
|
|
|
|
} e;
|
|
|
|
};
|
|
|
|
// CHECK: RecordDecl{{.*}} TestEnumDeclAnon
|
2014-04-02 13:48:29 +08:00
|
|
|
// CHECK-NEXT: EnumDecl{{.*> .*$}}
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
enum TestEnumDeclForward;
|
|
|
|
// CHECK: EnumDecl{{.*}} TestEnumDeclForward
|
|
|
|
|
|
|
|
__module_private__ enum TestEnumDeclPrivate;
|
|
|
|
// CHECK: EnumDecl{{.*}} TestEnumDeclPrivate __module_private__
|
|
|
|
|
|
|
|
struct TestRecordDecl {
|
|
|
|
int i;
|
|
|
|
};
|
|
|
|
// CHECK: RecordDecl{{.*}} struct TestRecordDecl
|
|
|
|
// CHECK-NEXT: FieldDecl
|
|
|
|
|
|
|
|
struct TestRecordDeclEmpty {
|
|
|
|
};
|
|
|
|
// CHECK: RecordDecl{{.*}} struct TestRecordDeclEmpty
|
|
|
|
|
|
|
|
struct TestRecordDeclAnon1 {
|
|
|
|
struct {
|
|
|
|
} testRecordDeclAnon1;
|
|
|
|
};
|
|
|
|
// CHECK: RecordDecl{{.*}} struct TestRecordDeclAnon1
|
|
|
|
// CHECK-NEXT: RecordDecl{{.*}} struct
|
|
|
|
|
|
|
|
struct TestRecordDeclAnon2 {
|
|
|
|
struct {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// CHECK: RecordDecl{{.*}} struct TestRecordDeclAnon2
|
|
|
|
// CHECK-NEXT: RecordDecl{{.*}} struct
|
|
|
|
|
|
|
|
struct TestRecordDeclForward;
|
|
|
|
// CHECK: RecordDecl{{.*}} struct TestRecordDeclForward
|
|
|
|
|
|
|
|
__module_private__ struct TestRecordDeclPrivate;
|
|
|
|
// CHECK: RecordDecl{{.*}} struct TestRecordDeclPrivate __module_private__
|
|
|
|
|
|
|
|
enum testEnumConstantDecl {
|
|
|
|
TestEnumConstantDecl,
|
|
|
|
TestEnumConstantDeclInit = 1
|
|
|
|
};
|
|
|
|
// CHECK: EnumConstantDecl{{.*}} TestEnumConstantDecl 'int'
|
|
|
|
// CHECK: EnumConstantDecl{{.*}} TestEnumConstantDeclInit 'int'
|
|
|
|
// CHECK-NEXT: IntegerLiteral
|
|
|
|
|
|
|
|
struct testIndirectFieldDecl {
|
|
|
|
struct {
|
|
|
|
int TestIndirectFieldDecl;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
// CHECK: IndirectFieldDecl{{.*}} TestIndirectFieldDecl 'int'
|
|
|
|
// CHECK-NEXT: Field{{.*}} ''
|
|
|
|
// CHECK-NEXT: Field{{.*}} 'TestIndirectFieldDecl'
|
|
|
|
|
Store decls in prototypes on the declarator instead of in the AST
This saves two pointers from FunctionDecl that were being used for some
rare and questionable C-only functionality. The DeclsInPrototypeScope
ArrayRef was added in r151712 in order to parse this kind of C code:
enum e {x, y};
int f(enum {y, x} n) {
return x; // should return 1, not 0
}
The challenge is that we parse 'int f(enum {y, x} n)' it its own
function prototype scope that gets popped before we build the
FunctionDecl for 'f'. The original change was doing two questionable
things:
1. Saving all tag decls introduced in prototype scope on a TU-global
Sema variable. This is problematic when you have cases like this, where
'x' and 'y' shouldn't be visible in 'f':
void f(void (*fp)(enum { x, y } e)) { /* no x */ }
This patch fixes that, so now 'f' can't see 'x', which is consistent
with GCC.
2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that
they could be used in ActOnStartOfFunctionDef. This is just an
inefficient way to move information around. The AST lives forever, but
the list of non-parameter decls in prototype scope is short lived.
Moving these things to the Declarator solves both of these issues.
Reviewers: rsmith
Subscribers: jmolloy, cfe-commits
Differential Revision: https://reviews.llvm.org/D27279
llvm-svn: 289225
2016-12-10 01:14:05 +08:00
|
|
|
// FIXME: It would be nice to dump the enum and its enumerators.
|
2012-12-20 10:09:13 +08:00
|
|
|
int TestFunctionDecl(int x, enum { e } y) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
// CHECK: FunctionDecl{{.*}} TestFunctionDecl 'int (int, enum {{.*}})'
|
|
|
|
// CHECK-NEXT: ParmVarDecl{{.*}} x
|
|
|
|
// CHECK-NEXT: ParmVarDecl{{.*}} y
|
|
|
|
// CHECK-NEXT: CompoundStmt
|
|
|
|
|
Store decls in prototypes on the declarator instead of in the AST
This saves two pointers from FunctionDecl that were being used for some
rare and questionable C-only functionality. The DeclsInPrototypeScope
ArrayRef was added in r151712 in order to parse this kind of C code:
enum e {x, y};
int f(enum {y, x} n) {
return x; // should return 1, not 0
}
The challenge is that we parse 'int f(enum {y, x} n)' it its own
function prototype scope that gets popped before we build the
FunctionDecl for 'f'. The original change was doing two questionable
things:
1. Saving all tag decls introduced in prototype scope on a TU-global
Sema variable. This is problematic when you have cases like this, where
'x' and 'y' shouldn't be visible in 'f':
void f(void (*fp)(enum { x, y } e)) { /* no x */ }
This patch fixes that, so now 'f' can't see 'x', which is consistent
with GCC.
2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that
they could be used in ActOnStartOfFunctionDef. This is just an
inefficient way to move information around. The AST lives forever, but
the list of non-parameter decls in prototype scope is short lived.
Moving these things to the Declarator solves both of these issues.
Reviewers: rsmith
Subscribers: jmolloy, cfe-commits
Differential Revision: https://reviews.llvm.org/D27279
llvm-svn: 289225
2016-12-10 01:14:05 +08:00
|
|
|
// FIXME: It would be nice to 'Enum' and 'e'.
|
|
|
|
int TestFunctionDecl2(enum Enum { e } x) { return x; }
|
|
|
|
// CHECK: FunctionDecl{{.*}} TestFunctionDecl2 'int (enum {{.*}})'
|
|
|
|
// CHECK-NEXT: ParmVarDecl{{.*}} x
|
|
|
|
// CHECK-NEXT: CompoundStmt
|
|
|
|
|
|
|
|
|
2012-12-20 10:09:13 +08:00
|
|
|
int TestFunctionDeclProto(int x);
|
|
|
|
// CHECK: FunctionDecl{{.*}} TestFunctionDeclProto 'int (int)'
|
|
|
|
// CHECK-NEXT: ParmVarDecl{{.*}} x
|
|
|
|
|
|
|
|
extern int TestFunctionDeclSC();
|
|
|
|
// CHECK: FunctionDecl{{.*}} TestFunctionDeclSC 'int ()' extern
|
|
|
|
|
|
|
|
inline int TestFunctionDeclInline();
|
|
|
|
// CHECK: FunctionDecl{{.*}} TestFunctionDeclInline 'int ()' inline
|
|
|
|
|
|
|
|
struct testFieldDecl {
|
|
|
|
int TestFieldDecl;
|
|
|
|
int TestFieldDeclWidth : 1;
|
|
|
|
__module_private__ int TestFieldDeclPrivate;
|
|
|
|
};
|
|
|
|
// CHECK: FieldDecl{{.*}} TestFieldDecl 'int'
|
|
|
|
// CHECK: FieldDecl{{.*}} TestFieldDeclWidth 'int'
|
|
|
|
// CHECK-NEXT: IntegerLiteral
|
|
|
|
// CHECK: FieldDecl{{.*}} TestFieldDeclPrivate 'int' __module_private__
|
|
|
|
|
|
|
|
int TestVarDecl;
|
|
|
|
// CHECK: VarDecl{{.*}} TestVarDecl 'int'
|
|
|
|
|
|
|
|
extern int TestVarDeclSC;
|
|
|
|
// CHECK: VarDecl{{.*}} TestVarDeclSC 'int' extern
|
|
|
|
|
|
|
|
__thread int TestVarDeclThread;
|
2013-04-13 10:43:54 +08:00
|
|
|
// CHECK: VarDecl{{.*}} TestVarDeclThread 'int' tls{{$}}
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
__module_private__ int TestVarDeclPrivate;
|
|
|
|
// CHECK: VarDecl{{.*}} TestVarDeclPrivate 'int' __module_private__
|
|
|
|
|
|
|
|
int TestVarDeclInit = 0;
|
|
|
|
// CHECK: VarDecl{{.*}} TestVarDeclInit 'int'
|
|
|
|
// CHECK-NEXT: IntegerLiteral
|
|
|
|
|
|
|
|
void testParmVarDecl(int TestParmVarDecl);
|
|
|
|
// CHECK: ParmVarDecl{{.*}} TestParmVarDecl 'int'
|