| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core %s -verify |
| 2 |
// expected-no-diagnostics |
| 3 |
|
| 4 |
#define SIZE 2 |
| 5 |
|
| 6 |
typedef struct { |
| 7 |
int noOfSymbols; |
| 8 |
} Params; |
| 9 |
|
| 10 |
static void create(const Params * const params, int fooList[]) { |
| 11 |
int tmpList[SIZE] = {0}; |
| 12 |
for (int i = 0; i < params->noOfSymbols; i++) |
| 13 |
fooList[i] = tmpList[i]; |
| 14 |
} |
| 15 |
|
| 16 |
int work(Params * const params) { |
| 17 |
int fooList[SIZE]; |
| 18 |
create(params, fooList); |
| 19 |
int sum = 0; |
| 20 |
for (int i = 0; i < params->noOfSymbols; i++) |
| 21 |
sum += fooList[i]; // no-warning |
| 22 |
return sum; |
| 23 |
} |
| 24 |
|
| 25 |
static void create2(const Params * const * pparams, int fooList[]) { |
| 26 |
const Params * params = *pparams; |
| 27 |
int tmpList[SIZE] = {0}; |
| 28 |
for (int i = 0; i < params->noOfSymbols; i++) |
| 29 |
fooList[i] = tmpList[i]; |
| 30 |
} |
| 31 |
|
| 32 |
int work2(const Params * const params) { |
| 33 |
int fooList[SIZE]; |
| 34 |
create2(¶ms, fooList); |
| 35 |
int sum = 0; |
| 36 |
for (int i = 0; i < params->noOfSymbols; i++) |
| 37 |
sum += fooList[i]; // no-warning |
| 38 |
return sum; |
| 39 |
} |
| 40 |
|
| 41 |
static void create3(Params * const * pparams, int fooList[]) { |
| 42 |
const Params * params = *pparams; |
| 43 |
int tmpList[SIZE] = {0}; |
| 44 |
for (int i = 0; i < params->noOfSymbols; i++) |
| 45 |
fooList[i] = tmpList[i]; |
| 46 |
} |
| 47 |
|
| 48 |
int work3(const Params * const params) { |
| 49 |
int fooList[SIZE]; |
| 50 |
Params *const *ptr = (Params *const*)¶ms; |
| 51 |
create3(ptr, fooList); |
| 52 |
int sum = 0; |
| 53 |
for (int i = 0; i < params->noOfSymbols; i++) |
| 54 |
sum += fooList[i]; // no-warning |
| 55 |
return sum; |
| 56 |
} |
| 57 |
|
| 58 |
typedef Params ParamsTypedef; |
| 59 |
typedef const ParamsTypedef *ConstParamsTypedef; |
| 60 |
|
| 61 |
static void create4(ConstParamsTypedef const params, int fooList[]) { |
| 62 |
int tmpList[SIZE] = {0}; |
| 63 |
for (int i = 0; i < params->noOfSymbols; i++) |
| 64 |
fooList[i] = tmpList[i]; |
| 65 |
} |
| 66 |
|
| 67 |
int work4(Params * const params) { |
| 68 |
int fooList[SIZE]; |
| 69 |
create4(params, fooList); |
| 70 |
int sum = 0; |
| 71 |
for (int i = 0; i < params->noOfSymbols; i++) |
| 72 |
sum += fooList[i]; // no-warning |
| 73 |
return sum; |
| 74 |
} |