brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 013ab78 Raw
75 lines · c
1// RUN: %clang_analyze_cc1 -analyzer-checker=core %s -verify 2// expected-no-diagnostics3 4#define SIZE 25 6typedef struct {7  int noOfSymbols;8} Params;9 10static 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 16int 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-warning22  return sum;23}24 25static 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 32int work2(const Params * const params) {33  int fooList[SIZE];34  create2(&params, fooList);35  int sum = 0;36  for (int i = 0; i < params->noOfSymbols; i++)37    sum += fooList[i]; // no-warning38  return sum;39}40 41static 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 48int work3(const Params * const params) {49  int fooList[SIZE];50  Params *const *ptr = (Params *const*)&params;51  create3(ptr, fooList);52  int sum = 0;53  for (int i = 0; i < params->noOfSymbols; i++)54    sum += fooList[i]; // no-warning55  return sum;56}57 58typedef Params ParamsTypedef;59typedef const ParamsTypedef *ConstParamsTypedef;60 61static 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 67int 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-warning73  return sum;74}75