Skip to content

Commit 754ae09

Browse files
author
einvbri
committed
[analyzer] Indicate UnarySymExpr is not supported by Z3
Random testing found that the Z3 wrapper does not support UnarySymExpr, which was added recently and not included in the original Z3 wrapper. For now, just avoid submitting expressions to Z3 to avoid compiler crashes. Some crash context ... clang -cc1 -analyze -analyzer-checker=core z3-unarysymexpr.c -analyzer-constraints=z3 Unsupported expression to reason about! UNREACHABLE executed at clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h:297! Stack dump: 3. <root>/clang/test/Analysis/z3-unarysymexpr.c:13:7: Error evaluating branch #0 <addr> llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) #1 <addr> llvm::sys::RunSignalHandlers() #8 <addr> clang::ento::SimpleConstraintManager::assumeAux( llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::NonLoc, bool) #9 <addr> clang::ento::SimpleConstraintManager::assume( llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::NonLoc, bool)
1 parent 51df8a3 commit 754ae09

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h

+7
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
278278
if (const SymbolCast *SC = dyn_cast<SymbolCast>(Sym))
279279
return canReasonAbout(SVB.makeSymbolVal(SC->getOperand()));
280280

281+
// If a UnarySymExpr is encountered, the Z3
282+
// wrapper does not support those. So indicate Z3 does not
283+
// support those and return.
284+
if (isa<UnarySymExpr>(Sym)) {
285+
return false;
286+
}
287+
281288
if (const BinarySymExpr *BSE = dyn_cast<BinarySymExpr>(Sym)) {
282289
if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(BSE))
283290
return canReasonAbout(SVB.makeSymbolVal(SIE->getLHS()));

clang/test/Analysis/z3-unarysymexpr.c

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s \
2+
// RUN: -analyzer-constraints=z3
3+
4+
// REQUIRES: Z3
5+
//
6+
// Previously Z3 analysis crashed when it encountered an UnarySymExpr, validate
7+
// that this no longer happens.
8+
//
9+
10+
// expected-no-diagnostics
11+
int negate(int x, int y) {
12+
if ( ~(x && y))
13+
return 0;
14+
return 1;
15+
}

0 commit comments

Comments
 (0)