llvm-project/clang/test/AST/ast-dump-expr.cpp
Matheus Izvekov 91cdd35008
[clang] Improve nested name specifier AST representation (#147835)
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:

![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831)

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
2025-08-09 05:06:53 -03:00

599 lines
28 KiB
C++

// Test without serialization:
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -fcxx-exceptions -std=gnu++17 -ast-dump %s \
// RUN: | FileCheck --strict-whitespace %s
//
// Test with serialization:
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -fcxx-exceptions -std=gnu++17 -emit-pch -o %t %s
// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value -fcxx-exceptions -std=gnu++17 \
// RUN: -include-pch %t -ast-dump-all /dev/null \
// RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
// RUN: | FileCheck --strict-whitespace %s
namespace std {
using size_t = decltype(sizeof(0));
class type_info {
public:
virtual ~type_info();
bool operator==(const type_info& rhs) const noexcept;
bool operator!=(const type_info& rhs) const noexcept;
type_info(const type_info& rhs) = delete; // cannot be copied
type_info& operator=(const type_info& rhs) = delete; // cannot be copied
};
class bad_typeid {
public:
bad_typeid() noexcept;
bad_typeid(const bad_typeid&) noexcept;
virtual ~bad_typeid();
bad_typeid& operator=(const bad_typeid&) noexcept;
const char* what() const noexcept;
};
} // namespace std
void *operator new(std::size_t, void *ptr);
struct S {
virtual ~S() = default;
void func(int);
template <typename Ty>
Ty foo();
int i;
};
struct T : S {};
template <typename>
struct U {};
void Throw() {
throw 12;
// CHECK: CXXThrowExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:9> 'void'
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:9> 'int' 12
throw;
// CHECK: CXXThrowExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3> 'void'
}
void PointerToMember(S obj1, S *obj2, int S::* data, void (S::*call)(int)) {
obj1.*data;
// CHECK: BinaryOperator 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:9> 'int' lvalue '.*'
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S' lvalue ParmVar 0x{{[^ ]*}} 'obj1' 'S'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:9> 'int S::*' lvalue ParmVar 0x{{[^ ]*}} 'data' 'int S::*'
obj2->*data;
// CHECK: BinaryOperator 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:10> 'int' lvalue '->*'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S *' lvalue ParmVar 0x{{[^ ]*}} 'obj2' 'S *'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:10> 'int S::*' lvalue ParmVar 0x{{[^ ]*}} 'data' 'int S::*'
(obj1.*call)(12);
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:18> 'void'
// CHECK-NEXT: ParenExpr 0x{{[^ ]*}} <col:3, col:14> '<bound member function type>'
// CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:4, col:10> '<bound member function type>' '.*'
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:4> 'S' lvalue ParmVar 0x{{[^ ]*}} 'obj1' 'S'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:10> 'void (S::*)(int)' lvalue ParmVar 0x{{[^ ]*}} 'call' 'void (S::*)(int)'
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:16> 'int' 12
(obj2->*call)(12);
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:19> 'void'
// CHECK-NEXT: ParenExpr 0x{{[^ ]*}} <col:3, col:15> '<bound member function type>'
// CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:4, col:11> '<bound member function type>' '->*'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:4> 'S *' lvalue ParmVar 0x{{[^ ]*}} 'obj2' 'S *'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:11> 'void (S::*)(int)' lvalue ParmVar 0x{{[^ ]*}} 'call' 'void (S::*)(int)'
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:17> 'int' 12
}
void Casting(const S *s) {
const_cast<S *>(s);
// CHECK: CXXConstCastExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:20> 'S *' const_cast<S *> <NoOp>
// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:19> 'const S *' <LValueToRValue> part_of_explicit_cast
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:19> 'const S *' lvalue ParmVar 0x{{[^ ]*}} 's' 'const S *'
static_cast<const T *>(s);
// CHECK: CXXStaticCastExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:27> 'const T *' static_cast<const T *> <BaseToDerived (S)>
// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:26> 'const S *' <LValueToRValue> part_of_explicit_cast
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:26> 'const S *' lvalue ParmVar 0x{{[^ ]*}} 's' 'const S *'
dynamic_cast<const T *>(s);
// CHECK: CXXDynamicCastExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:28> 'const T *' dynamic_cast<const T *> <Dynamic>
// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:27> 'const S *' <LValueToRValue> part_of_explicit_cast
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:27> 'const S *' lvalue ParmVar 0x{{[^ ]*}} 's' 'const S *'
reinterpret_cast<const int *>(s);
// CHECK: CXXReinterpretCastExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:34> 'const int *' reinterpret_cast<const int *> <BitCast>
// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:33> 'const S *' <LValueToRValue> part_of_explicit_cast
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:33> 'const S *' lvalue ParmVar 0x{{[^ ]*}} 's' 'const S *'
}
template <typename... Ts>
void UnaryExpressions(int *p) {
sizeof...(Ts);
// CHECK: SizeOfPackExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:15> '__size_t':'unsigned long' 0x{{[^ ]*}} Ts
noexcept(p - p);
// CHECK: CXXNoexceptExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:17> 'bool'
// CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:12, col:16> '__ptrdiff_t':'long' '-'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:12> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
::new int;
// CHECK: CXXNewExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:9> 'int *' global Function 0x{{[^ ]*}} 'operator new' 'void *(__size_t)'
new (int);
// CHECK: CXXNewExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:11> 'int *' Function 0x{{[^ ]*}} 'operator new' 'void *(__size_t)'
new int{12};
// CHECK: CXXNewExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:13> 'int *' Function 0x{{[^ ]*}} 'operator new' 'void *(__size_t)'
// CHECK-NEXT: InitListExpr 0x{{[^ ]*}} <col:10, col:13> 'int'
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:11> 'int' 12
new int[2];
// CHECK: CXXNewExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:12> 'int *' array Function 0x{{[^ ]*}} 'operator new[]' 'void *(__size_t)'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:11> 'int' 2
new int[2]{1, 2};
// CHECK: CXXNewExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:18> 'int *' array Function 0x{{[^ ]*}} 'operator new[]' 'void *(__size_t)'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:11> 'int' 2
// CHECK-NEXT: InitListExpr 0x{{[^ ]*}} <col:13, col:18> 'int[2]'
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:14> 'int' 1
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:17> 'int' 2
new (p) int;
// CHECK: CXXNewExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:11> 'int *' Function 0x{{[^ ]*}} 'operator new' 'void *(std::size_t, void *)'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void *' <BitCast>
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:8> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
new (p) int{12};
// CHECK: CXXNewExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:17> 'int *' Function 0x{{[^ ]*}} 'operator new' 'void *(std::size_t, void *)'
// CHECK-NEXT: InitListExpr 0x{{[^ ]*}} <col:14, col:17> 'int'
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:15> 'int' 12
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void *' <BitCast>
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:8> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
::delete p;
// CHECK: CXXDeleteExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:12> 'void' global Function 0x{{[^ ]*}} 'operator delete' 'void (void *, __size_t) noexcept'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:12> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
delete [] p;
// CHECK: CXXDeleteExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:13> 'void' array Function 0x{{[^ ]*}} 'operator delete[]' 'void (void *) noexcept'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:13> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
}
void PostfixExpressions(S a, S *p, U<int> *r) {
a.func(0);
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:11> 'void'
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:5> '<bound member function type>' .func 0x{{[^ ]*}}
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S' lvalue ParmVar 0x{{[^ ]*}} 'a' 'S'
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:10> 'int' 0
p->func(0);
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:12> 'void'
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:6> '<bound member function type>' ->func 0x{{[^ ]*}}
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'S *'
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:11> 'int' 0
// FIXME: there is no mention that this used the template keyword.
p->template foo<int>();
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:24> 'int'
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:22> '<bound member function type>' ->foo 0x{{[^ ]*}}
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'S *'
// FIXME: there is no mention that this used the template keyword.
a.template foo<float>();
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:25> 'float'
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:23> '<bound member function type>' .foo 0x{{[^ ]*}}
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S' lvalue ParmVar 0x{{[^ ]*}} 'a' 'S'
p->~S();
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:9> 'void'
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:7> '<bound member function type>' ->~S 0x{{[^ ]*}}
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'S *'
a.~S();
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:8> 'void'
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:6> '<bound member function type>' .~S 0x{{[^ ]*}}
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S' lvalue ParmVar 0x{{[^ ]*}} 'a' 'S'
// FIXME: there seems to be no way to distinguish the construct below from
// the construct above.
a.~decltype(a)();
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:18> 'void'
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:5> '<bound member function type>' .~S 0x{{[^ ]*}}
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S' lvalue ParmVar 0x{{[^ ]*}} 'a' 'S'
p->::S::~S();
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:14> 'void'
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:12> '<bound member function type>' ->~S 0x{{[^ ]*}}
// CHECK-NEXT: NestedNameSpecifier TypeSpec '::S'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'S *'
r->template U<int>::~U();
// CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:26> 'void'
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:24> '<bound member function type>' ->~U 0x{{[^ ]*}}
// CHECK-NEXT: NestedNameSpecifier TypeSpec 'template U<int>':'U<int>'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'U<int> *' lvalue ParmVar 0x{{[^ ]*}} 'r' 'U<int> *'
typeid(a);
// CHECK: CXXTypeidExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:11> 'const std::type_info' lvalue
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:10> 'S' lvalue ParmVar 0x{{[^ ]*}} 'a' 'S'
// FIXME: no type information is printed for the argument.
typeid(S);
// CHECK: CXXTypeidExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:11> 'const std::type_info' lvalue
}
template <typename... Ts>
void PrimaryExpressions(Ts... a) {
struct V {
void f() {
this;
// CHECK: CXXThisExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:7> 'V *' this
[this]{};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:7, col:14>
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:7> col:7 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <col:8> col:8 implicit 'V *'
// CHECK-NEXT: ParenListExpr
// CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}} <col:8> 'V *' this
[*this]{};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:7, col:15>
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:7> col:7 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <col:8> col:8 implicit 'V'
// CHECK-NEXT: ParenListExpr 0x{{[^ ]*}} <col:8> 'NULL TYPE'
// CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:8> 'V' lvalue prefix '*' cannot overflow
// CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}} <col:8> 'V *' this
}
};
int b, c;
[](){};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:8> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:6, col:8> col:3 operator() 'auto () const' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXConversionDecl 0x{{[^ ]*}} <col:3, col:8> col:3 implicit constexpr operator auto (*)() 'auto (*() const noexcept)()' inline
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:3, col:8> col:3 implicit __invoke 'auto ()' static inline
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:7, col:8>
[](int a, ...){};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:18> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:16, col:18> col:3 operator() 'auto (int, ...) const' inline
// CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} <col:6, col:10> col:10 a 'int'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXConversionDecl 0x{{[^ ]*}} <col:3, col:18> col:3 implicit constexpr operator auto (*)(int, ...) 'auto (*() const noexcept)(int, ...)' inline
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:3, col:18> col:3 implicit __invoke 'auto (int, ...)' static inline
// CHECK-NEXT: ParmVarDecl 0x{{[^ ]*}} <col:6, col:10> col:10 a 'int'
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:17, col:18>
[a...]{};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:10> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:8, col:10> col:3 operator() 'auto () const -> auto' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <col:4> col:4 implicit 'Ts...'
// CHECK-NEXT: ParenListExpr 0x{{[^ ]*}} <col:4> 'NULL TYPE'
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:4> 'Ts' lvalue ParmVar 0x{{[^ ]*}} 'a' 'Ts...'
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:9, col:10>
[=]{};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:7> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:5, col:7> col:3 operator() 'auto () const -> auto' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:6, col:7>
[=] { return b; };
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:19> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:5, col:19> col:3 operator() 'auto () const -> auto' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} <col:9, col:16>
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> 'const int' lvalue Var 0x{{[^ ]*}} 'b' 'int'
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:7, col:19>
// CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} <col:9, col:16>
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> 'const int' lvalue Var 0x{{[^ ]*}} 'b' 'int'
[&]{};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:7> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:5, col:7> col:3 operator() 'auto () const -> auto' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:6, col:7>
[&] { return c; };
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:19> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:5, col:19> col:3 operator() 'auto () const -> auto' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} <col:9, col:16>
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> 'int' lvalue Var 0x{{[^ ]*}} 'c' 'int'
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:7, col:19>
// CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} <col:9, col:16>
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> 'int' lvalue Var 0x{{[^ ]*}} 'c' 'int'
[b, &c]{ return b + c; };
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:26> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:9, col:26> col:3 operator() 'auto () const -> auto' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} <col:12, col:23>
// CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:19, col:23> 'int' '+'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:19> 'const int' lvalue Var 0x{{[^ ]*}} 'b' 'int'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:23> 'int' lvalue Var 0x{{[^ ]*}} 'c' 'int'
// CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <col:4> col:4 implicit 'int'
// CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <col:8> col:8 implicit 'int &'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:4> 'int' lvalue Var 0x{{[^ ]*}} 'b' 'int'
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:8> 'int' lvalue Var 0x{{[^ ]*}} 'c' 'int'
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:10, col:26>
// CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} <col:12, col:23>
// CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:19, col:23> 'int' '+'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:19> 'const int' lvalue Var 0x{{[^ ]*}} 'b' 'int'
// CHECK-NEXT: ImplicitCastExpr
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:23> 'int' lvalue Var 0x{{[^ ]*}} 'c' 'int'
[a..., x = 12]{};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:18> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:16, col:18> col:3 operator() 'auto () const -> auto' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <col:4> col:4 implicit 'Ts...'
// CHECK-NEXT: FieldDecl 0x{{[^ ]*}} <col:10> col:10 implicit 'int'
// CHECK-NEXT: ParenListExpr 0x{{[^ ]*}} <col:4> 'NULL TYPE'
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:4> 'Ts' lvalue ParmVar 0x{{[^ ]*}} 'a' 'Ts...'
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:14> 'int' 12
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:17, col:18>
[]() constexpr {};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:19> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:8, col:19> col:3 constexpr operator() 'auto () const' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXConversionDecl 0x{{[^ ]*}} <col:3, col:19> col:3 implicit constexpr operator auto (*)() 'auto (*() const noexcept)()' inline
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:3, col:19> col:3 implicit constexpr __invoke 'auto ()' static inline
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:18, col:19>
[]() mutable {};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:17> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:8, col:17> col:3 operator() 'auto ()' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXConversionDecl 0x{{[^ ]*}} <col:3, col:17> col:3 implicit constexpr operator auto (*)() 'auto (*() const noexcept)()' inline
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:3, col:17> col:3 implicit __invoke 'auto ()' static inline
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:16, col:17>
[]() noexcept {};
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:18> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:8, col:18> col:3 operator() 'auto () const noexcept' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXConversionDecl 0x{{[^ ]*}} <col:3, col:18> col:3 implicit constexpr operator auto (*)() noexcept 'auto (*() const noexcept)() noexcept' inline
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:3, col:18> col:3 implicit __invoke 'auto () noexcept' static inline
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:17, col:18>
[]() -> int { return 0; };
// CHECK: LambdaExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:27> '(lambda at {{.*}}:[[@LINE-1]]:3)'
// CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} <col:3> col:3 implicit class definition
// CHECK-NEXT: DefinitionData lambda
// CHECK-NEXT: DefaultConstructor
// CHECK-NEXT: CopyConstructor
// CHECK-NEXT: MoveConstructor
// CHECK-NEXT: CopyAssignment
// CHECK-NEXT: MoveAssignment
// CHECK-NEXT: Destructor
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:11, col:27> col:3 operator() 'auto () const -> int' inline
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} <col:17, col:24>
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:24> 'int' 0
// CHECK-NEXT: CXXConversionDecl 0x{{[^ ]*}} <col:3, col:27> col:3 implicit constexpr operator int (*)() 'auto (*() const noexcept)() -> int' inline
// CHECK-NEXT: CXXMethodDecl 0x{{[^ ]*}} <col:3, col:27> col:3 implicit __invoke 'auto () -> int' static inline
// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:15, col:27>
// CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} <col:17, col:24>
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:24> 'int' 0
(a + ...);
// CHECK: CXXFoldExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:11> '<dependent type>'
// CHECK-NEXT: <<<NULL>>>
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:4> 'Ts' lvalue ParmVar 0x{{[^ ]*}} 'a' 'Ts...'
// CHECK-NEXT: <<<NULL>>>
(... + a);
// CHECK: CXXFoldExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:11> '<dependent type>'
// CHECK-NEXT: <<<NULL>>>
// CHECK-NEXT: <<<NULL>>>
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:10> 'Ts' lvalue ParmVar 0x{{[^ ]*}} 'a' 'Ts...'
(a + ... + b);
// CHECK: CXXFoldExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:15> '<dependent type>'
// CHECK-NEXT: <<<NULL>>>
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:4> 'Ts' lvalue ParmVar 0x{{[^ ]*}} 'a' 'Ts...'
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int' lvalue Var 0x{{[^ ]*}} 'b' 'int'
}
namespace NS {
struct X {};
void f(X);
void y(...);
} // namespace NS
// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}ADLCall 'void ()'
void ADLCall() {
NS::X x;
// CHECK: CallExpr 0x{{[^ ]*}} <line:[[@LINE+1]]:{{[^>]+}}> 'void' adl{{$}}
f(x);
// CHECK: CallExpr 0x{{[^ ]*}} <line:[[@LINE+1]]:{{[^>]+}}> 'void' adl{{$}}
y(x);
}
// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall 'void ()'
void NonADLCall() {
NS::X x;
// CHECK: CallExpr 0x{{[^ ]*}} <line:[[@LINE+1]]:{{[^>]+}}> 'void'{{$}}
NS::f(x);
}
// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall2 'void ()'
void NonADLCall2() {
NS::X x;
using NS::f;
// CHECK: CallExpr 0x{{[^ ]*}} <line:[[@LINE+1]]:{{[^>]+}}> 'void'{{$}}
f(x);
// CHECK: CallExpr 0x{{[^ ]*}} <line:[[@LINE+1]]:{{[^>]+}}> 'void' adl{{$}}
y(x);
}
namespace test_adl_call_three {
using namespace NS;
// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall3 'void ()'
void NonADLCall3() {
X x;
// CHECK: CallExpr 0x{{[^ ]*}} <line:[[@LINE+1]]:{{[^>]+}}> 'void'{{$}}
f(x);
}
} // namespace test_adl_call_three
namespace GH35300 {
struct Sock {};
void leakNewFn() { new struct Sock; }
// CHECK: CXXNewExpr {{.*}} <col:20, col:31> 'struct Sock *'
}
namespace GH143711 {
struct S {
S(int, int);
};
void f() {
S(S(0, 1));
}
// CHECK: CXXTemporaryObjectExpr {{.*}} <col:5, col:11> 'S' 'void (int, int)'
}