From 87c50e8c89b5af9d00bc129d6c032849696422d5 Mon Sep 17 00:00:00 2001 From: Francesco Bertolaccini Date: Thu, 22 Dec 2022 13:37:23 +0100 Subject: [PATCH] Migrate to LLVM15 (#308) * Migrate to LLVM15 * Update CI * Update build script * Remove vcpkg helper (#314) * remove vcpkg_helper.cmake * fix build instruction in README * fix build script perms * fix diff ci build * fix typo, should be VCPKG_TARGET_TRIPLET * update anghabench CI scripts for llvm 15 * miss comma Co-authored-by: William Tan <1284324+Ninja3047@users.noreply.github.com> --- .github/workflows/anghabench-after-build.yml | 2 +- .github/workflows/anghabench-cron-jobs.yml | 2 +- .github/workflows/ci.yml | 10 +- .github/workflows/diff_tests.yml | 10 +- lib/AST/ASTBuilder.cpp | 12 +- lib/AST/DebugInfoCollector.cpp | 1 + lib/AST/StructGenerator.cpp | 1 + lib/BC/Util.cpp | 1 + scripts/build.sh | 8 +- tools/decomp/Decomp.cpp | 2 - tools/repl/Repl.cpp | 1 - tools/xref/DeclPrinter.cpp | 17 +- tools/xref/StmtPrinter.cpp | 184 ++++++++++++++++--- tools/xref/TypePrinter.cpp | 55 +++++- tools/xref/Xref.cpp | 1 - 15 files changed, 254 insertions(+), 53 deletions(-) diff --git a/.github/workflows/anghabench-after-build.yml b/.github/workflows/anghabench-after-build.yml index 486cc564..441267fa 100644 --- a/.github/workflows/anghabench-after-build.yml +++ b/.github/workflows/anghabench-after-build.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - llvm: [ '14' ] + llvm: [ '15' ] run_size: [ '1k' ] name: Run AnghaBench CI (AMD64) diff --git a/.github/workflows/anghabench-cron-jobs.yml b/.github/workflows/anghabench-cron-jobs.yml index 21b79111..ef7d958f 100644 --- a/.github/workflows/anghabench-cron-jobs.yml +++ b/.github/workflows/anghabench-cron-jobs.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - llvm: [ '14' ] + llvm: [ '15' ] run_size: [ '1k' ] name: Run AnghaBench CI (AMD64) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02076685..3c15adb6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: image: - { name: 'ubuntu', tag: '20.04' } llvm: [ - '14' + '15' ] name: Rellic CI @@ -48,8 +48,8 @@ jobs: run: | # TODO some of these should probably live in the Docker build image wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - - echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list - echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list + echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${{ matrix.llvm }} main" >> /etc/apt/sources.list + echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-${{ matrix.llvm }} main" >> /etc/apt/sources.list apt-get update apt-get install -y ninja-build pixz xz-utils make rpm python3.8 update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 100 @@ -129,7 +129,7 @@ jobs: 'macos-11' ] llvm: [ - '14' + '15' ] runs-on: ${{ matrix.os }} @@ -246,7 +246,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - llvm: ["14"] + llvm: ["15"] ubuntu: ["20.04"] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/diff_tests.yml b/.github/workflows/diff_tests.yml index ced760d0..d5a6160a 100644 --- a/.github/workflows/diff_tests.yml +++ b/.github/workflows/diff_tests.yml @@ -12,7 +12,7 @@ jobs: matrix: image: - { name: 'ubuntu', tag: '20.04', codename: 'focal' } - llvm: [ '14' ] + llvm: [ '15' ] common_base: [ 'https://github.com/lifting-bits/cxx-common/releases/latest/download' ] env: @@ -62,13 +62,13 @@ jobs: - name: Build old rellic shell: bash run: | - cmake -G Ninja -S old -B rellic-build-old -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm-${{ matrix.llvm }}_amd64/scripts/buildsystems/vcpkg.cmake + cmake -G Ninja -S old -B rellic-build-old -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm-${{ matrix.llvm }}_amd64/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET="x64-linux-rel" cmake --build rellic-build-old - name: Build new rellic shell: bash run: | - cmake -G Ninja -S . -B rellic-build -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm-${{ matrix.llvm }}_amd64/scripts/buildsystems/vcpkg.cmake + cmake -G Ninja -S . -B rellic-build -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm-${{ matrix.llvm }}_amd64/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET="x64-linux-rel" cmake --build rellic-build - name: Print job summary @@ -76,7 +76,7 @@ jobs: run: | echo "# Test diffs" >> $GITHUB_STEP_SUMMARY cd $GITHUB_WORKSPACE/tests/tools/decomp - env CLANG=clang-14 \ + env CLANG=clang-${{ matrix.llvm }} \ OLD_RELLIC=$GITHUB_WORKSPACE/rellic-build-old/tools/rellic-decomp \ NEW_RELLIC=$GITHUB_WORKSPACE/rellic-build/tools/rellic-decomp \ make -s -j1 -f diff_outputs.mk >> $GITHUB_STEP_SUMMARY @@ -86,7 +86,7 @@ jobs: id: md run: | cd $GITHUB_WORKSPACE/tests/tools/decomp - env CLANG=clang-14 \ + env CLANG=clang-${{ matrix.llvm }} \ OLD_RELLIC=$GITHUB_WORKSPACE/rellic-build-old/tools/rellic-decomp \ NEW_RELLIC=$GITHUB_WORKSPACE/rellic-build/tools/rellic-decomp \ make -s -j1 -f diff_outputs.mk >> $GITHUB_WORKSPACE/test-diff.md diff --git a/lib/AST/ASTBuilder.cpp b/lib/AST/ASTBuilder.cpp index 8f969c94..08b9e352 100644 --- a/lib/AST/ASTBuilder.cpp +++ b/lib/AST/ASTBuilder.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -33,11 +34,13 @@ enum CExprPrecedence : unsigned { namespace { static unsigned GetOperatorPrecedence(clang::UnaryOperatorKind opc) { - return static_cast(CExprPrecedence::UnaryOp) + static_cast(opc); + return static_cast(CExprPrecedence::UnaryOp) + + static_cast(opc); } static unsigned GetOperatorPrecedence(clang::BinaryOperatorKind opc) { - return static_cast(CExprPrecedence::BinaryOp) + static_cast(opc); + return static_cast(CExprPrecedence::BinaryOp) + + static_cast(opc); } static unsigned GetOperatorPrecedence(clang::Expr *op) { @@ -186,7 +189,7 @@ clang::CharacterLiteral *ASTBuilder::CreateCharLit(unsigned val) { clang::StringLiteral *ASTBuilder::CreateStrLit(std::string val) { auto type{ctx.getStringLiteralArrayType(ctx.CharTy, val.size())}; return clang::StringLiteral::Create( - ctx, val, clang::StringLiteral::StringKind::Ascii, + ctx, val, clang::StringLiteral::StringKind::Ordinary, /*Pascal=*/false, type, clang::SourceLocation()); } @@ -459,7 +462,8 @@ clang::CompoundStmt *ASTBuilder::CreateCompoundStmt( // sema.ActOnFinishOfCompoundStmt(); // CHECK(sr.isUsable()); // return sr.getAs(); - return clang::CompoundStmt::Create(ctx, stmts, clang::SourceLocation(), + return clang::CompoundStmt::Create(ctx, stmts, clang::FPOptionsOverride{}, + clang::SourceLocation(), clang::SourceLocation()); } diff --git a/lib/AST/DebugInfoCollector.cpp b/lib/AST/DebugInfoCollector.cpp index b48d7ee0..f264dd58 100644 --- a/lib/AST/DebugInfoCollector.cpp +++ b/lib/AST/DebugInfoCollector.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include diff --git a/lib/AST/StructGenerator.cpp b/lib/AST/StructGenerator.cpp index 59f5d960..57a0d694 100644 --- a/lib/AST/StructGenerator.cpp +++ b/lib/AST/StructGenerator.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include diff --git a/lib/BC/Util.cpp b/lib/BC/Util.cpp index 21aedadc..07de89e2 100644 --- a/lib/BC/Util.cpp +++ b/lib/BC/Util.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/scripts/build.sh b/scripts/build.sh index 03badaf0..fd94d36f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -18,8 +18,8 @@ DOWNLOAD_DIR="$( cd "$( dirname "${SRC_DIR}" )" && pwd )/lifting-bits-downloads" CURR_DIR=$( pwd ) BUILD_DIR="${CURR_DIR}/rellic-build" INSTALL_DIR=/usr/local -LLVM_VERSION=llvm-14 -CXX_COMMON_VERSION=v0.2.16 +LLVM_VERSION=llvm-15 +CXX_COMMON_VERSION=v0.2.19 OS_VERSION=unknown ARCH_VERSION=unknown BUILD_FLAGS= @@ -334,6 +334,10 @@ function GetLLVMVersion LLVM_VERSION=llvm-14 return 0 ;; + 15) + LLVM_VERSION=llvm-15 + return 0 + ;; *) # unknown option echo "[x] Unknown or unsupported LLVM version ${1}. You may be able to manually build it with cxx-common." diff --git a/tools/decomp/Decomp.cpp b/tools/decomp/Decomp.cpp index 0e4df1f1..9f60622b 100644 --- a/tools/decomp/Decomp.cpp +++ b/tools/decomp/Decomp.cpp @@ -111,8 +111,6 @@ int main(int argc, char* argv[]) { } std::unique_ptr llvm_ctx(new llvm::LLVMContext); - llvm_ctx->enableOpaquePointers(); - auto module{std::unique_ptr( rellic::LoadModuleFromFile(llvm_ctx.get(), FLAGS_input))}; diff --git a/tools/repl/Repl.cpp b/tools/repl/Repl.cpp index 5a9f30d7..b100959b 100644 --- a/tools/repl/Repl.cpp +++ b/tools/repl/Repl.cpp @@ -493,7 +493,6 @@ int main(int argc, char* argv[]) { SetVersion(); google::ParseCommandLineFlags(&argc, &argv, true); - llvm_ctx.enableOpaquePointers(); auto& pr{*llvm::PassRegistry::getPassRegistry()}; initializeCore(pr); initializeAnalysis(pr); diff --git a/tools/xref/DeclPrinter.cpp b/tools/xref/DeclPrinter.cpp index ad5cc8ca..35aedd0f 100644 --- a/tools/xref/DeclPrinter.cpp +++ b/tools/xref/DeclPrinter.cpp @@ -651,6 +651,10 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (FT->isVariadic()) { if (D->getNumParams()) POut << ", "; POut << "..."; + } else if (!D->getNumParams() && !Context.getLangOpts().CPlusPlus) { + // The function has a prototype, so it needs to retain the prototype + // in C. + POut << "void"; } } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) { for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { @@ -845,8 +849,11 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { Expr *Init = D->getInit(); if (!Policy.SuppressInitializers && Init) { bool ImplicitInit = false; - if (CXXConstructExpr *Construct = - dyn_cast(Init->IgnoreImplicit())) { + if (D->isCXXForRangeDecl()) { + // FIXME: We should print the range expression instead. + ImplicitInit = true; + } else if (CXXConstructExpr *Construct = + dyn_cast(Init->IgnoreImplicit())) { if (D->getInitStyle() == VarDecl::CallInit && !Construct->isListInitialization()) { ImplicitInit = Construct->getNumArgs() == 0 || @@ -945,6 +952,12 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { } } + if (D->hasDefinition()) { + if (D->hasAttr()) { + Out << " final"; + } + } + if (D->isCompleteDefinition()) { // Print the base classes if (D->getNumBases()) { diff --git a/tools/xref/StmtPrinter.cpp b/tools/xref/StmtPrinter.cpp index 3a91c3f4..8ce00530 100644 --- a/tools/xref/StmtPrinter.cpp +++ b/tools/xref/StmtPrinter.cpp @@ -135,6 +135,7 @@ class StmtPrinter : public StmtVisitor { void PrintRawSEHFinallyStmt(SEHFinallyStmt *S); void PrintOMPExecutableDirective(OMPExecutableDirective *S, bool ForceNoStmt = false); + void PrintFPPragmas(CompoundStmt *S); void PrintExpr(Expr *E) { if (E) @@ -185,11 +186,72 @@ class StmtPrinter : public StmtVisitor { /// with no newline after the }. void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) { OS << "{" << NL; + PrintFPPragmas(Node); for (auto *I : Node->body()) PrintStmt(I); Indent() << "}"; } +void StmtPrinter::PrintFPPragmas(CompoundStmt *S) { + if (!S->hasStoredFPFeatures()) + return; + FPOptionsOverride FPO = S->getStoredFPFeatures(); + bool FEnvAccess = false; + if (FPO.hasAllowFEnvAccessOverride()) { + FEnvAccess = FPO.getAllowFEnvAccessOverride(); + Indent() << "#pragma STDC FENV_ACCESS " << (FEnvAccess ? "ON" : "OFF") + << NL; + } + if (FPO.hasSpecifiedExceptionModeOverride()) { + LangOptions::FPExceptionModeKind EM = + FPO.getSpecifiedExceptionModeOverride(); + if (!FEnvAccess || EM != LangOptions::FPE_Strict) { + Indent() << "#pragma clang fp exceptions("; + switch (FPO.getSpecifiedExceptionModeOverride()) { + default: + break; + case LangOptions::FPE_Ignore: + OS << "ignore"; + break; + case LangOptions::FPE_MayTrap: + OS << "maytrap"; + break; + case LangOptions::FPE_Strict: + OS << "strict"; + break; + } + OS << ")\n"; + } + } + if (FPO.hasConstRoundingModeOverride()) { + LangOptions::RoundingMode RM = FPO.getConstRoundingModeOverride(); + Indent() << "#pragma STDC FENV_ROUND "; + switch (RM) { + case llvm::RoundingMode::TowardZero: + OS << "FE_TOWARDZERO"; + break; + case llvm::RoundingMode::NearestTiesToEven: + OS << "FE_TONEAREST"; + break; + case llvm::RoundingMode::TowardPositive: + OS << "FE_UPWARD"; + break; + case llvm::RoundingMode::TowardNegative: + OS << "FE_DOWNWARD"; + break; + case llvm::RoundingMode::NearestTiesToAway: + OS << "FE_TONEARESTFROMZERO"; + break; + case llvm::RoundingMode::Dynamic: + OS << "FE_DYNAMIC"; + break; + default: + llvm_unreachable("Invalid rounding mode"); + } + OS << NL; + } +} + void StmtPrinter::PrintRawDecl(Decl *D) { PrintDecl(D, Policy, IndentLevel, OS); } @@ -751,6 +813,12 @@ void StmtPrinter::VisitOMPParallelMasterDirective( PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPParallelMaskedDirective( + OMPParallelMaskedDirective *Node) { + Indent() << "#pragma omp parallel masked"; + PrintOMPExecutableDirective(Node); +} + void StmtPrinter::VisitOMPParallelSectionsDirective( OMPParallelSectionsDirective *Node) { Indent() << "#pragma omp parallel " @@ -758,6 +826,12 @@ void StmtPrinter::VisitOMPParallelSectionsDirective( PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPMaskedTaskLoopDirective( + OMPMaskedTaskLoopDirective *Node) { + Indent() << "#pragma omp masked taskloop"; + PrintOMPExecutableDirective(Node); +} + void StmtPrinter::VisitOMPTaskDirective(OMPTaskDirective *Node) { Indent() << "#pragma omp task"; PrintOMPExecutableDirective(Node); @@ -906,6 +980,48 @@ void StmtPrinter::VisitOMPParallelMasterTaskLoopSimdDirective( PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPMaskedTaskLoopSimdDirective( + OMPMaskedTaskLoopSimdDirective *Node) { + Indent() << "#pragma omp masked taskloop simd"; + PrintOMPExecutableDirective(Node); +} + +void StmtPrinter::VisitOMPParallelMaskedTaskLoopDirective( + OMPParallelMaskedTaskLoopDirective *Node) { + Indent() << "#pragma omp parallel masked taskloop"; + PrintOMPExecutableDirective(Node); +} + +void StmtPrinter::VisitOMPParallelMaskedTaskLoopSimdDirective( + OMPParallelMaskedTaskLoopSimdDirective *Node) { + Indent() << "#pragma omp parallel masked taskloop simd"; + PrintOMPExecutableDirective(Node); +} + +void StmtPrinter::VisitOMPTeamsGenericLoopDirective( + OMPTeamsGenericLoopDirective *Node) { + Indent() << "#pragma omp teams loop"; + PrintOMPExecutableDirective(Node); +} + +void StmtPrinter::VisitOMPTargetTeamsGenericLoopDirective( + OMPTargetTeamsGenericLoopDirective *Node) { + Indent() << "#pragma omp target teams loop"; + PrintOMPExecutableDirective(Node); +} + +void StmtPrinter::VisitOMPParallelGenericLoopDirective( + OMPParallelGenericLoopDirective *Node) { + Indent() << "#pragma omp parallel loop"; + PrintOMPExecutableDirective(Node); +} + +void StmtPrinter::VisitOMPTargetParallelGenericLoopDirective( + OMPTargetParallelGenericLoopDirective *Node) { + Indent() << "#pragma omp target parallel loop"; + PrintOMPExecutableDirective(Node); +} + void StmtPrinter::VisitOMPDistributeDirective(OMPDistributeDirective *Node) { Indent() << "#pragma omp distribute"; @@ -1054,7 +1170,7 @@ void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) { return; } if (const auto *TPOD = dyn_cast(Node->getDecl())) { - TPOD->printAsExpr(OS); + TPOD->printAsExpr(OS, Policy); return; } if (NestedNameSpecifier *Qualifier = Node->getQualifier()) @@ -1261,6 +1377,11 @@ void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) { OS << toString(Node->getValue(), 16, isSigned, /*formatAsCLiteral=*/true); } + if (isa(Node->getType())) { + OS << (isSigned ? "wb" : "uwb"); + return; + } + // Emit suffixes. Integer literals are always a builtin integer type. switch (Node->getType()->castAs()->getKind()) { default: @@ -1398,7 +1519,7 @@ void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) { static void outputString(const StringLiteral *Str, raw_ostream &OS) { switch (Str->getKind()) { - case StringLiteral::Ascii: + case StringLiteral::Ordinary: break; // no prefix. case StringLiteral::Wide: OS << 'L'; @@ -2017,20 +2138,15 @@ void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) { } } else if (Kind == OO_Arrow) { PrintExpr(Node->getArg(0)); - } else if (Kind == OO_Call) { + } else if (Kind == OO_Call || Kind == OO_Subscript) { PrintExpr(Node->getArg(0)); - OS << '('; + OS << (Kind == OO_Call ? '(' : '['); for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) { if (ArgIdx > 1) OS << ", "; if (!isa(Node->getArg(ArgIdx))) PrintExpr(Node->getArg(ArgIdx)); } - OS << ')'; - } else if (Kind == OO_Subscript) { - PrintExpr(Node->getArg(0)); - OS << '['; - PrintExpr(Node->getArg(1)); - OS << ']'; + OS << (Kind == OO_Call ? ')' : ']'); } else if (Node->getNumArgs() == 1) { OS << getOperatorSpelling(Kind) << ' '; PrintExpr(Node->getArg(0)); @@ -2157,7 +2273,7 @@ void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) { cast(DRE->getDecl())->getTemplateSpecializationArgs(); assert(Args); - if (Args->size() != 1) { + if (Args->size() != 1 || Args->get(0).getKind() != TemplateArgument::Pack) { OS << "operator\"\"" << Node->getUDSuffix()->getName(); printTemplateArgumentList(OS, Args->asArray(), Policy); @@ -2223,12 +2339,23 @@ void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) { } void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) { - PrintType(Node->getType(), OS, Policy); - // If there are no parens, this is list-initialization, and the braces are - // part of the syntax of the inner construct. - if (Node->getLParenLoc().isValid()) OS << "("; + auto TargetType = Node->getType(); + auto *Auto = TargetType->getContainedDeducedType(); + bool Bare = Auto && Auto->isDeduced(); + + // Parenthesize deduced casts. + if (Bare) + OS << '('; + TargetType.print(OS, Policy); + if (Bare) + OS << ')'; + + // No extra braces surrounding the inner construct. + if (!Node->isListInitialization()) + OS << '('; PrintExpr(Node->getSubExpr()); - if (Node->getLParenLoc().isValid()) OS << ")"; + if (!Node->isListInitialization()) + OS << ')'; } void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) { @@ -2403,20 +2530,24 @@ void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) { } if (E->isParenTypeId()) OS << "("; std::string TypeS; - if (Optional Size = E->getArraySize()) { + if (E->isArray()) { llvm::raw_string_ostream s(TypeS); s << '['; - if (*Size) ::PrintStmt(*Size, s, Policy, 0, nullptr, Helper); + if (Optional Size = E->getArraySize()) ::PrintStmt(*Size, s, Policy, 0, nullptr, Helper); s << ']'; } PrintType(E->getAllocatedType(), OS, Policy, TypeS); if (E->isParenTypeId()) OS << ")"; CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle(); - if (InitStyle) { - if (InitStyle == CXXNewExpr::CallInit) OS << "("; + if (InitStyle != CXXNewExpr::NoInit) { + bool Bare = InitStyle == CXXNewExpr::CallInit && + !isa(E->getInitializer()); + if (Bare) + OS << "("; PrintExpr(E->getInitializer()); - if (InitStyle == CXXNewExpr::CallInit) OS << ")"; + if (Bare) + OS << ")"; } } @@ -2475,14 +2606,15 @@ void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) { void StmtPrinter::VisitCXXUnresolvedConstructExpr( CXXUnresolvedConstructExpr *Node) { PrintType(Node->getTypeAsWritten(), OS, Policy); - OS << "("; - for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(), - ArgEnd = Node->arg_end(); - Arg != ArgEnd; ++Arg) { + if (!Node->isListInitialization()) + OS << '('; + for (auto Arg = Node->arg_begin(), ArgEnd = Node->arg_end(); Arg != ArgEnd; + ++Arg) { if (Arg != Node->arg_begin()) OS << ", "; PrintExpr(*Arg); } - OS << ")"; + if (!Node->isListInitialization()) + OS << ')'; } void StmtPrinter::VisitCXXDependentScopeMemberExpr( diff --git a/tools/xref/TypePrinter.cpp b/tools/xref/TypePrinter.cpp index 9be4c56a..c609f7f9 100644 --- a/tools/xref/TypePrinter.cpp +++ b/tools/xref/TypePrinter.cpp @@ -79,6 +79,19 @@ class ParamPolicyRAII { ~ParamPolicyRAII() { Policy.SuppressSpecifiers = Old; } }; +class DefaultTemplateArgsPolicyRAII { + PrintingPolicy &Policy; + bool Old; + + public: + explicit DefaultTemplateArgsPolicyRAII(PrintingPolicy &Policy) + : Policy(Policy), Old(Policy.SuppressDefaultTemplateArgs) { + Policy.SuppressDefaultTemplateArgs = false; + } + + ~DefaultTemplateArgsPolicyRAII() { Policy.SuppressDefaultTemplateArgs = Old; } +}; + class ElaboratedTypePolicyRAII { PrintingPolicy &Policy; bool SuppressTagKeyword; @@ -232,6 +245,7 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, case Type::Pipe: case Type::BitInt: case Type::DependentBitInt: + case Type::BTFTagAttributed: CanPrefixQualifiers = true; break; @@ -280,6 +294,7 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, // address_space attribute. const auto *AttrTy = cast(UnderlyingType); CanPrefixQualifiers = AttrTy->getAttrKind() == attr::AddressSpace; + break; } } @@ -918,6 +933,12 @@ void TypePrinter::printFunctionAfter(const FunctionType::ExtInfo &Info, case CC_AArch64VectorCall: OS << "__attribute__((aarch64_vector_pcs))"; break; + case CC_AArch64SVEPCS: + OS << "__attribute__((aarch64_sve_pcs))"; + break; + case CC_AMDGPUKernelCall: + OS << "__attribute__((amdgpu_kernel))"; + break; case CC_IntelOclBicc: OS << " __attribute__((intel_ocl_bicc))"; break; @@ -1423,6 +1444,7 @@ void TypePrinter::printTemplateId(const TemplateSpecializationType *T, T->getTemplateName().print(OS, Policy); } + DefaultTemplateArgsPolicyRAII TemplateArgs(Policy); const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : nullptr; printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL); spaceBeforePlaceHolder(OS); @@ -1637,6 +1659,15 @@ void TypePrinter::printAttributedAfter(const AttributedType *T, // this twice. if (T->getAttrKind() == attr::AddressSpace) return; + if (T->getAttrKind() == attr::AnnotateType) { + // FIXME: Print the attribute arguments once we have a way to retrieve these + // here. For the meantime, we just print `[[clang::annotate_type(...)]]` + // without the arguments so that we know at least that we had _some_ + // annotation on the type. + OS << " [[clang::annotate_type(...)]]"; + return; + } + OS << " __attribute__(("; switch (T->getAttrKind()) { #define TYPE_ATTR(NAME) @@ -1645,6 +1676,9 @@ void TypePrinter::printAttributedAfter(const AttributedType *T, #include llvm_unreachable("non-type attribute attached to type"); + case attr::BTFTypeTag: + llvm_unreachable("BTFTypeTag attribute handled separately"); + case attr::OpenCLPrivateAddressSpace: case attr::OpenCLGlobalAddressSpace: case attr::OpenCLGlobalDeviceAddressSpace: @@ -1671,6 +1705,7 @@ void TypePrinter::printAttributedAfter(const AttributedType *T, case attr::UPtr: case attr::AddressSpace: case attr::CmseNSCall: + case attr::AnnotateType: llvm_unreachable("This attribute should have been handled already"); case attr::NSReturnsRetained: @@ -1728,6 +1763,12 @@ void TypePrinter::printAttributedAfter(const AttributedType *T, case attr::AArch64VectorPcs: OS << "aarch64_vector_pcs"; break; + case attr::AArch64SVEPcs: + OS << "aarch64_sve_pcs"; + break; + case attr::AMDGPUKernelCall: + OS << "amdgpu_kernel"; + break; case attr::IntelOclBicc: OS << "inteloclbicc"; break; @@ -1747,13 +1788,21 @@ void TypePrinter::printAttributedAfter(const AttributedType *T, case attr::ArmMveStrictPolymorphism: OS << "__clang_arm_mve_strict_polymorphism"; break; - case attr::BTFTypeTag: - OS << "btf_type_tag"; - break; } OS << "))"; } +void TypePrinter::printBTFTagAttributedBefore(const BTFTagAttributedType *T, + raw_ostream &OS) { + printBefore(T->getWrappedType(), OS); + OS << " btf_type_tag(" << T->getAttr()->getBTFTypeTag() << ")"; +} + +void TypePrinter::printBTFTagAttributedAfter(const BTFTagAttributedType *T, + raw_ostream &OS) { + printAfter(T->getWrappedType(), OS); +} + void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T, raw_ostream &OS) { OS << "" << T->getDecl()->getName() diff --git a/tools/xref/Xref.cpp b/tools/xref/Xref.cpp index 5c028e47..56b6b185 100644 --- a/tools/xref/Xref.cpp +++ b/tools/xref/Xref.cpp @@ -185,7 +185,6 @@ static Session& GetSession(const httplib::Request& req) { if (kvp == sessions.end()) { session.Id = id; session.Context = std::make_unique(); - session.Context->enableOpaquePointers(); } RemoveOldSessions();