brintos

brintos / llvm-project-archived public Read only

0
0
Text · 924 B · 2bfb4af Raw
36 lines · plain
1// RUN: %clang_analyze_cc1 -w -fblocks -analyzer-checker=core,deadcode,alpha.core,debug.ExprInspection -verify %s2 3void *malloc(unsigned long);4void clang_analyzer_warnIfReached(void);5 6void test_static_from_block(void) {7  static int *x;8  ^{9    *x; // no-warning10  };11}12 13void test_static_within_block(void) {14  ^{15    static int *x;16    *x; // expected-warning{{Dereference of null pointer}}17  };18}19 20void test_static_control_flow(int y) {21  static int *x;22  if (x) {23    // FIXME: Should be reachable.24    clang_analyzer_warnIfReached(); // no-warning25  }26  if (y) {27    // We are not sure if this branch is possible, because the developer28    // may argue that function is always called with y == 1 for the first time.29    // In this case, we can only advise the developer to add assertions30    // for suppressing such path.31    *x; // expected-warning{{Dereference of null pointer}}32  } else {33    x = malloc(1);34  }35}36