Ericsson / clang

Cross Translation Unit analysis capability for Clang Static Analyzer. (Fork of official clang at http://llvm.org/git/clang)
http://clang.llvm.org/
Other
15 stars 10 forks source link

Assertion `CachedFieldIndex && "failed to find field in parent"' failed #442

Closed balazske closed 6 years ago

balazske commented 6 years ago
clang-6.0: llvm/tools/clang/lib/AST/Decl.cpp:3677: unsigned int clang::FieldDecl::getFieldIndex() const: Assertion `CachedFieldIndex && "failed to find field in parent"' failed.
#0 0x00007f2695af1497 llvm::sys::PrintStackTrace(llvm::raw_ostream&) llvm/lib/Support/Unix/Signals.inc:398:0
#1 0x00007f2695af1528 PrintStackTraceSignalHandler(void*) llvm/lib/Support/Unix/Signals.inc:462:0
#2 0x00007f2695aef910 llvm::sys::RunSignalHandlers() llvm/lib/Support/Signals.cpp:49:0
#3 0x00007f2695af0e2f SignalHandler(int) llvm/lib/Support/Unix/Signals.inc:252:0
#4 0x00007f26921a4cb0 (/lib/x86_64-linux-gnu/libc.so.6+0x36cb0)
#5 0x00007f26921a4c37 gsignal /build/eglibc-ripdx6/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#6 0x00007f26921a8028 abort /build/eglibc-ripdx6/eglibc-2.19/stdlib/abort.c:91:0
#7 0x00007f269219dbf6 __assert_fail_base /build/eglibc-ripdx6/eglibc-2.19/assert/assert.c:92:0
#8 0x00007f269219dca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#9 0x00007f268dd05e75 clang::FieldDecl::getFieldIndex() const llvm/tools/clang/lib/AST/Decl.cpp:3678:0
#10 0x00007f268dd9b372 HandleLValueMember((anonymous namespace)::EvalInfo&, clang::Expr const*, (anonymous namespace)::LValue&, clang::FieldDecl const*, clang::ASTRecordLayout const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:2301:0
#11 0x00007f268ddc5b5a (anonymous namespace)::LValueExprEvaluatorBase<(anonymous namespace)::LValueExprEvaluator>::VisitMemberExpr(clang::MemberExpr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:5012:0
#12 0x00007f268dda5669 (anonymous namespace)::LValueExprEvaluator::VisitMemberExpr(clang::MemberExpr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:5334:0
#13 0x00007f268ddc4d3f clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*) /build_d/tools/clang/include/clang/AST/StmtNodes.inc:597:0
#14 0x00007f268dddc318 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::LValueExprEvaluator>::VisitParenExpr(clang::ParenExpr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:4562:0
#15 0x00007f268ddc4f67 clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*) /build_d/tools/clang/include/clang/AST/StmtNodes.inc:743:0
#16 0x00007f268dda41ef EvaluateLValue(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) llvm/tools/clang/lib/AST/ExprConstant.cpp:5154:0
#17 0x00007f268dda6342 (anonymous namespace)::PointerExprEvaluator::evaluateLValue(clang::Expr const*, (anonymous namespace)::LValue&) llvm/tools/clang/lib/AST/ExprConstant.cpp:5548:0
#18 0x00007f268dda71b9 (anonymous namespace)::PointerExprEvaluator::VisitCastExpr(clang::CastExpr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:5744:0
#19 0x00007f268ddde311 clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::PointerExprEvaluator, bool>::VisitImplicitCastExpr(clang::ImplicitCastExpr const*) /build_d/tools/clang/include/clang/AST/StmtNodes.inc:423:0
#20 0x00007f268ddc687b clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::PointerExprEvaluator, bool>::Visit(clang::Stmt const*) /build_d/tools/clang/include/clang/AST/StmtNodes.inc:423:0
#21 0x00007f268dda68da EvaluatePointer(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) llvm/tools/clang/lib/AST/ExprConstant.cpp:5634:0
#22 0x00007f268ddc5ce8 (anonymous namespace)::LValueExprEvaluatorBase<(anonymous namespace)::LValueExprEvaluator>::evaluatePointer(clang::Expr const*, (anonymous namespace)::LValue&) llvm/tools/clang/lib/AST/ExprConstant.cpp:4973:0
#23 0x00007f268dda56f6 (anonymous namespace)::LValueExprEvaluator::VisitArraySubscriptExpr(clang::ArraySubscriptExpr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:5342:0
#24 0x00007f268ddc46e5 clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*) /build_d/tools/clang/include/clang/AST/StmtNodes.inc:157:0
#25 0x00007f268dda41ef EvaluateLValue(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) llvm/tools/clang/lib/AST/ExprConstant.cpp:5154:0
#26 0x00007f268ddd30e1 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::IntExprEvaluator>::VisitCastExpr(clang::CastExpr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:4861:0
#27 0x00007f268ddb6233 (anonymous namespace)::IntExprEvaluator::VisitCastExpr(clang::CastExpr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:8961:0
#28 0x00007f268ddefb2b clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::IntExprEvaluator, bool>::VisitImplicitCastExpr(clang::ImplicitCastExpr const*) /build_d/tools/clang/include/clang/AST/StmtNodes.inc:423:0
#29 0x00007f268ddd1b2f clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*) /build_d/tools/clang/include/clang/AST/StmtNodes.inc:423:0
#30 0x00007f268ddbb766 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:9914:0
#31 0x00007f268ddb2099 (anonymous namespace)::DataRecursiveIntBinOpEvaluator::EvaluateExpr(clang::Expr const*, (anonymous namespace)::DataRecursiveIntBinOpEvaluator::EvalResult&) llvm/tools/clang/lib/AST/ExprConstant.cpp:8130:0
#32 0x00007f268ddb2d51 (anonymous namespace)::DataRecursiveIntBinOpEvaluator::process((anonymous namespace)::DataRecursiveIntBinOpEvaluator::EvalResult&) llvm/tools/clang/lib/AST/ExprConstant.cpp:8313:0
#33 0x00007f268ddb1f4e (anonymous namespace)::DataRecursiveIntBinOpEvaluator::Traverse(clang::BinaryOperator const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:8095:0
#34 0x00007f268ddb30d1 (anonymous namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:8374:0
#35 0x00007f268ddeecc9 clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::IntExprEvaluator, bool>::VisitBinNE(clang::BinaryOperator const*) llvm/tools/clang/include/clang/AST/StmtVisitor.h:135:0
#36 0x00007f268ddd11dc clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*) llvm/tools/clang/include/clang/AST/StmtVisitor.h:67:0
#37 0x00007f268ddf0290 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::IntExprEvaluator>::VisitParenExpr(clang::ParenExpr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:4562:0
#38 0x00007f268ddd1fdf clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*) /build_d/tools/clang/include/clang/AST/StmtNodes.inc:743:0
#39 0x00007f268ddbb766 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) llvm/tools/clang/lib/AST/ExprConstant.cpp:9914:0
#40 0x00007f268ddbc23c EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) llvm/tools/clang/lib/AST/ExprConstant.cpp:10018:0
#41 0x00007f268ddbc649 clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&, clang::ASTContext const&) const llvm/tools/clang/lib/AST/ExprConstant.cpp:10073:0
#42 0x00007f268ddbc6ca clang::Expr::EvaluateAsBooleanCondition(bool&, clang::ASTContext const&) const llvm/tools/clang/lib/AST/ExprConstant.cpp:10079:0
#43 0x00007f268d5513c1 (anonymous namespace)::CFGBuilder::evaluateAsBooleanConditionNoCache(clang::Expr*) llvm/tools/clang/lib/Analysis/CFG.cpp:1054:0
#44 0x00007f268d55105a (anonymous namespace)::CFGBuilder::tryEvaluateBool(clang::Expr*) llvm/tools/clang/lib/Analysis/CFG.cpp:1006:0
#45 0x00007f268d555faa (anonymous namespace)::CFGBuilder::VisitIfStmt(clang::IfStmt*) llvm/tools/clang/lib/Analysis/CFG.cpp:2478:0
#46 0x00007f268d553a58 (anonymous namespace)::CFGBuilder::Visit(clang::Stmt*, (anonymous namespace)::AddStmtChoice) llvm/tools/clang/lib/Analysis/CFG.cpp:1745:0
#47 0x00007f268d54f867 (anonymous namespace)::CFGBuilder::addStmt(clang::Stmt*) llvm/tools/clang/lib/Analysis/CFG.cpp:652:0
#48 0x00007f268d555147 (anonymous namespace)::CFGBuilder::VisitCompoundStmt(clang::CompoundStmt*) llvm/tools/clang/lib/Analysis/CFG.cpp:2173:0
#49 0x00007f268d55378c (anonymous namespace)::CFGBuilder::Visit(clang::Stmt*, (anonymous namespace)::AddStmtChoice) llvm/tools/clang/lib/Analysis/CFG.cpp:1675:0
#50 0x00007f268d54f867 (anonymous namespace)::CFGBuilder::addStmt(clang::Stmt*) llvm/tools/clang/lib/Analysis/CFG.cpp:652:0
#51 0x00007f268d558034 (anonymous namespace)::CFGBuilder::VisitWhileStmt(clang::WhileStmt*) llvm/tools/clang/lib/Analysis/CFG.cpp:3118:0
#52 0x00007f268d553d7d (anonymous namespace)::CFGBuilder::Visit(clang::Stmt*, (anonymous namespace)::AddStmtChoice) llvm/tools/clang/lib/Analysis/CFG.cpp:1820:0
#53 0x00007f268d54f867 (anonymous namespace)::CFGBuilder::addStmt(clang::Stmt*) llvm/tools/clang/lib/Analysis/CFG.cpp:652:0
#54 0x00007f268d555147 (anonymous namespace)::CFGBuilder::VisitCompoundStmt(clang::CompoundStmt*) llvm/tools/clang/lib/Analysis/CFG.cpp:2173:0
#55 0x00007f268d55378c (anonymous namespace)::CFGBuilder::Visit(clang::Stmt*, (anonymous namespace)::AddStmtChoice) llvm/tools/clang/lib/Analysis/CFG.cpp:1675:0
#56 0x00007f268d54f867 (anonymous namespace)::CFGBuilder::addStmt(clang::Stmt*) llvm/tools/clang/lib/Analysis/CFG.cpp:652:0
#57 0x00007f268d551809 (anonymous namespace)::CFGBuilder::buildCFG(clang::Decl const*, clang::Stmt*) llvm/tools/clang/lib/Analysis/CFG.cpp:1144:0
#58 0x00007f268d55b8a8 clang::CFG::buildCFG(clang::Decl const*, clang::Stmt*, clang::ASTContext*, clang::CFG::BuildOptions const&) llvm/tools/clang/lib/Analysis/CFG.cpp:4207:0
#59 0x00007f268d532620 clang::AnalysisDeclContext::getCFG() llvm/tools/clang/lib/Analysis/AnalysisDeclContext.cpp:211:0
#60 0x00007f26868d9b79 mayInlineDecl(clang::AnalysisDeclContext*, clang::AnalyzerOptions&) llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp:775:0
#61 0x00007f26868d9ddd clang::ento::ExprEngine::shouldInlineCall(clang::ento::CallEvent const&, clang::Decl const*, clang::ento::ExplodedNode const*) llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp:830:0
#62 0x00007f26868da2b4 clang::ento::ExprEngine::defaultEvalCall(clang::ento::NodeBuilder&, clang::ento::ExplodedNode*, clang::ento::CallEvent const&) llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp:917:0
#63 0x00007f2686868ac9 clang::ento::CheckerManager::runCheckersForEvalCall(clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&, clang::ento::CallEvent const&, clang::ento::ExprEngine&) llvm/tools/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:619:0
#64 0x00007f26868d8dd9 clang::ento::ExprEngine::evalCall(clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNode*, clang::ento::CallEvent const&) llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp:521:0
#65 0x00007f26868d8c66 clang::ento::ExprEngine::VisitCallExpr(clang::CallExpr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp:487:0
#66 0x00007f26868a2906 clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:1306:0
#67 0x00007f268689ef61 clang::ento::ExprEngine::ProcessStmt(clang::CFGStmt, clang::ento::ExplodedNode*) llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:567:0
#68 0x00007f268689e238 clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:410:0
#69 0x00007f2686886955 clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock const*, unsigned int, clang::ento::ExplodedNode*) llvm/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:533:0
#70 0x00007f268688575c clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) llvm/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:280:0
#71 0x00007f26868852ce clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) llvm/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:216:0
#72 0x00007f26885ec80c clang::ento::ExprEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int) llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h:114:0
#73 0x00007f26885949ff (anonymous namespace)::AnalysisConsumer::ActionExprEngine(clang::Decl*, bool, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*> >*) llvm/tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:725:0
#74 0x00007f2688594b1e (anonymous namespace)::AnalysisConsumer::RunPathSensitiveChecks(clang::Decl*, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*> >*) llvm/tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:742:0
#75 0x00007f26885947d6 (anonymous namespace)::AnalysisConsumer::HandleCode(clang::Decl*, unsigned int, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*> >*) llvm/tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:688:0
#76 0x00007f26885937d0 (anonymous namespace)::AnalysisConsumer::HandleDeclsCallGraph(unsigned int) llvm/tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:504:0
#77 0x00007f2688593baa (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) llvm/tools/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:555:0
#78 0x00007f2692e66bb2 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) llvm/tools/clang/lib/Frontend/MultiplexConsumer.cpp:310:0
#79 0x00007f268bab361b clang::ParseAST(clang::Sema&, bool, bool) llvm/tools/clang/lib/Parse/ParseAST.cpp:161:0
#80 0x00007f2692e3a006 clang::ASTFrontendAction::ExecuteAction() llvm/tools/clang/lib/Frontend/FrontendAction.cpp:1000:0
#81 0x00007f2692e39a77 clang::FrontendAction::Execute() llvm/tools/clang/lib/Frontend/FrontendAction.cpp:901:0
#82 0x00007f2692dc6a55 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:992:0
#83 0x00007f26928bcd39 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:252:0
#84 0x000000000044cecd cc1_main(llvm::ArrayRef<char const*>, char const*, void*) llvm/tools/clang/tools/driver/cc1_main.cpp:221:0
#85 0x0000000000442909 ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) llvm/tools/clang/tools/driver/driver.cpp:309:0
#86 0x00000000004435f1 main llvm/tools/clang/tools/driver/driver.cpp:388:0
#87 0x00007f269218ff45 __libc_start_main /build/eglibc-ripdx6/eglibc-2.19/csu/libc-start.c:321:0
#88 0x0000000000440179 _start (/build_d/bin/clang-6.0+0x440179)
balazske commented 6 years ago

There is a following definition in select.h:

/* fd_set for select and pselect.  */
typedef struct
  {
    /* XPG4.2 requires this member name.  Otherwise avoid the name
       from the global namespace.  */
#ifdef __USE_XOPEN
    __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
# define __FDS_BITS(set) ((set)->fds_bits)
#else
    __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
# define __FDS_BITS(set) ((set)->__fds_bits)
#endif
  } fd_set;

The already imported struct is the one with __fds_bits, the to be imported is one with fds_bits. These are structurally not equivalent (one field with different name). What to do in this case?

If the conflicting case would result in failed import of the record, a !hasBody assertion occurs somewhere (not checked if it is related but possibly yes). A possibility is to merge the definitions, import the new fields into the existing struct (but it can be that there are fields with different type but same name, these can not be imported, and a AST structure is created that does not correspond to source code).

balazske commented 6 years ago

Probably the compile commands or include files are wrong?

martong commented 6 years ago

Yes, this is indeed a hard situation. In this case I would create another fd_set with the fds_bits. At the moment, we do not create the second fd_set, right? Having one struct with both fields is probably not correct. Still, we will have a very hard time to distinguish this situation from that one when the structs are indeed inequivalent (ODR is violated). Perhaps, we should track the macro definitions on which the definition of a record is dependent upon?

Adding @dkurpp and @zporky, maybe they have some better ideas.

martong commented 6 years ago

My other thought: Strictly speaking this is ODR violation! So we could diagnose the ODR violation and then exit (which is not equal to a crash).

martong commented 6 years ago

Adding @dkrupp

martong commented 6 years ago

Here are my 50 cents: This is ODR violation, and we cannot handle this in the ASTImporter level, clang should exit in this case. The error must be handled on the build system / compile commands json level. Two TUs, one with __USE_XOPEN and another without it could never have been linked into one lib/executable (that is undefined behaviour). Thus, we may not expect to analyse together such two TUs.

Adding @whisperity , to hear other opinions too.

balazske commented 6 years ago

I think it is not good to have multiple records (struct or other) with same name (and different content). The current implementation does this, but something goes wrong with import of the field and the crash happens. (The two different struct's with same name are linked together with previous decl chain, this is wrong to do. If there is somewhere a map-like structure for name lookup it can not work with multiple things with same name.)

balazske commented 6 years ago

Probably the handleNameConflict should be implemented to generate a new name?

balazske commented 6 years ago

Related pull request:

457