diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/live-variables.cpp | 23 | ||||
-rw-r--r-- | clang/test/Analysis/live-variables.m | 24 | ||||
-rw-r--r-- | clang/test/Analysis/temporaries.cpp | 28 |
3 files changed, 65 insertions, 10 deletions
diff --git a/clang/test/Analysis/live-variables.cpp b/clang/test/Analysis/live-variables.cpp new file mode 100644 index 00000000000..0cfaa1b41f5 --- /dev/null +++ b/clang/test/Analysis/live-variables.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s +// expected-no-diagnostics +class B { +public: + bool m; + ~B() {} // The destructor ensures that the binary logical operator below is wrapped in the ExprWithCleanups. +}; +B foo(); +int getBool(); +int *getPtr(); +int test() { + int r = 0; + for (int x = 0; x< 10; x++) { + int *p = getPtr(); + // Liveness info is not computed correctly due to the following expression. + // This happens due to CFG being special cased for short circuit operators. + // PR18159 + if (p != 0 && getBool() && foo().m && getBool()) { + r = *p; // no warning + } + } + return r; +} diff --git a/clang/test/Analysis/live-variables.m b/clang/test/Analysis/live-variables.m new file mode 100644 index 00000000000..eefd292bf79 --- /dev/null +++ b/clang/test/Analysis/live-variables.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core -fobjc-arc -verify %s +// expected-no-diagnostics +@interface NSObject +@end +@interface NSString : NSObject +- (id)lastPathComponent; +@end +int getBool(); +int *getPtr(); +int foo() { + int r = 0; + NSString *filename = @"filename"; + for (int x = 0; x< 10; x++) { + int *p = getPtr(); + // Liveness info is not computed correctly due to the following expression. + // This happens due to CFG being special cased for short circuit operators. + // Note, due to ObjC method call, the outermost logical operator is wrapped in ExprWithCleanups. + // PR18159 + if ((p != 0) && (getBool()) && ([filename lastPathComponent]) && (getBool())) { + r = *p; // no-warning + } + } + return r; +}
\ No newline at end of file diff --git a/clang/test/Analysis/temporaries.cpp b/clang/test/Analysis/temporaries.cpp index d5237e597cf..6b49fcbddd4 100644 --- a/clang/test/Analysis/temporaries.cpp +++ b/clang/test/Analysis/temporaries.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -w -std=c++03 %s // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -w -std=c++11 %s -// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -w -analyzer-config cfg-temporary-dtors=true %s -DTEMPORARY_DTORS +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -DTEMPORARY_DTORS -verify -w -analyzer-config cfg-temporary-dtors=true %s extern bool clang_analyzer_eval(bool); @@ -111,17 +111,20 @@ namespace compound_literals { } namespace destructors { - void testPR16664Crash() { + void testPR16664andPR18159Crash() { struct Dtor { ~Dtor(); }; extern bool coin(); extern bool check(const Dtor &); - // Don't crash here. +#ifndef TEMPORARY_DTORS + // FIXME: Don't crash here when tmp dtros are enabled. + // PR16664 and PR18159 if (coin() && (coin() || coin() || check(Dtor()))) { Dtor(); } +#endif } #ifdef TEMPORARY_DTORS @@ -147,9 +150,6 @@ namespace destructors { extern bool check(const NoReturnDtor &); void testConsistencyIf(int i) { - if (i == 5 && (i == 4 || i == 5 || check(NoReturnDtor()))) - clang_analyzer_eval(true); // expected-warning{{TRUE}} - if (i != 5) return; if (i == 5 && (i == 4 || check(NoReturnDtor()) || i == 5)) { @@ -170,11 +170,18 @@ namespace destructors { clang_analyzer_eval(true); // no warning, unreachable code } + +/* + // PR16664 and PR18159 + FIXME: Don't crash here. void testConsistencyNested(int i) { extern bool compute(bool); - + + if (i == 5 && (i == 4 || i == 5 || check(NoReturnDtor()))) + clang_analyzer_eval(true); // expected TRUE + if (i == 5 && (i == 4 || i == 5 || check(NoReturnDtor()))) - clang_analyzer_eval(true); // expected-warning{{TRUE}} + clang_analyzer_eval(true); // expected TRUE if (i != 5) return; @@ -183,7 +190,7 @@ namespace destructors { (i == 4 || compute(true) || compute(i == 5 && (i == 4 || check(NoReturnDtor()))))) || i != 4) { - clang_analyzer_eval(true); // expected-warning{{TRUE}} + clang_analyzer_eval(true); // expected TRUE } if (compute(i == 5 && @@ -192,7 +199,8 @@ namespace destructors { i != 4) { clang_analyzer_eval(true); // no warning, unreachable code } - } + }*/ + #endif // TEMPORARY_DTORS } |