[clang] [analyzer][NFC] Add ArrayBound tests to document casting bug (PR #127062)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 13 06:03:22 PST 2025
================
@@ -194,3 +194,34 @@ char test_comparison_with_extent_symbol(struct incomplete *p) {
return ((char *)p)[-1]; // no-warning
}
+int table[256], small_table[128];
+int test_cast_to_unsigned(signed char x) {
+ unsigned char y = x;
+ if (x >= 0)
+ return x;
+ // FIXME: Here the analyzer ignores the signed -> unsigned cast, and manages to
+ // load a negative value from an unsigned variable. This causes an underflow
+ // report, which is an ugly false positive.
+ // The underlying issue is tracked by Github ticket #39492.
+ return table[y]; // expected-warning {{Out of bound access to memory preceding}}
----------------
steakhal wrote:
Can we also dump the value range of this y sym?
That would probably highlight the "wrong assumption"
Maybe in the rest of the examples too. Wdyt?
https://github.com/llvm/llvm-project/pull/127062
More information about the cfe-commits
mailing list