llvm-project/clang/test/Analysis/null-deref-path-notes.m
Balazs Benics ffe7950ebc Reland "[analyzer] Deprecate -analyzer-store region flag"
I'm trying to remove unused options from the `Analyses.def` file, then
merge the rest of the useful options into the `AnalyzerOptions.def`.
Then make sure one can set these by an `-analyzer-config XXX=YYY` style
flag.
Then surface the `-analyzer-config` to the `clang` frontend;

After all of this, we can pursue the tablegen approach described
https://discourse.llvm.org/t/rfc-tablegen-clang-static-analyzer-engine-options-for-better-documentation/61488

In this patch, I'm proposing flag deprecations.
We should support deprecated analyzer flags for exactly one release. In
this case I'm planning to drop this flag in `clang-16`.

In the clang frontend, now we won't pass this option to the cc1
frontend, rather emit a warning diagnostic reminding the users about
this deprecated flag, which will be turned into error in clang-16.

Unfortunately, I had to remove all the tests referring to this flag,
causing a mass change. I've also added a test for checking this warning.

I've seen that `scan-build` also uses this flag, but I think we should
remove that part only after we turn this into a hard error.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126215
2022-06-14 09:20:41 +02:00

71 lines
2.3 KiB
Objective-C

// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -fblocks -verify -Wno-objc-root-class %s
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-multi-file -fblocks -Wno-objc-root-class %s -o %t
// RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/null-deref-path-notes.m.plist -
@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}}
// expected-note@-2 {{Taking false branch}}
int *x = &obj->uniqueID; // expected-note{{'x' initialized to a null pointer value}}
return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} expected-note{{Dereference of null pointer (loaded from variable 'x')}}
}
@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}}
// expected-note@-2 {{Taking false branch}}
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
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(void);
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}}
}
@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'}}
}