xref: /minix3/external/bsd/llvm/dist/clang/test/Analysis/live-variables.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
2*0a6a1f1dSLionel Sambuc // expected-no-diagnostics
3*0a6a1f1dSLionel Sambuc class B {
4*0a6a1f1dSLionel Sambuc public:
5*0a6a1f1dSLionel Sambuc   bool m;
~B()6*0a6a1f1dSLionel Sambuc   ~B() {} // The destructor ensures that the binary logical operator below is wrapped in the ExprWithCleanups.
7*0a6a1f1dSLionel Sambuc };
8*0a6a1f1dSLionel Sambuc B foo();
9*0a6a1f1dSLionel Sambuc int getBool();
10*0a6a1f1dSLionel Sambuc int *getPtr();
test()11*0a6a1f1dSLionel Sambuc int test() {
12*0a6a1f1dSLionel Sambuc   int r = 0;
13*0a6a1f1dSLionel Sambuc   for (int x = 0; x< 10; x++) {
14*0a6a1f1dSLionel Sambuc     int *p = getPtr();
15*0a6a1f1dSLionel Sambuc     // Liveness info is not computed correctly due to the following expression.
16*0a6a1f1dSLionel Sambuc     // This happens due to CFG being special cased for short circuit operators.
17*0a6a1f1dSLionel Sambuc     // PR18159
18*0a6a1f1dSLionel Sambuc     if (p != 0 && getBool() && foo().m && getBool()) {
19*0a6a1f1dSLionel Sambuc       r = *p; // no warning
20*0a6a1f1dSLionel Sambuc     }
21*0a6a1f1dSLionel Sambuc   }
22*0a6a1f1dSLionel Sambuc   return r;
23*0a6a1f1dSLionel Sambuc }
24