[RISCV][VLOPT] Don't reduce the VL is the same as CommonVL (#123878)
[llvm-project.git] / clang / unittests / AST / ProfilingTest.cpp
blob27a4a197f1cbfa7e5c0fddab929128a772ee78be
1 //===- unittests/AST/ProfilingTest.cpp --- Tests for Profiling ------===//
2 //
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
6 //
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"
14 #include <utility>
16 namespace clang {
17 namespace {
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;
25 )cpp";
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")))
34 Res.push_back(CTD);
36 assert(Res.size() == 3);
37 #ifndef NDEBUG
38 for (auto &&I : Res)
39 assert(I->getCanonicalDecl() == Res[0]);
40 #endif
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;
47 T1->Profile(ID1);
48 T2->Profile(ID2);
49 ASSERT_NE(ID1, ID2);
51 auto *CT1 = cast<T>(T1->getCanonicalTypeInternal());
52 auto *CT2 = cast<T>(T2->getCanonicalTypeInternal());
54 llvm::FoldingSetNodeID ID1, ID2;
55 CT1->Profile(ID1);
56 CT2->Profile(ID2);
57 ASSERT_EQ(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(),
67 false));
68 auto *T2 = cast<DeducedTemplateSpecializationType>(
69 Ctx.getDeducedTemplateSpecializationType(TemplateName(CTD2), QualType(),
70 false));
71 testTypeNode(T1, T2);
74 } // namespace
75 } // namespace clang