mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 05:16:42 +00:00

This expands checking for more expressions. This will check underflow and loss of precision when using call expressions like: void foo(unsigned); int i = -1; foo(i); This also includes other expressions as well, so it can catch negative indices to std::vector since it uses unsigned integers for [] and .at() function. Patch by: @pfultz2 Differential Revision: https://reviews.llvm.org/D46081
23 lines
424 B
C++
23 lines
424 B
C++
// RUN: %clang_analyze_cc1 -Wno-conversion -Wno-tautological-constant-compare -analyzer-checker=core,alpha.core.Conversion -verify %s
|
|
|
|
// expected-no-diagnostics
|
|
|
|
void dontwarn1() {
|
|
unsigned long x = static_cast<unsigned long>(-1);
|
|
}
|
|
|
|
void dontwarn2(unsigned x) {
|
|
if (x == static_cast<unsigned>(-1)) {
|
|
}
|
|
}
|
|
|
|
struct C {
|
|
C(unsigned x, unsigned long y) {}
|
|
};
|
|
|
|
void f(C) {}
|
|
|
|
void functioncall1(long x) {
|
|
f(C(64, x));
|
|
}
|