Beispiel #1
0
void multipleCaptures() {
  int i = 5, j = 5;
  [i, &j]() mutable {
    if (i != 5 && j != 5)
      clang_analyzer_warnIfReached();
    ++i;
    ++j;
  }();
  clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
  clang_analyzer_eval(j == 6); // expected-warning{{TRUE}}
  [=]() mutable {
    if (i != 5 && j != 6)
      clang_analyzer_warnIfReached();
    ++i;
    ++j;
  }();
  clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
  clang_analyzer_eval(j == 6); // expected-warning{{TRUE}}
  [&]() mutable {
    if (i != 5 && j != 6)
      clang_analyzer_warnIfReached();
    ++i;
    ++j;
  }();
  clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
  clang_analyzer_eval(j == 7); // expected-warning{{TRUE}}
}
Beispiel #2
0
 bool testRecursiveFrames(bool isInner) {
   if (isInner ||
       (clang_analyzer_warnIfReached(), false) || // expected-warning{{REACHABLE}}
       check(NoReturnDtor()) ||
       testRecursiveFrames(true)) {
     clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
   }
 }
Beispiel #3
0
void captureConstants() {
  const int i = 5;
  [=]() {
    if (i != 5)
      clang_analyzer_warnIfReached();
  }();
  [&] {
    if (i != 5)
      clang_analyzer_warnIfReached();
  }();
}
void test_single_cfg_block_sink() {
  void *p = malloc(1); // no-warning (wherever the leak warning may occur here)

  // Due to max-nodes option in the run line, we should reach the first call
  // but bail out before the second call.
  // If the test on these two lines starts failing, see if modifying
  // the max-nodes run-line helps.
  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
  clang_analyzer_warnIfReached(); // no-warning

  // Even though we do not reach this line, we should still suppress
  // the leak report.
  exit(0);
}
Beispiel #5
0
 void captureFields() {
   i = 5;
   [this]() {
     // clang_analyzer_eval does nothing in inlined functions.
     if (i != 5)
       clang_analyzer_warnIfReached();
     ++i;
     [this]() {
       // clang_analyzer_eval does nothing in inlined functions.
       if (i != 6)
         clang_analyzer_warnIfReached();
       ++i;
     }();
   }();
   clang_analyzer_eval(i == 7); // expected-warning{{TRUE}}
 }
Beispiel #6
0
void testConstrainState(int p) {
  ASSERT_TRUE(p == 7);

  clang_analyzer_eval(p == 7); // expected-warning {{TRUE}}

  ASSERT_TRUE(false);
  clang_analyzer_warnIfReached(); // no-warning
}
Beispiel #7
0
void basicCapture() {
  int i = 5;
  [i]() mutable {
    // clang_analyzer_eval does nothing in inlined functions.
    if (i != 5)
      clang_analyzer_warnIfReached();
    ++i;
  }();
  [&i] {
    if (i != 5)
      clang_analyzer_warnIfReached();
  }();
  [&i] {
    if (i != 5)
      clang_analyzer_warnIfReached();
    i++;
  }();
  clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
}
Beispiel #8
0
int make_new_branches_loop_uncached() {
  int l = 2;
  for (int i = 0; i < 8; i++) {
    clang_analyzer_numTimesReached(); // expected-warning {{10}}
    if(getNum()){
      ++l;
    }
  }
  clang_analyzer_warnIfReached(); // no-warning
  return 0;
}
Beispiel #9
0
int make_new_branches_loop_cached() {
  for (int i = 0; i < 8; i++) {
    clang_analyzer_numTimesReached(); // expected-warning {{4}}
    if(getNum()){
        (void) i; // Since this Stmt does not change the State the analyzer
                  // won't make a new execution path but reuse the earlier nodes.
      }
  }
  clang_analyzer_warnIfReached(); // no-warning
  return 0;
}
Beispiel #10
0
void deferredLambdaCall() {
  int i = 5;
  auto l1 = [i]() mutable {
    if (i != 5)
      clang_analyzer_warnIfReached();
    ++i;
  };
  auto l2 = [&i] {
    if (i != 5)
      clang_analyzer_warnIfReached();
  };
  auto l3 = [&i] {
    if (i != 5)
      clang_analyzer_warnIfReached();
    i++;
  };
  l1();
  l2();
  l3();
  clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
}
Beispiel #11
0
void testNestedLambdas() {
  int i = 5;
  auto l = [i]() mutable {
    [&i]() {
      ++i;
    }();
    if (i != 6)
      clang_analyzer_warnIfReached();
  };
  l();
  clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
}
Beispiel #12
0
int make_new_branches_loop_uncached2() {
  int l = 2;
  for (int i = 0; i < 8; i++) {
    clang_analyzer_numTimesReached(); // expected-warning {{10}}
    if(getNum()){
      ++l;
    }
    (void)&i; // This ensures that the loop won't be unrolled.
  }
  clang_analyzer_warnIfReached(); // no-warning
  return 0;
}
Beispiel #13
0
 void testTernaryFalseBranchReached(bool value) {
   value ? check(NoReturnDtor()) :
           clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
Beispiel #14
0
void nullFunctionPointerConstraint(void (*f)(void)) {
  if (f)
    return;
  f(); // expected-warning{{Called function pointer is null}}
  clang_analyzer_warnIfReached(); // no-warning
}
Beispiel #15
0
void nullFunctionPointerConstant() {
  void (*f)(void) = 0;
  f(); // expected-warning{{Called function pointer is null}}
  clang_analyzer_warnIfReached(); // no-warning
}