Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
28 changes: 28 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 ");
Expand Down Expand Up @@ -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())
Expand All @@ -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 ");
Expand Down Expand Up @@ -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<FunctionDeclFrontendAction>().get());
Expand Down