Skip to content

Commit

Permalink
[analyzer] Fix the crash in IteratorChecker.cpp when 'SymbolConjured'…
Browse files Browse the repository at this point in the history
… has a null Stmt.

When the loop has a null terminator statement and sets 'widen-loops=true', 'invalidateRegions' will constructs the 'SymbolConjured' with null 'Stmt'. And this will lead to a crash in 'IteratorChecker.cpp'. This patch use 'dyn_cast_or_null<>' instead of 'dyn_cast<>' in IteratorChecker.cpp.

Differential Revision: https://reviews.llvm.org/D44606

llvm-svn: 327962
  • Loading branch information
movie-travel-code committed Mar 20, 2018
1 parent bf3213e commit 073d5f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
Expand Up @@ -604,7 +604,7 @@ BinaryOperator::Opcode getOpcode(const SymExpr *SE) {
if (const auto *BSE = dyn_cast<BinarySymExpr>(SE)) {
return BSE->getOpcode();
} else if (const auto *SC = dyn_cast<SymbolConjured>(SE)) {
const auto *COE = dyn_cast<CXXOperatorCallExpr>(SC->getStmt());
const auto *COE = dyn_cast_or_null<CXXOperatorCallExpr>(SC->getStmt());
if (!COE)
return BO_Comma; // Extremal value, neither EQ nor NE
if (COE->getOperator() == OO_EqualEqual) {
Expand Down
14 changes: 14 additions & 0 deletions clang/test/Analysis/loop-widening.c
@@ -1,4 +1,5 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-max-loop 4 -analyzer-config widen-loops=true -verify %s
// RUN: %clang_analyze_cc1 -DTEST_NULL_TERM -analyzer-checker=core,unix.Malloc,debug.ExprInspection,alpha.cplusplus.IteratorRange -analyzer-max-loop 4 -analyzer-config widen-loops=true -verify %s

void clang_analyzer_eval(int);
void clang_analyzer_warnIfReached();
Expand Down Expand Up @@ -188,3 +189,16 @@ void nested_loop_inner_widen() {
}
clang_analyzer_eval(i >= 2); // expected-warning {{TRUE}}
}

#ifdef TEST_NULL_TERM
void null_terminator_loop_widen(int *a) {
int c;
// Loop widening will call 'invalidateRegions()' and 'invalidateRegions()'
// will construct the SymbolConjured with null Stmt because of the null
// terminator statement. Accessing the null Stmt will cause a crash.
for (;;) {
c = *a; // no-crash
a++;
}
}
#endif

0 comments on commit 073d5f0

Please sign in to comment.