1 //===- unittests/AST/ProfilingTest.cpp --- Tests for Profiling ------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "clang/AST/ASTContext.h"
10 #include "clang/ASTMatchers/ASTMatchFinder.h"
11 #include "clang/ASTMatchers/ASTMatchers.h"
12 #include "clang/Tooling/Tooling.h"
13 #include "gtest/gtest.h"
18 using namespace ast_matchers
;
20 static auto getClassTemplateRedecls() {
21 std::string Code
= R
"cpp(
22 template <class> struct A;
23 template <class> struct A;
24 template <class> struct A;
26 auto AST
= tooling::buildASTFromCode(Code
);
27 ASTContext
&Ctx
= AST
->getASTContext();
29 auto MatchResults
= match(classTemplateDecl().bind("id"), Ctx
);
30 SmallVector
<ClassTemplateDecl
*, 3> Res
;
31 for (BoundNodes
&N
: MatchResults
) {
32 if (auto *CTD
= const_cast<ClassTemplateDecl
*>(
33 N
.getNodeAs
<ClassTemplateDecl
>("id")))
36 assert(Res
.size() == 3);
39 assert(I
->getCanonicalDecl() == Res
[0]);
41 return std::make_tuple(std::move(AST
), Res
[1], Res
[2]);
44 template <class T
> static void testTypeNode(const T
*T1
, const T
*T2
) {
46 llvm::FoldingSetNodeID ID1
, ID2
;
51 auto *CT1
= cast
<T
>(T1
->getCanonicalTypeInternal());
52 auto *CT2
= cast
<T
>(T2
->getCanonicalTypeInternal());
54 llvm::FoldingSetNodeID ID1
, ID2
;
61 TEST(Profiling
, DeducedTemplateSpecializationType_Name
) {
62 auto [AST
, CTD1
, CTD2
] = getClassTemplateRedecls();
63 ASTContext
&Ctx
= AST
->getASTContext();
65 auto *T1
= cast
<DeducedTemplateSpecializationType
>(
66 Ctx
.getDeducedTemplateSpecializationType(TemplateName(CTD1
), QualType(),
68 auto *T2
= cast
<DeducedTemplateSpecializationType
>(
69 Ctx
.getDeducedTemplateSpecializationType(TemplateName(CTD2
), QualType(),