From: George Karpenkov Date: Fri, 23 Feb 2018 23:26:57 +0000 (+0000) Subject: [analyzer] Relax the assert used when traversing the node graph. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=712969ac082c72882fdba1226a963c4d3ea3378d;p=clang [analyzer] Relax the assert used when traversing the node graph. The assertion gets exposed when changing the exploration order. This is a quick hacky fix, but the intention is that if the nodes do merge, it should not matter which predecessor should be traverse. A proper fix would be not to traverse predecessors at all, as all information relevant for any decision should be avilable locally. rdar://37540480 Differential Revision: https://reviews.llvm.org/D42773 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325977 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/lib/StaticAnalyzer/Core/ExprEngineC.cpp index 3e7a50365f..c3c1cb93fd 100644 --- a/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -760,7 +760,11 @@ void ExprEngine::VisitGuardedExpr(const Expr *Ex, for (const ExplodedNode *N = Pred ; N ; N = *N->pred_begin()) { ProgramPoint PP = N->getLocation(); if (PP.getAs() || PP.getAs()) { - assert(N->pred_size() == 1); + // If the state N has multiple predecessors P, it means that successors + // of P are all equivalent. + // In turn, that means that all nodes at P are equivalent in terms + // of observable behavior at N, and we can follow any of them. + // FIXME: a more robust solution which does not walk up the tree. continue; } SrcBlock = PP.castAs().getSrc(); diff --git a/test/Analysis/exploration_order/noexprcrash.c b/test/Analysis/exploration_order/noexprcrash.c new file mode 100644 index 0000000000..75c2f0e679 --- /dev/null +++ b/test/Analysis/exploration_order/noexprcrash.c @@ -0,0 +1,17 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config exploration_strategy=unexplored_first %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config exploration_strategy=dfs %s + +extern void clang_analyzer_eval(int); + +typedef struct { char a; } b; +int c(b* input) { + int x = (input->a ?: input) ? 1 : 0; // expected-warning{{pointer/integer type mismatch}} + if (input->a) { + // FIXME: The value should actually be "TRUE", + // but is incorrect due to a bug. + clang_analyzer_eval(x); // expected-warning{{FALSE}} + } else { + clang_analyzer_eval(x); // expected-warning{{TRUE}} + } + return x; +}