llvm-project/clang/test/Analysis/svalbuilder-simplify-no-crash.c
DonatNagyE 23b88e8123
[analyzer] Remove inaccurate legacy handling of bad bitwise shifts (#66647)
Previously, bitwise shifts with constant operands were validated by the
checker `core.UndefinedBinaryOperatorResult`. However, this logic was
unreliable, and commit 25b9696b61e53a958e217bb3d0eab66350dc187f added
the dedicated checker `core.BitwiseShift` which validated the
preconditions of all bitwise shifts with a more accurate logic (that
uses the real types from the AST instead of the unreliable type
information encoded in `APSInt` objects).

This commit disables the inaccurate logic that could mark bitwise shifts
as 'undefined' and removes the redundant shift-related warning messages
from core.UndefinedBinaryOperatorResult. The tests that were validating
this logic are also deleted by this commit; but I verified that those
testcases trigger the expected bug reports from `core.BitwiseShift`. (I
didn't convert them to tests of `core.BitwiseShift`, because that
checker already has its own extensive test suite with many analogous
testcases.)

I hope that there will be a time when the constant folding will be
reliable, but until then we need hacky solutions like this improve the
quality of results.
2023-09-29 20:02:38 +02:00

16 lines
346 B
C

// RUN: %clang_analyze_cc1 %s \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-checker=debug.ExprInspection \
// RUN: -verify
// Here, we test that svalbuilder simplification does not produce any
// assertion failure.
// expected-no-diagnostics
void crashing(long a, _Bool b) {
(void)(a & 1 && 0);
b = a & 1;
(void)(b << 1);
}