2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,core,alpha.core.CallAndMessageUnInitRefArg -analyzer-output=text -verify %s
|
2018-01-25 05:24:10 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,core,alpha.core.CallAndMessageUnInitRefArg -analyzer-output=text -DTEST_INLINABLE_ALLOCATORS -verify %s
|
2014-03-14 01:55:39 +08:00
|
|
|
// Passing uninitialized const data to unknown function
|
|
|
|
|
|
|
|
#include "Inputs/system-header-simulator-cxx.h"
|
|
|
|
|
|
|
|
void doStuff6(const int& c);
|
|
|
|
void doStuff4(const int y);
|
|
|
|
void doStuff3(int& g);
|
|
|
|
void doStuff_uninit(const int *u);
|
|
|
|
|
|
|
|
|
|
|
|
int f10(void) {
|
|
|
|
int *ptr;
|
|
|
|
|
|
|
|
ptr = new int; //
|
|
|
|
if(*ptr) {
|
|
|
|
doStuff4(*ptr);
|
|
|
|
}
|
|
|
|
delete ptr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int f9(void) {
|
|
|
|
int *ptr;
|
|
|
|
|
|
|
|
ptr = new int; //
|
|
|
|
|
|
|
|
doStuff_uninit(ptr); // no warning
|
|
|
|
delete ptr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int f8(void) {
|
|
|
|
int *ptr;
|
|
|
|
|
|
|
|
ptr = new int;
|
|
|
|
*ptr = 25;
|
|
|
|
|
|
|
|
doStuff_uninit(ptr); // no warning?
|
|
|
|
delete ptr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void f7(void) {
|
|
|
|
int m = 3;
|
|
|
|
doStuff6(m); // no warning
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int& f6_1_sub(int &p) {
|
2018-08-23 07:17:25 +08:00
|
|
|
return p; // expected-note{{Returning without writing to 'p'}}
|
|
|
|
// expected-note@-1{{Returning pointer (reference to 't')}}
|
2014-03-14 01:55:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void f6_1(void) {
|
2017-12-20 09:03:22 +08:00
|
|
|
int t; // expected-note{{'t' declared without an initial value}}
|
2014-03-14 01:55:39 +08:00
|
|
|
int p = f6_1_sub(t); //expected-warning {{Assigned value is garbage or undefined}}
|
2018-08-23 07:17:25 +08:00
|
|
|
//expected-note@-1 {{Passing value via 1st parameter 'p'}}
|
|
|
|
//expected-note@-2 {{Calling 'f6_1_sub'}}
|
|
|
|
//expected-note@-3 {{Returning from 'f6_1_sub'}}
|
|
|
|
//expected-note@-4 {{Assigned value is garbage or undefined}}
|
2014-03-14 01:55:39 +08:00
|
|
|
int q = p;
|
|
|
|
doStuff6(q);
|
|
|
|
}
|
|
|
|
|
|
|
|
void f6_2(void) {
|
|
|
|
int t; //expected-note {{'t' declared without an initial value}}
|
|
|
|
int &p = t;
|
|
|
|
int &s = p;
|
|
|
|
int &q = s; //expected-note {{'q' initialized here}}
|
2017-03-08 23:22:24 +08:00
|
|
|
doStuff6(q); //expected-warning {{1st function call argument is an uninitialized value}}
|
|
|
|
//expected-note@-1 {{1st function call argument is an uninitialized value}}
|
2014-03-14 01:55:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void doStuff6_3(int& q_, int *ptr_) {}
|
|
|
|
|
|
|
|
void f6_3(void) {
|
|
|
|
int *ptr; //expected-note {{'ptr' declared without an initial value}}
|
|
|
|
int t;
|
|
|
|
int &p = t;
|
|
|
|
int &s = p;
|
|
|
|
int &q = s;
|
2017-03-08 23:22:24 +08:00
|
|
|
doStuff6_3(q,ptr); //expected-warning {{2nd function call argument is an uninitialized value}}
|
|
|
|
//expected-note@-1 {{2nd function call argument is an uninitialized value}}
|
2014-03-14 01:55:39 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void f6(void) {
|
|
|
|
int k; // expected-note {{'k' declared without an initial value}}
|
2017-03-08 23:22:24 +08:00
|
|
|
doStuff6(k); // expected-warning {{1st function call argument is an uninitialized value}}
|
|
|
|
// expected-note@-1 {{1st function call argument is an uninitialized value}}
|
2014-03-14 01:55:39 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void f5(void) {
|
|
|
|
int t;
|
|
|
|
int* tp = &t; // expected-note {{'tp' initialized here}}
|
2017-03-08 23:22:24 +08:00
|
|
|
doStuff_uninit(tp); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
|
|
|
|
// expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
|
2014-03-14 01:55:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void f4(void) {
|
|
|
|
int y; // expected-note {{'y' declared without an initial value}}
|
2017-03-08 23:22:24 +08:00
|
|
|
doStuff4(y); // expected-warning {{1st function call argument is an uninitialized value}}
|
|
|
|
// expected-note@-1 {{1st function call argument is an uninitialized value}}
|
2014-03-14 01:55:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void f3(void) {
|
|
|
|
int g;
|
|
|
|
doStuff3(g); // no warning
|
|
|
|
}
|
|
|
|
|
|
|
|
int z;
|
|
|
|
void f2(void) {
|
|
|
|
doStuff_uninit(&z); // no warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void f1(void) {
|
|
|
|
int x_=5;
|
|
|
|
doStuff_uninit(&x_); // no warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void f_uninit(void) {
|
2017-04-25 03:30:33 +08:00
|
|
|
int x; // expected-note {{'x' declared without an initial value}}
|
2017-03-08 23:22:24 +08:00
|
|
|
doStuff_uninit(&x); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
|
|
|
|
// expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
|
2014-03-14 01:55:39 +08:00
|
|
|
}
|