Dependent patch adds UnarySymExpr, now I'd like to handle that for SMT
conversions like refutation.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Something is messed up with the diff. You refer to fromUnOp() but it's not defined anywhere.
No. There is no mess up here, the diff is correct. fromUnOp had been implemented way before. I missed that when I created the initial patch. So, we just have to call that preexisting function in getSymExpr.
There are Z3 refutation related assertions on open-source projects once the patch stack is applied. Interestingly it happens in fromBinOp.
clang-14: ../../git/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:96: static const llvm::SMTExpr* clang::ento::SMTConv::fromBinOp(llvm::SMTSolverRef&, const llvm::SMTExpr* const&, clang::BinaryOperator::Opcode, const llvm::SMTExpr* const&, bool): Assertion `*Solver->getSort(LHS) == *Solver->getSort(RHS) && "AST's must have the same sort!"' failed.
This is the minimal reproducer:
int b; long c(); void d(int e, long *f) { *f = e; } void k() { long a = c(); int g = a, h = g - 2, i = -h; _Bool j; d(i, &b); j &= b == 0; }
I'd like to delay the commit of the patch stack until we can fix that, since Z3 refutation is essential for most of our (internal) users.
- Fix Assertion `*Solver->getSort(LHS) == *Solver->getSort(RHS) && "AST's must have the same sort!"' failed.
I think it looks greatt
There are a couple questions you need to think about, but I don't insist about changing anything if the code works passed widescale testing.
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h | ||
---|---|---|
463 | Could this fail spuriously due to a constness mismatch, since you compare QualTypes instead of types? ALternatively, we could emit this cast only if the bitwidths are different. (which caused the sort difference, thus the crash) | |
clang/test/Analysis/unary-sym-expr-z3-refutation.c | ||
29 | So this is the implicit cast that we don't emit. |
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h | ||
---|---|---|
463 |
No, I don't think so. The underlying fromCast would simply return the same SMTExprRef if the bitwidths are the same.
The same as in case of the qualifier mismatch.
Good point. The code would be more direct and efficient like that, I am going to update. | |
clang/test/Analysis/unary-sym-expr-z3-refutation.c | ||
29 | Yes. Actually, without emitting SymbolCasts: h is evaluated as $L<long> + 1. However, the expression's type is int. |
I would prefer the fromUnOp similarly to how fromBinOp is called.