In the wild, many cases of null pointer dereference, or uninitialized value read occur because the value was meant to be initialized by the inlined function, but did not, most often due to error condition in the inlined function. This change highlights the return branch taken by the inlined function, in order to help user understand the error report and see why the value was uninitialized. rdar://36287652 Differential Revision: https://reviews.llvm.org/D41848 llvm-svn: 325976
47 lines
1.7 KiB
Objective-C
47 lines
1.7 KiB
Objective-C
// RUN: %clang_analyze_cc1 -x objective-c -analyzer-checker=core -analyzer-output=text -Wno-objc-root-class -fblocks -verify %s
|
|
|
|
@interface I
|
|
- (int)initVar:(int *)var param:(int)param;
|
|
@end
|
|
|
|
@implementation I
|
|
- (int)initVar:(int *)var param:(int)param {
|
|
if (param) { // expected-note{{Taking false branch}}
|
|
*var = 1;
|
|
return 0;
|
|
}
|
|
return 1; // expected-note{{Returning without writing to '*var'}}
|
|
}
|
|
@end
|
|
|
|
int foo(I *i) {
|
|
int x; //expected-note{{'x' declared without an initial value}}
|
|
int out = [i initVar:&x param:0]; //expected-note{{Calling 'initVar:param:'}}
|
|
//expected-note@-1{{Returning from 'initVar:param:'}}
|
|
if (out) // expected-note{{Taking true branch}}
|
|
return x; //expected-warning{{Undefined or garbage value returned to caller}}
|
|
//expected-note@-1{{Undefined or garbage value returned to caller}}
|
|
return 0;
|
|
}
|
|
|
|
int initializer1(int *p, int x) {
|
|
if (x) { // expected-note{{Taking false branch}}
|
|
*p = 1;
|
|
return 0;
|
|
} else {
|
|
return 1; // expected-note {{Returning without writing to '*p'}}
|
|
}
|
|
}
|
|
|
|
int initFromBlock() {
|
|
__block int z;
|
|
^{ // expected-note {{Calling anonymous block}}
|
|
int p; // expected-note{{'p' declared without an initial value}}
|
|
initializer1(&p, 0); // expected-note{{Calling 'initializer1'}}
|
|
// expected-note@-1{{Returning from 'initializer1'}}
|
|
z = p; // expected-warning{{Assigned value is garbage or undefined}}
|
|
// expected-note@-1{{Assigned value is garbage or undefined}}
|
|
}();
|
|
return z;
|
|
}
|