1 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,core,alpha.core.CallAndMessageUnInitRefArg -analyzer-output=text -verify %s 2 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,core,alpha.core.CallAndMessageUnInitRefArg -analyzer-output=text -DTEST_INLINABLE_ALLOCATORS -verify %s 3 // Passing uninitialized const data to unknown function 4 5 #include "Inputs/system-header-simulator-cxx.h" 6 7 void doStuff6(const int& c); 8 void doStuff4(const int y); 9 void doStuff3(int& g); 10 void doStuff_uninit(const int *u); 11 12 13 int f10(void) { 14 int *ptr; 15 16 ptr = new int; // 17 if(*ptr) { 18 doStuff4(*ptr); 19 } 20 delete ptr; 21 return 0; 22 } 23 24 int f9(void) { 25 int *ptr; 26 27 ptr = new int; // 28 29 doStuff_uninit(ptr); // no warning 30 delete ptr; 31 return 0; 32 } 33 34 int f8(void) { 35 int *ptr; 36 37 ptr = new int; 38 *ptr = 25; 39 40 doStuff_uninit(ptr); // no warning? 41 delete ptr; 42 return 0; 43 } 44 45 void f7(void) { 46 int m = 3; 47 doStuff6(m); // no warning 48 } 49 50 51 int& f6_1_sub(int &p) { 52 return p; 53 } 54 55 void f6_1(void) { 56 int t; // expected-note{{'t' declared without an initial value}} 57 int p = f6_1_sub(t); //expected-warning {{Assigned value is garbage or undefined}} 58 //expected-note@-1 {{Calling 'f6_1_sub'}} 59 //expected-note@-2 {{Returning from 'f6_1_sub'}} 60 //expected-note@-3 {{Assigned value is garbage or undefined}} 61 int q = p; 62 doStuff6(q); 63 } 64 65 void f6_2(void) { 66 int t; //expected-note {{'t' declared without an initial value}} 67 int &p = t; 68 int &s = p; 69 int &q = s; //expected-note {{'q' initialized here}} 70 doStuff6(q); //expected-warning {{1st function call argument is an uninitialized value}} 71 //expected-note@-1 {{1st function call argument is an uninitialized value}} 72 } 73 74 void doStuff6_3(int& q_, int *ptr_) {} 75 76 void f6_3(void) { 77 int *ptr; //expected-note {{'ptr' declared without an initial value}} 78 int t; 79 int &p = t; 80 int &s = p; 81 int &q = s; 82 doStuff6_3(q,ptr); //expected-warning {{2nd function call argument is an uninitialized value}} 83 //expected-note@-1 {{2nd function call argument is an uninitialized value}} 84 85 } 86 87 void f6(void) { 88 int k; // expected-note {{'k' declared without an initial value}} 89 doStuff6(k); // expected-warning {{1st function call argument is an uninitialized value}} 90 // expected-note@-1 {{1st function call argument is an uninitialized value}} 91 92 } 93 94 95 96 void f5(void) { 97 int t; 98 int* tp = &t; // expected-note {{'tp' initialized here}} 99 doStuff_uninit(tp); // expected-warning {{1st function call argument is a pointer to uninitialized value}} 100 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}} 101 } 102 103 104 void f4(void) { 105 int y; // expected-note {{'y' declared without an initial value}} 106 doStuff4(y); // expected-warning {{1st function call argument is an uninitialized value}} 107 // expected-note@-1 {{1st function call argument is an uninitialized value}} 108 } 109 110 void f3(void) { 111 int g; 112 doStuff3(g); // no warning 113 } 114 115 int z; 116 void f2(void) { 117 doStuff_uninit(&z); // no warning 118 } 119 120 void f1(void) { 121 int x_=5; 122 doStuff_uninit(&x_); // no warning 123 } 124 125 void f_uninit(void) { 126 int x; // expected-note {{'x' declared without an initial value}} 127 doStuff_uninit(&x); // expected-warning {{1st function call argument is a pointer to uninitialized value}} 128 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}} 129 } 130