Crash in NonNullParamChecker.cpp
| Bugzilla Link | 24914 |
| Resolution | FIXED |
| Resolved on | Nov 30, 2015 14:44 |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @devincoughlin,@AnnaZaks,@Xazax-hun |
Extended Description
Application crashes. Logs bellow.
clang-tidy: ...clang/llvm/tools/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp:102: void {anonymous}::NonNullParamChecker::checkPreCall(const clang::ento::CallEvent&, clang::ento::CheckerContext&) const: Assertion `!haveRefTypeParam || DV->getAs
Program received signal SIGABRT, Aborted. 0x000000375c032625 in raise () from /lib64/libc.so.6 (gdb) bt #0 0x000000375c032625 in raise () from /lib64/libc.so.6 #1 0x000000375c033e05 in abort () from /lib64/libc.so.6 #2 0x000000375c02b74e in __assert_fail_base () from /lib64/libc.so.6 #3 0x000000375c02b810 in __assert_fail () from /lib64/libc.so.6 #4 0x0000000000b15b8a in (anonymous namespace)::NonNullParamChecker::checkPreCall(clang::ento::CallEvent const&, clang::ento::CheckerContext&) const () at ...clang/llvm/include/llvm/ADT/BitVector.h:225 #5 0x0000000000b838f2 in void expandGraphWithCheckers<(anonymous namespace)::CheckCallContext>((anonymous namespace)::CheckCallContext, clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&) () at ...clang/llvm/tools/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h:58 #6 0x0000000000b839ae in clang::ento::CheckerManager::runCheckersForCallEvent(bool, clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&, clang::ento::CallEvent const&, clang::ento::ExprEngine&, bool) () at ...clang/llvm/tools/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:285 #7 0x0000000000b9eb1e in clang::ento::ExprEngine::VisitCXXConstructExpr(clang::CXXConstructExpr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) () at ...clang/llvm/tools/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h:253 #8 0x0000000000b96cb7 in clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) () at ...clang/llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:1100 #9 0x0000000000b97c6a in clang::ento::ExprEngine::ProcessStmt(clang::CFGStmt, clang::ento::ExplodedNode*) () at ...clang/llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:446 #10 0x0000000000b97d83 in clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) () at ...clang/llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:295 #11 0x0000000000b87224 in clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock const*, unsigned int, clang::ento::ExplodedNode*) () at ...clang/llvm/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:503 #12 0x0000000000b87b99 in clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) () at ...clang/llvm/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:267 #13 0x0000000000b87d5e in clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) () at ...clang/llvm/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:223 #14 0x00000000006a51e9 in (anonymous namespace)::AnalysisConsumer::ActionExprEngine () at ...clang/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h:109 #15 0x00000000006a5598 in (anonymous namespace)::AnalysisConsumer::HandleCode(clang::Decl*, unsigned int, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*> >) () at ...clang/llvm/tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:689 #16 0x00000000006ab246 in (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit () at ...clang/llvm/tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:492 #17 0x00000000006d8da0 in clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) () at ...clang/llvm/tools/clang/lib/Frontend/MultiplexConsumer.cpp:296 #18 0x00000000007313a3 in clang::ParseAST(clang::Sema&, bool, bool) () at ...clang/llvm/tools/clang/lib/Parse/ParseAST.cpp:168 #19 0x00000000006cb430 in clang::FrontendAction::Execute() () at ...clang/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:439 #20 0x00000000006b297b in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) () at ...clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:838 #21 0x000000000068ca47 in clang::tooling::FrontendActionFactory::runInvocation(clang::CompilerInvocation, clang::FileManager*, std::shared_ptrclang::PCHContainerOperations, clang::DiagnosticConsumer*) () at ...clang/llvm/tools/clang/lib/Tooling/Tooling.cpp:274 #22 0x000000000068b1e3 in clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, clang::CompilerInvocation*, std::shared_ptrclang::PCHContainerOperations) () at ...clang/llvm/tools/clang/lib/Tooling/Tooling.cpp:250 #23 0x000000000068c23f in clang::tooling::ToolInvocation::run() () at ...clang/llvm/tools/clang/lib/Tooling/Tooling.cpp:235 #24 0x000000000068c526 in clang::tooling::ClangTool::run(clang::tooling::ToolAction*) () at ...clang/llvm/tools/clang/lib/Tooling/Tooling.cpp:369 #25 0x00000000005e4bc4 in clang::tidy::runClangTidy(std::unique_ptr<clang::tidy::ClangTidyOptionsProvider, std::default_deleteclang::tidy::ClangTidyOptionsProvider >, clang::tooling::CompilationDatabase const&, llvm::ArrayRefstd::string, std::vector<clang::tidy::ClangTidyError, std::allocatorclang::tidy::ClangTidyError >, clang::tidy::ProfileData) () at ...clang/llvm/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp:408 #26 0x000000000049378b in clang::tidy::clangTidyMain(int, char const**) () at ...clang/llvm/tools/clang/tools/extra/clang-tidy/tool/ClangTidyMain.cpp:317 #27 0x000000375c01ed5d in __libc_start_main () from /lib64/libc.so.6 #28 0x000000000048d555 in _start ()
mentioned in issue llvm/llvm-bugzilla-archive#25420
*** Bug llvm/llvm-bugzilla-archive#25420 has been marked as a duplicate of this bug. ***
r253157 should fix this. The issue was that even when a reference type was captured by copy, we were still referring to the original captured variable (rather than the field capture) to determine whether to treat it as a reference. This led to an extra load when getting the lvalue for a DeclRefExpr for a reference type captured by copy.
I was able to come up with a minimal example for the bug you linked, however I am not sure yet what to do about it.
The example looks like this:
struct Foo { int x, y; };
void processFoo(const Foo&);
void captureStructs(const Foo& f) { f { processFoo(f); }(); }
What actually happens: Because processFoo's argument is a reference, the nonnull param checker expects the sval of the argument to be a loc type sval. The analyzer however (at least right now) copies the value of f inside a field in the lambda object, and this results in a lazyCompoundVal which is nonloc, and that is passed to f, which triggers the assert
Could you attach a minimal example or a preprocessed source file so I can reproduce and fix the issue?
Does adding "-analyzer-config inline-lambdas=false" to the command line make this problem disappear?
Crash is caused by commit:
247426 [Static Analyzer] Lambda support. Differential Revision: http://reviews.llvm.org/D12652
Crashes on 60% of files in commercial project that have over 1 million lines of code.
Finding problematic code isn't easy.
About assert: !haveRefTypeParam -> const class std::function<void (_Bool)> & (4.9.4/functional:2192)
DeclRefExpr 0xa171be0 'const SomeInternalTypedefToStdFunction':'const class std::function<void (_Bool)>' lvalue ParmVar 0xa160ef0 'p_callback' 'const SomeInternalTypedefToStdFunction &'
I will try to find a better code.
This is something that is in code for no more than 1 month. There is any reason why so many asserts are in clang code ? During clang-tidy check implementation I saw over 20 different crashes, it's boring, couldn't check just don't work instead of crash... Now: read template structure size -> crash, get real type of method -> crash, ...
Could you attach the test case that we could use to reproduce this failure?
assigned to @tkremenek