aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Martins <smartins@kde.org>2018-09-22 20:25:42 +0100
committerSergio Martins <smartins@kde.org>2018-09-22 20:25:42 +0100
commitd6cb7569816ce11160a2eeebd58a92a345b59f70 (patch)
treeaae108fd918eb0928d135406103df67355b418ca
parentc650de49e3bdcb6f2116c0a0f76e1924615f48f6 (diff)
Workaround crash with LLVM 7upstream/1.3
If clazy is compiled with clang instead of gcc it might crash with: ==10637== Process terminating with default action of signal 11 (SIGSEGV): dumping core ==10637== Access not within mapped region at address 0x8 ==10637== at 0x19CDD8C: clang::ast_matchers::MatchFinder::MatchFinder(clang::ast_matchers::MatchFinder::MatchFinderOptions) (in /usr/lib/llvm-7/bin/clang) ==10637== by 0x9D75670: ClazyASTConsumer (Clazy.cpp:62) ==10637== by 0x9D75670: ClazyASTAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef) (Clazy.cpp:183) ==10637== by 0x9E29ED: clang::FrontendAction::CreateWrappedASTConsumer(clang::CompilerInstance&, llvm::StringRef) (in /usr/lib/llvm-7/bin/clang) ==10637== by 0x9E8FCA: clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, clang::FrontendInputFile const&) (in /usr/lib/llvm-7/bin/clang) ==10637== by 0x9AE3D5: clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (in /usr/lib/llvm-7/bin/clang) ==10637== by 0xA8C9FA: clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (in /usr/lib/llvm-7/bin/clang) ==10637== by 0x5822C7: cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (in /usr/lib/llvm-7/bin/clang) ==10637== by 0x571ACC: main (in /usr/lib/llvm-7/bin/clang) After debugging clazy and clang's code I couldn't find anything wrong with it. Valgrind's output doesn't make much sense, and simply compiling the Clazy.cpp translation unit with gcc instead of clang makes the crash go away and valgrind's output is clean. I'm assuming debian's LLVM was built with gcc and building clazy with clang will have some sort of incompatibility, or maybe it's simply a clang bug. The downside of this workaround is that qcolor-literal check will be disabled. Next step will be producing a minimal test case and reporting to LLVM. BUG: 392223 CCMAIL: Woebbeking@kde.org
-rw-r--r--CMakeLists.txt6
-rw-r--r--src/Clazy.cpp7
2 files changed, 13 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3bf424c3..0549f1fa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,6 +30,12 @@ add_definitions(-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS)
add_definitions(-D_GNU_SOURCE -DHAVE_CLANG_CONFIG_H)
option(CLAZY_BUILD_UTILS_LIB "Enable this option to build a library so you can reuse clazy's utility functions" OFF)
+option(CLAZY_AST_MATCHERS_CRASH_WORKAROUND "Disable AST Matchers if being built with clang. See bug #392223" ON)
+
+if (CLAZY_AST_MATCHERS_CRASH_WORKAROUND AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ message("Enabling AST Matchers workaround. Consider building with gcc instead. See bug #392223.")
+ add_definitions(-DCLAZY_DISABLE_AST_MATCHERS)
+endif()
if(CLAZY_BUILD_UTILS_LIB)
add_definitions(-DCLAZY_BUILD_UTILS_LIB)
diff --git a/src/Clazy.cpp b/src/Clazy.cpp
index 5ef48ae0..c1ff2c67 100644
--- a/src/Clazy.cpp
+++ b/src/Clazy.cpp
@@ -61,14 +61,19 @@ static void manuallyPopulateParentMap(ParentMap *map, Stmt *s)
ClazyASTConsumer::ClazyASTConsumer(ClazyContext *context)
: m_context(context)
+ , m_matchFinder(nullptr)
{
clang::ast_matchers::MatchFinder::MatchFinderOptions options;
+#ifndef CLAZY_DISABLE_AST_MATCHERS
m_matchFinder = new clang::ast_matchers::MatchFinder(options);
+#endif
}
void ClazyASTConsumer::addCheck(CheckBase *check)
{
+#ifndef CLAZY_DISABLE_AST_MATCHERS
check->registerASTMatchers(*m_matchFinder);
+#endif
m_createdChecks.push_back(check);
}
@@ -134,8 +139,10 @@ void ClazyASTConsumer::HandleTranslationUnit(ASTContext &ctx)
// Run our RecursiveAstVisitor based checks:
TraverseDecl(ctx.getTranslationUnitDecl());
+#ifndef CLAZY_DISABLE_AST_MATCHERS
// Run our AstMatcher base checks:
m_matchFinder->matchAST(ctx);
+#endif
}
static bool parseArgument(const string &arg, vector<string> &args)