2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
|
2018-06-13 03:07:41 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-multi-file %s -o %t.plist
|
2019-06-11 22:21:32 +08:00
|
|
|
// RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/deref-track-symbolic-region.c.plist -
|
2012-09-06 06:31:55 +08:00
|
|
|
|
|
|
|
struct S {
|
|
|
|
int *x;
|
|
|
|
int y;
|
|
|
|
};
|
|
|
|
|
|
|
|
int *foo();
|
|
|
|
|
2013-03-02 11:20:52 +08:00
|
|
|
void test(struct S syz, int *pp) {
|
|
|
|
int m = 0;
|
|
|
|
syz.x = foo(); // expected-note{{Value assigned to 'syz.x'}}
|
|
|
|
|
|
|
|
struct S *ps = &syz;
|
|
|
|
if (ps->x)
|
2019-05-30 04:29:02 +08:00
|
|
|
//expected-note@-1{{Assuming field 'x' is null}}
|
|
|
|
//expected-note@-2{{Taking false branch}}
|
2012-09-06 06:31:55 +08:00
|
|
|
|
|
|
|
m++;
|
|
|
|
|
|
|
|
m += *syz.x; // expected-warning{{Dereference of null pointer (loaded from field 'x')}}
|
2013-03-02 11:20:52 +08:00
|
|
|
// expected-note@-1{{Dereference of null pointer (loaded from field 'x')}}
|
2012-09-06 06:31:55 +08:00
|
|
|
}
|
|
|
|
|
2013-04-18 06:29:47 +08:00
|
|
|
void testTrackConstraintBRVisitorIsTrackingTurnedOn(struct S syz, int *pp) {
|
|
|
|
int m = 0;
|
|
|
|
syz.x = foo(); // expected-note{{Value assigned to 'syz.x'}}
|
|
|
|
|
|
|
|
struct S *ps = &syz;
|
|
|
|
if (ps->x)
|
2019-05-30 04:29:02 +08:00
|
|
|
//expected-note@-1{{Assuming field 'x' is null}}
|
|
|
|
//expected-note@-2{{Taking false branch}}
|
2013-04-18 06:29:47 +08:00
|
|
|
|
|
|
|
m++;
|
|
|
|
int *p = syz.x; //expected-note {{'p' initialized to a null pointer value}}
|
|
|
|
m = *p; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
|
|
|
|
// expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
|
|
|
|
}
|
|
|
|
|