
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well:  This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
211 lines
5.9 KiB
C++
211 lines
5.9 KiB
C++
// RUN: %clang_cc1 -triple i686-mingw32 %std_cxx11-14 -ast-dump %s | FileCheck %s
|
|
// RUN: %clang_cc1 -triple i686-mingw32 %std_cxx17- -ast-dump %s | FileCheck %s -check-prefix=CHECK-1Z
|
|
|
|
template<class T>
|
|
class P {
|
|
public:
|
|
P(T* t) {}
|
|
};
|
|
|
|
namespace foo {
|
|
class A { public: A(int = 0) {} };
|
|
enum B {};
|
|
typedef int C;
|
|
}
|
|
|
|
// CHECK: VarDecl {{0x[0-9a-fA-F]+}} <line:[[@LINE+1]]:1, col:36> col:15 ImplicitConstrArray 'foo::A[2]'
|
|
static foo::A ImplicitConstrArray[2];
|
|
|
|
int main() {
|
|
// CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::A *'
|
|
P<foo::A> p14 = new foo::A;
|
|
// CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::B *'
|
|
P<foo::B> p24 = new foo::B;
|
|
// CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::C *'
|
|
P<foo::C> pr4 = new foo::C;
|
|
}
|
|
|
|
foo::A getName() {
|
|
// CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:10, col:17> 'foo::A'
|
|
return foo::A();
|
|
}
|
|
|
|
void destruct(foo::A *a1, foo::A *a2, P<int> *p1) {
|
|
// CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:8> '<bound member function type>' ->~A
|
|
a1->~A();
|
|
// CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:16> '<bound member function type>' ->~A
|
|
a2->foo::A::~A();
|
|
// CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:13> '<bound member function type>' ->~P
|
|
p1->~P<int>();
|
|
}
|
|
|
|
struct D {
|
|
D(int);
|
|
~D();
|
|
};
|
|
|
|
void construct() {
|
|
using namespace foo;
|
|
A a = A(12);
|
|
// CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'A' 'void (int){{( __attribute__\(\(thiscall\)\))?}}'
|
|
D d = D(12);
|
|
// CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'D' 'void (int){{( __attribute__\(\(thiscall\)\))?}}'
|
|
}
|
|
|
|
namespace PR38987 {
|
|
struct A { A(); };
|
|
template <class T> void f() { T{}; }
|
|
template void f<A>();
|
|
// CHECK: CXXTemporaryObjectExpr {{.*}} <col:31, col:33> 'PR38987::A'
|
|
}
|
|
|
|
void abort() __attribute__((noreturn));
|
|
|
|
namespace std {
|
|
typedef decltype(sizeof(int)) size_t;
|
|
|
|
template <typename E> struct initializer_list {
|
|
const E *p;
|
|
size_t n;
|
|
initializer_list(const E *p, size_t n) : p(p), n(n) {}
|
|
};
|
|
|
|
template <typename F, typename S> struct pair {
|
|
F f;
|
|
S s;
|
|
pair(const F &f, const S &s) : f(f), s(s) {}
|
|
};
|
|
|
|
struct string {
|
|
const char *str;
|
|
string() { abort(); }
|
|
string(const char *S) : str(S) {}
|
|
~string() { abort(); }
|
|
};
|
|
|
|
template<typename K, typename V>
|
|
struct map {
|
|
using T = pair<K, V>;
|
|
map(initializer_list<T> i, const string &s = string()) {}
|
|
~map() { abort(); }
|
|
};
|
|
|
|
}; // namespace std
|
|
|
|
// CHECK: NamespaceDecl {{.*}} attributed_decl
|
|
namespace attributed_decl {
|
|
void f() {
|
|
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:28>
|
|
[[maybe_unused]] int i1;
|
|
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:35>
|
|
__attribute__((unused)) int i2;
|
|
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:35>
|
|
int __attribute__((unused)) i3;
|
|
// CHECK: DeclStmt {{.*}} <<built-in>:{{.*}}, {{.*}}:[[@LINE+1]]:40>
|
|
__declspec(dllexport) extern int i4;
|
|
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:40>
|
|
extern int __declspec(dllexport) i5;
|
|
}
|
|
}
|
|
|
|
// CHECK-1Z: NamespaceDecl {{.*}} attributed_case
|
|
namespace attributed_case {
|
|
void f(int n) {
|
|
switch (n) {
|
|
case 0:
|
|
n--;
|
|
// CHECK: AttributedStmt {{.*}} <line:[[@LINE+2]]:5, line:[[@LINE+4]]:35>
|
|
// CHECK: FallThroughAttr {{.*}} <line:[[@LINE+1]]:20>
|
|
__attribute__((fallthrough))
|
|
// CHECK: FallThroughAttr {{.*}} <line:[[@LINE+1]]:22>
|
|
__attribute__((fallthrough));
|
|
case 1:
|
|
n++;
|
|
break;
|
|
}
|
|
}
|
|
} // namespace attributed_case
|
|
|
|
// CHECK: NamespaceDecl {{.*}} attributed_stmt
|
|
namespace attributed_stmt {
|
|
// In DO_PRAGMA and _Pragma cases, `LoopHintAttr` comes from <scratch space>
|
|
// file.
|
|
|
|
#define DO_PRAGMA(x) _Pragma (#x)
|
|
|
|
void f() {
|
|
// CHECK: AttributedStmt {{.*}} <line:[[@LINE-3]]:24, line:[[@LINE+2]]:33>
|
|
DO_PRAGMA (unroll(2))
|
|
for (int i = 0; i < 10; ++i);
|
|
|
|
// CHECK: AttributedStmt {{.*}} <line:[[@LINE+2]]:5, line:[[@LINE+3]]:33>
|
|
// CHECK: LoopHintAttr {{.*}} <line:[[@LINE+1]]:13, col:22>
|
|
#pragma unroll(2)
|
|
for (int i = 0; i < 10; ++i);
|
|
|
|
// CHECK: AttributedStmt {{.*}} <line:[[@LINE+2]]:5, line:[[@LINE+5]]:33>
|
|
// CHECK: LoopHintAttr {{.*}} <line:[[@LINE+1]]:19, col:41>
|
|
#pragma clang loop vectorize(enable)
|
|
// CHECK: LoopHintAttr {{.*}} <line:[[@LINE+1]]:19, col:42>
|
|
#pragma clang loop interleave(enable)
|
|
for (int i = 0; i < 10; ++i);
|
|
|
|
// CHECK: AttributedStmt {{.*}} <line:[[@LINE+1]]:5, line:[[@LINE+2]]:33>
|
|
_Pragma("unroll(2)")
|
|
for (int i = 0; i < 10; ++i);
|
|
}
|
|
}
|
|
|
|
#if __cplusplus >= 201703L
|
|
// CHECK-1Z: FunctionDecl {{.*}} construct_with_init_list
|
|
std::map<int, int> construct_with_init_list() {
|
|
// CHECK-1Z-NEXT: CompoundStmt
|
|
// CHECK-1Z-NEXT: ReturnStmt {{.*}} <line:[[@LINE+5]]:3, col:35
|
|
// CHECK-1Z-NEXT: ExprWithCleanups {{.*}} <col:10, col:35
|
|
// CHECK-1Z-NEXT: CXXBindTemporaryExpr {{.*}} <col:10, col:35
|
|
// CHECK-1Z-NEXT: CXXTemporaryObjectExpr {{.*}} <col:10, col:35
|
|
// CHECK-1Z-NEXT: CXXStdInitializerListExpr {{.*}} <col:28, col:35
|
|
return std::map<int, int>{{0, 0}};
|
|
}
|
|
|
|
// CHECK-1Z: NamespaceDecl {{.*}} in_class_init
|
|
namespace in_class_init {
|
|
struct A {};
|
|
|
|
// CHECK-1Z: CXXRecordDecl {{.*}} struct B definition
|
|
struct B {
|
|
// CHECK-1Z: FieldDecl {{.*}} a 'A'
|
|
// CHECK-1Z-NEXT: InitListExpr {{.*}} <col:11, col:12
|
|
A a = {};
|
|
};
|
|
}
|
|
|
|
// CHECK-1Z: NamespaceDecl {{.*}} delegating_constructor_init
|
|
namespace delegating_constructor_init {
|
|
struct A {};
|
|
|
|
struct B : A {
|
|
A a;
|
|
B(A a) : a(a) {}
|
|
};
|
|
|
|
// CHECK-1Z: CXXRecordDecl {{.*}} struct C definition
|
|
struct C : B {
|
|
// CHECK-1Z: CXXConstructorDecl {{.*}} C
|
|
// CHECK-1Z-NEXT: CXXCtorInitializer 'B'
|
|
// CHECK-1Z-NEXT: CXXConstructExpr {{.*}} <col:11, col:15
|
|
// CHECK-1Z-NEXT: InitListExpr {{.*}} <col:13, col:14
|
|
C() : B({}) {};
|
|
};
|
|
}
|
|
|
|
// CHECK-1Z: NamespaceDecl {{.*}} new_init
|
|
namespace new_init {
|
|
void A() {
|
|
// CHECK-1Z: CXXNewExpr {{.*}} <line:[[@LINE+2]]:5, col:14
|
|
// CHECK-1Z-NEXT: InitListExpr {{.*}} <col:12, col:14
|
|
new int{0};
|
|
}
|
|
}
|
|
#endif
|