From d482586a283909be3e263783d3e35ce3ec7c48a6 Mon Sep 17 00:00:00 2001 From: clin99 <34017491+clin99@users.noreply.github.com> Date: Mon, 31 Oct 2022 23:03:55 -0400 Subject: [PATCH 1/3] Update main.cpp Add support for LLVM 13.0.0 --- main.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/main.cpp b/main.cpp index 0753191..d01a1ca 100644 --- a/main.cpp +++ b/main.cpp @@ -235,6 +235,9 @@ class ConstexprFunctionASTVisitor #if LLVM_VERSION_MAJOR <= 9 if (!sema.CheckConstexprFunctionBody(func, func->getBody())) return true; +#elif LLVM_VERSION_MAJOR == 13 + if(!sema.CheckConstexprFunctionDefinition(func, Sema::CheckConstexprKind::CheckValid)) + return true; #endif if (!CheckConstexprParameterTypes(sema, func)) @@ -247,7 +250,11 @@ class ConstexprFunctionASTVisitor // Mark function as constexpr, the next ast visitor will use this // information to find constexpr vardecls +#if LLVM_VERSION_MAJOR == 13 + func->setConstexprKind(ConstexprSpecKind::Constexpr); +#else func->setConstexprKind(CSK_constexpr); +#endif // Create diagnostic const auto FixIt = clang::FixItHint::CreateInsertion(loc, "constexpr "); @@ -305,9 +312,12 @@ class ConstexprVarDeclFunctionASTVisitor if (!ty.isConstQualified()) return true; +#if LLVM_VERSION_MAJOR != 13 // Is init an integral constant expression if (!var->checkInitIsICE()) return true; + } +#endif // Does the init function use dependent values if (Init->isValueDependent()) @@ -317,9 +327,17 @@ class ConstexprVarDeclFunctionASTVisitor if (!var->evaluateValue()) return true; +#if LLVM_VERSION_MAJOR == 13 + if(!var->hasConstantInitialization()) + return true; + + if (!var->hasICEInitializer(CI_.getASTContext())) + return true; +#else // Is init an ice if (!var->isInitICE()) return true; +#endif // Create Diagnostic/FixIt const auto FixIt = clang::FixItHint::CreateInsertion(loc, "constexpr "); @@ -410,8 +428,19 @@ class FunctionDeclFrontendAction : public clang::ASTFrontendAction { }; int main(int argc, const char **argv) { + +#if LLVM_VERSION_MAJOR == 13 + auto ExpectedParser = CommonOptionsParser::create(argc, argv, ConstexprCategory); + if (!ExpectedParser) { + llvm::errs() << ExpectedParser.takeError(); + return 1; + } + CommonOptionsParser& OptionsParser = ExpectedParser.get(); +#else CommonOptionsParser OptionsParser(argc, argv, ConstexprCategory); +#endif + ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); Tool.run(newFrontendActionFactory().get()); From 522f9c901dffd351719a075c4d2929bd0cae5d89 Mon Sep 17 00:00:00 2001 From: clin99 <34017491+clin99@users.noreply.github.com> Date: Mon, 31 Oct 2022 23:09:31 -0400 Subject: [PATCH 2/3] Update CMakeLists.txt Update CMakeList to enable LLVM 13 --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae6cfdb..b135805 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,9 @@ find_package(LLVM REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") -if((${LLVM_PACKAGE_VERSION} VERSION_LESS "9.0.0") +if(((${LLVM_PACKAGE_VERSION} VERSION_LESS "9.0.0") OR (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "12")) + AND (NOT (${LLVM_PACKAGE_VERSION} VERSION_EQUAL "13"))) message(FATAL_ERROR "Only LLVM 9 through 11 are supported.") endif() From 3c0d28e306595368567ca6f644cecedc51ec45c3 Mon Sep 17 00:00:00 2001 From: clin99 <34017491+clin99@users.noreply.github.com> Date: Tue, 1 Nov 2022 23:22:04 -0400 Subject: [PATCH 3/3] Fix a missing parenthesis Fix a missing parenthesis which causes the build failure. --- main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/main.cpp b/main.cpp index d01a1ca..6735b5c 100644 --- a/main.cpp +++ b/main.cpp @@ -316,7 +316,6 @@ class ConstexprVarDeclFunctionASTVisitor // Is init an integral constant expression if (!var->checkInitIsICE()) return true; - } #endif // Does the init function use dependent values