1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
2*f4a2713aSLionel Sambuc // expected-no-diagnostics
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc extern void __assert_fail (__const char *__assertion, __const char *__file,
5*f4a2713aSLionel Sambuc unsigned int __line, __const char *__function)
6*f4a2713aSLionel Sambuc __attribute__ ((__noreturn__));
7*f4a2713aSLionel Sambuc #define assert(expr) \
8*f4a2713aSLionel Sambuc ((expr) ? (void)(0) : __assert_fail (#expr, __FILE__, __LINE__, __func__))
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambuc class ButterFly {
11*f4a2713aSLionel Sambuc private:
ButterFly()12*f4a2713aSLionel Sambuc ButterFly() { }
13*f4a2713aSLionel Sambuc public:
triggerderef()14*f4a2713aSLionel Sambuc int triggerderef() {
15*f4a2713aSLionel Sambuc return 0;
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc };
18*f4a2713aSLionel Sambuc ButterFly *getInP();
19*f4a2713aSLionel Sambuc class X{
20*f4a2713aSLionel Sambuc ButterFly *p;
setP(ButterFly * inP)21*f4a2713aSLionel Sambuc void setP(ButterFly *inP) {
22*f4a2713aSLionel Sambuc if(inP)
23*f4a2713aSLionel Sambuc ;
24*f4a2713aSLionel Sambuc p = inP;
25*f4a2713aSLionel Sambuc };
subtest1()26*f4a2713aSLionel Sambuc void subtest1() {
27*f4a2713aSLionel Sambuc ButterFly *inP = getInP();
28*f4a2713aSLionel Sambuc setP(inP);
29*f4a2713aSLionel Sambuc }
subtest2()30*f4a2713aSLionel Sambuc int subtest2() {
31*f4a2713aSLionel Sambuc int c = p->triggerderef(); // no-warning
32*f4a2713aSLionel Sambuc return c;
33*f4a2713aSLionel Sambuc }
test()34*f4a2713aSLionel Sambuc int test() {
35*f4a2713aSLionel Sambuc subtest1();
36*f4a2713aSLionel Sambuc return subtest2();
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc };
39*f4a2713aSLionel Sambuc
40*f4a2713aSLionel Sambuc typedef const int *Ty;
41*f4a2713aSLionel Sambuc extern
42*f4a2713aSLionel Sambuc Ty notNullArg(Ty cf) __attribute__((nonnull));
43*f4a2713aSLionel Sambuc typedef const void *CFTypeRef;
44*f4a2713aSLionel Sambuc extern Ty getTyVal();
radar13224271_callee(Ty def,Ty & result)45*f4a2713aSLionel Sambuc inline void radar13224271_callee(Ty def, Ty& result ) {
46*f4a2713aSLionel Sambuc result = def;
47*f4a2713aSLionel Sambuc // Clearly indicates that result cannot be 0 if def is not NULL.
48*f4a2713aSLionel Sambuc assert( (result != 0) || (def == 0) );
49*f4a2713aSLionel Sambuc }
radar13224271_caller()50*f4a2713aSLionel Sambuc void radar13224271_caller()
51*f4a2713aSLionel Sambuc {
52*f4a2713aSLionel Sambuc Ty value;
53*f4a2713aSLionel Sambuc radar13224271_callee(getTyVal(), value );
54*f4a2713aSLionel Sambuc notNullArg(value); // no-warning
55*f4a2713aSLionel Sambuc }
56*f4a2713aSLionel Sambuc
57*f4a2713aSLionel Sambuc struct Foo {
58*f4a2713aSLionel Sambuc int *ptr;
FooFoo59*f4a2713aSLionel Sambuc Foo(int *p) {
60*f4a2713aSLionel Sambuc *p = 1; // no-warning
61*f4a2713aSLionel Sambuc }
62*f4a2713aSLionel Sambuc };
idc(int * p3)63*f4a2713aSLionel Sambuc void idc(int *p3) {
64*f4a2713aSLionel Sambuc if (p3)
65*f4a2713aSLionel Sambuc ;
66*f4a2713aSLionel Sambuc }
retNull()67*f4a2713aSLionel Sambuc int *retNull() {
68*f4a2713aSLionel Sambuc return 0;
69*f4a2713aSLionel Sambuc }
test(int * p1,int * p2)70*f4a2713aSLionel Sambuc void test(int *p1, int *p2) {
71*f4a2713aSLionel Sambuc idc(p1);
72*f4a2713aSLionel Sambuc Foo f(p1);
73*f4a2713aSLionel Sambuc }