brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · f8234c9 Raw
79 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -verify %s2// REQUIRES: LP643 4void clang_analyzer_eval(bool);5 6int f1(char *dst) {7  char *p = dst + 4;8  char *q = dst + 3;9  return !(q >= p);10}11 12long f2(char *c) {13  return long(c) & 1;14}15 16bool f3() {17  return !false;18}19 20void *f4(int* w) {21  return reinterpret_cast<void*&>(w);22}23 24namespace {25 26struct A { };27struct B {28  operator A() { return A(); }29};30 31A f(char *dst) {32  B b;33  return b;34}35 36}37 38namespace {39 40struct S {41    void *p;42};43 44void *f(S* w) {45    return &reinterpret_cast<void*&>(*w);46}47 48}49 50namespace {51 52struct C { 53  void *p;54  static void f();55};56 57void C::f() { }58 59}60 61 62void vla(int n) {63  int nums[n];64  nums[0] = 1;65  clang_analyzer_eval(nums[0] == 1); // expected-warning{{TRUE}}66  67  // This used to fail with MallocChecker on, and /only/ in C++ mode.68  // This struct is POD, though, so it should be fine to put it in a VLA.69  struct { int x; } structs[n];70  structs[0].x = 1;71  clang_analyzer_eval(structs[0].x == 1); // expected-warning{{TRUE}}72}73 74void useIntArray(int []);75void testIntArrayLiteral() {76  useIntArray((int []){ 1, 2, 3 });77}78 79