2013-02-08 07:05:37 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,debug.ExprInspection -verify %s
|
|
|
|
|
|
|
|
void clang_analyzer_eval(int);
|
|
|
|
|
|
|
|
void use(int);
|
|
|
|
id foo(int x) {
|
|
|
|
if (x)
|
|
|
|
return 0;
|
|
|
|
static id p = foo(1);
|
|
|
|
clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
|
|
|
|
return p;
|
2013-02-26 03:45:34 +08:00
|
|
|
}
|
|
|
|
|
2013-03-21 04:36:01 +08:00
|
|
|
const int &globalIntRef = 42;
|
2013-02-26 03:45:34 +08:00
|
|
|
|
2013-03-21 04:36:01 +08:00
|
|
|
void testGlobalRef() {
|
2013-02-26 03:45:34 +08:00
|
|
|
// FIXME: Should be TRUE, but should at least not crash.
|
2013-03-21 04:36:01 +08:00
|
|
|
clang_analyzer_eval(globalIntRef == 42); // expected-warning{{UNKNOWN}}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int globalInt;
|
2013-04-16 04:39:41 +08:00
|
|
|
extern struct {
|
|
|
|
int value;
|
|
|
|
} globalStruct;
|
2013-03-21 04:36:01 +08:00
|
|
|
extern void invalidateGlobals();
|
|
|
|
|
|
|
|
void testGlobalInvalidation() {
|
2013-04-16 04:39:41 +08:00
|
|
|
clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
|
|
|
|
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
|
|
|
|
|
2013-03-21 04:36:01 +08:00
|
|
|
if (globalInt != 42)
|
|
|
|
return;
|
2013-04-16 04:39:41 +08:00
|
|
|
if (globalStruct.value != 43)
|
|
|
|
return;
|
2013-03-21 04:36:01 +08:00
|
|
|
clang_analyzer_eval(globalInt == 42); // expected-warning{{TRUE}}
|
2013-04-16 04:39:41 +08:00
|
|
|
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{TRUE}}
|
2013-03-21 04:36:01 +08:00
|
|
|
|
|
|
|
invalidateGlobals();
|
2013-02-26 03:45:34 +08:00
|
|
|
clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
|
2013-04-16 04:39:41 +08:00
|
|
|
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
|
2013-02-26 03:45:34 +08:00
|
|
|
}
|
2013-03-21 04:36:01 +08:00
|
|
|
|
|
|
|
void testGlobalInvalidationWithDirectBinding() {
|
2013-04-16 04:39:41 +08:00
|
|
|
clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
|
|
|
|
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
|
|
|
|
|
2013-03-21 04:36:01 +08:00
|
|
|
globalInt = 42;
|
2013-04-16 04:39:41 +08:00
|
|
|
globalStruct.value = 43;
|
2013-03-21 04:36:01 +08:00
|
|
|
clang_analyzer_eval(globalInt == 42); // expected-warning{{TRUE}}
|
2013-04-16 04:39:41 +08:00
|
|
|
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{TRUE}}
|
2013-03-21 04:36:01 +08:00
|
|
|
|
|
|
|
invalidateGlobals();
|
2013-04-16 04:39:41 +08:00
|
|
|
clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
|
|
|
|
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
|
2013-03-21 04:36:01 +08:00
|
|
|
}
|