llvm-project/clang/test/Analysis/stackaddrleak.c
Ted Kremenek 17504bea33 Rework StackAddrLeakChecker to find stores of stack memory addresses to global variables
by inspecting the Store bindings instead of iterating over all the global variables
in a translation unit.  By looking at the store directly, we avoid cases where we cannot
directly load from the global variable, such as an array (which can result in an assertion failure)
and it also catches cases where we store stack addresses to non-scalar globals.
Also, but not iterating over all the globals in the translation unit, we maintain cache
locality, and the complexity of the checker becomes restricted to the complexity of the
analyzed function, and doesn't scale with the size of the translation unit.

This fixes PR 7383.

llvm-svn: 106184
2010-06-17 00:24:44 +00:00

27 lines
707 B
C

// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -verify %s
char const *p;
void f0() {
char const str[] = "This will change";
p = str; // expected-warning {{Stack address was saved into a global variable.}}
}
void f1() {
char const str[] = "This will change";
p = str;
p = 0; // no-warning
}
void f2() {
p = (const char *) __builtin_alloca(12); // expected-warning {{Stack address was saved into a global variable.}}
}
// PR 7383 - previosly the stack address checker would crash on this example
// because it would attempt to do a direct load from 'pr7383_list'.
static int pr7383(__const char *__)
{
return 0;
}
extern __const char *__const pr7383_list[];