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