2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-store=region -analyzer-output=text -fblocks -verify -Wno-objc-root-class %s
|
2018-06-13 03:07:41 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-store=region -analyzer-output=plist-multi-file -fblocks -Wno-objc-root-class %s -o %t
|
[analyzer][tests] Use normalize_plist in place of diff_plist (`cat` cases)
Summary:
The `%diff_plist` lit substitution invokes `diff` with a non-portable
`-I` option. The intended effect can be achieved by normalizing the
inputs to `diff` beforehand. Such normalization can be done with
`grep -Ev`, which is also used by other tests.
This patch applies the change (adjusted for review comments) described
in http://lists.llvm.org/pipermail/cfe-dev/2019-April/061904.html
mechanically to the cases where the output file is piped to
`%diff_plist` via `cat`.
The changes were applied via a script, except that
`clang/test/Analysis/NewDelete-path-notes.cpp` and
`clang/test/Analysis/plist-macros-with-expansion.cpp` were each adjusted
for the line-continuation on the relevant `RUN` step.
Reviewers: NoQ, sfertile, xingxue, jasonliu, daltenty
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, Charusso, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62950
llvm-svn: 362996
2019-06-11 06:37:31 +08:00
|
|
|
// RUN: %normalize_plist <%t | diff -u %S/Inputs/expected-plists/null-deref-path-notes.m.plist -
|
2012-09-22 09:24:38 +08:00
|
|
|
|
|
|
|
@interface Root {
|
|
|
|
@public
|
|
|
|
int uniqueID;
|
|
|
|
}
|
|
|
|
- (id)initWithID:(int)newID;
|
|
|
|
- (void)refreshID;
|
|
|
|
@end
|
|
|
|
|
|
|
|
int testNull(Root *obj) {
|
|
|
|
if (obj) return 0;
|
|
|
|
// expected-note@-1 {{Assuming 'obj' is nil}}
|
2012-10-02 03:07:22 +08:00
|
|
|
// expected-note@-2 {{Taking false branch}}
|
2012-09-22 09:24:38 +08:00
|
|
|
|
2013-02-27 03:44:38 +08:00
|
|
|
int *x = &obj->uniqueID; // expected-note{{'x' initialized to a null pointer value}}
|
2012-10-02 03:07:22 +08:00
|
|
|
return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} expected-note{{Dereference of null pointer (loaded from variable 'x')}}
|
2012-09-22 09:24:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@interface Subclass : Root
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Subclass
|
|
|
|
- (id)initWithID:(int)newID {
|
|
|
|
self = [super initWithID:newID]; // expected-note{{Value assigned to 'self'}}
|
|
|
|
if (self) return self;
|
|
|
|
// expected-note@-1 {{Assuming 'self' is nil}}
|
2012-10-26 06:07:10 +08:00
|
|
|
// expected-note@-2 {{Taking false branch}}
|
2012-09-22 09:24:38 +08:00
|
|
|
|
|
|
|
uniqueID = newID; // expected-warning{{Access to instance variable 'uniqueID' results in a dereference of a null pointer (loaded from variable 'self')}} expected-note{{Access to instance variable 'uniqueID' results in a dereference of a null pointer (loaded from variable 'self')}}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2013-02-28 02:49:57 +08:00
|
|
|
void repeatedStores(int coin) {
|
|
|
|
int *p = 0;
|
|
|
|
if (coin) {
|
|
|
|
// expected-note@-1 {{Assuming 'coin' is 0}}
|
|
|
|
// expected-note@-2 {{Taking false branch}}
|
|
|
|
extern int *getPointer();
|
|
|
|
p = getPointer();
|
|
|
|
} else {
|
|
|
|
p = 0; // expected-note {{Null pointer value stored to 'p'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = 1; // expected-warning{{Dereference of null pointer}} expected-note{{Dereference of null pointer}}
|
|
|
|
}
|
|
|
|
|
2017-09-27 17:33:37 +08:00
|
|
|
@interface WithArrayPtr
|
|
|
|
- (void) useArray;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation WithArrayPtr {
|
|
|
|
@public int *p;
|
|
|
|
}
|
|
|
|
- (void)useArray {
|
|
|
|
p[1] = 2; // expected-warning{{Array access (via ivar 'p') results in a null pointer dereference}}
|
|
|
|
// expected-note@-1{{Array access (via ivar 'p') results in a null pointer dereference}}
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
void testWithArrayPtr(WithArrayPtr *w) {
|
|
|
|
w->p = 0; // expected-note{{Null pointer value stored to 'p'}}
|
|
|
|
[w useArray]; // expected-note{{Calling 'useArray'}}
|
|
|
|
}
|
2012-09-22 09:24:38 +08:00
|
|
|
|