2020-06-21 20:35:15 +08:00
|
|
|
// Test without serialization:
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump -ast-dump-filter Test %s \
|
|
|
|
// RUN: | FileCheck --strict-whitespace %s
|
|
|
|
//
|
|
|
|
// Test with serialization:
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t %s
|
|
|
|
// RUN: %clang_cc1 -x c -triple x86_64-unknown-unknown -include-pch %t \
|
|
|
|
// RUN: -ast-dump-all -ast-dump-filter Test /dev/null \
|
|
|
|
// RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
|
|
|
|
// RUN: | FileCheck --strict-whitespace %s
|
|
|
|
//
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s \
|
|
|
|
// RUN: | FileCheck -check-prefix CHECK-TU --strict-whitespace %s
|
|
|
|
//
|
|
|
|
// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=X \
|
|
|
|
// RUN: -triple x86_64-unknown-unknown -fmodule-map-file=%S/Inputs/module.modulemap \
|
|
|
|
// RUN: -ast-dump -ast-dump-filter Test %s -DMODULES \
|
|
|
|
// RUN: | FileCheck -check-prefix CHECK -check-prefix CHECK-MODULES --strict-whitespace %s
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
int TestLocation;
|
2017-06-23 09:04:34 +08:00
|
|
|
// CHECK: VarDecl 0x{{[^ ]*}} <{{.*}}:[[@LINE-1]]:1, col:5> col:5 TestLocation
|
|
|
|
|
|
|
|
#ifdef MODULES
|
|
|
|
#pragma clang module begin X
|
|
|
|
#endif
|
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;
|
2017-06-23 09:04:34 +08:00
|
|
|
// CHECK-MODULE: TypedefDecl{{.*}} TestTypedefDeclPrivate 'int' __module_private__
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
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;
|
2017-06-23 09:04:34 +08:00
|
|
|
// CHECK-MODULE: EnumDecl{{.*}} TestEnumDeclPrivate __module_private__
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
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;
|
2017-06-23 09:04:34 +08:00
|
|
|
// CHECK-MODULE: RecordDecl{{.*}} struct TestRecordDeclPrivate __module_private__
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
enum testEnumConstantDecl {
|
|
|
|
TestEnumConstantDecl,
|
|
|
|
TestEnumConstantDeclInit = 1
|
|
|
|
};
|
|
|
|
// CHECK: EnumConstantDecl{{.*}} TestEnumConstantDecl 'int'
|
|
|
|
// CHECK: EnumConstantDecl{{.*}} TestEnumConstantDeclInit 'int'
|
2018-11-09 08:41:36 +08:00
|
|
|
// CHECK-NEXT: ConstantExpr
|
|
|
|
// CHECK-NEXT: IntegerLiteral
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-01-17 00:12:30 +08:00
|
|
|
void TestFunctionDeclNoProto();
|
|
|
|
// CHECK: FunctionDecl{{.*}} TestFunctionDeclNoProto 'void ()'
|
|
|
|
|
2012-12-20 10:09:13 +08:00
|
|
|
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'
|
2018-11-09 08:41:36 +08:00
|
|
|
// CHECK-NEXT: ConstantExpr
|
|
|
|
// CHECK-NEXT: IntegerLiteral
|
2017-06-23 09:04:34 +08:00
|
|
|
// CHECK-MODULE: FieldDecl{{.*}} TestFieldDeclPrivate 'int' __module_private__
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
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;
|
2017-06-23 09:04:34 +08:00
|
|
|
// CHECK-MODULE: VarDecl{{.*}} TestVarDeclPrivate 'int' __module_private__
|
2012-12-20 10:09:13 +08:00
|
|
|
|
|
|
|
int TestVarDeclInit = 0;
|
|
|
|
// CHECK: VarDecl{{.*}} TestVarDeclInit 'int'
|
|
|
|
// CHECK-NEXT: IntegerLiteral
|
|
|
|
|
|
|
|
void testParmVarDecl(int TestParmVarDecl);
|
|
|
|
// CHECK: ParmVarDecl{{.*}} TestParmVarDecl 'int'
|
2017-06-23 09:04:34 +08:00
|
|
|
|
|
|
|
#ifdef MODULES
|
|
|
|
#pragma clang module end
|
|
|
|
#endif
|
|
|
|
|