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() diff --git a/main.cpp b/main.cpp index 0753191..6735b5c 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,11 @@ 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 +326,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 +427,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());