diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2014-04-01 16:39:33 +0000 |
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2014-04-01 16:39:33 +0000 |
| commit | 398fb00e1ecfe9e3d2fc3e61dc7dcc709f3eece8 (patch) | |
| tree | 62aa57f69c34b02d840e1662d5457cf82f2c1b68 /clang/test/Analysis/dtor.cpp | |
| parent | 2b9036d54df32412cef00551dc6dd83384050289 (diff) | |
| download | bcm5719-llvm-398fb00e1ecfe9e3d2fc3e61dc7dcc709f3eece8.tar.gz bcm5719-llvm-398fb00e1ecfe9e3d2fc3e61dc7dcc709f3eece8.zip | |
[analyzer] Fix a CFG printing bug.
Also, add several destructor-related tests. Most of them don't work yet, but it's
good to have them recorded.
Patch by Alex McCarthy!
llvm-svn: 205326
Diffstat (limited to 'clang/test/Analysis/dtor.cpp')
| -rw-r--r-- | clang/test/Analysis/dtor.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/clang/test/Analysis/dtor.cpp b/clang/test/Analysis/dtor.cpp index 11ce0d57ef4..dbb950eda0f 100644 --- a/clang/test/Analysis/dtor.cpp +++ b/clang/test/Analysis/dtor.cpp @@ -374,6 +374,64 @@ namespace LifetimeExtension { clang_analyzer_eval(SaveOnDestruct::lastOutput == 42); // expected-warning{{TRUE}} } + struct NRCheck { + bool bool_; + NRCheck():bool_(true) {} + ~NRCheck() __attribute__((noreturn)); + operator bool() const { return bool_; } + }; + + struct CheckAutoDestructor { + bool bool_; + CheckAutoDestructor():bool_(true) {} + operator bool() const { return bool_; } + }; + + struct CheckCustomDestructor { + bool bool_; + CheckCustomDestructor():bool_(true) {} + ~CheckCustomDestructor(); + operator bool() const { return bool_; } + }; + + bool testUnnamedNR() { + if (NRCheck()) + return true; + return false; + } + + bool testNamedNR() { + if (NRCheck c = NRCheck()) + return true; + return false; + } + + bool testUnnamedAutoDestructor() { + if (CheckAutoDestructor()) + return true; + return false; + } + + bool testNamedAutoDestructor() { + if (CheckAutoDestructor c = CheckAutoDestructor()) + return true; + return false; + } + + bool testUnnamedCustomDestructor() { + if (CheckCustomDestructor()) + return true; + return false; + } + + // This case used to cause an unexpected "Undefined or garbage value returned + // to caller" warning + bool testNamedCustomDestructor() { + if (CheckCustomDestructor c = CheckCustomDestructor()) + return true; + return false; + } + class VirtualDtorBase { public: int value; @@ -416,6 +474,12 @@ namespace NoReturn { f(&x); *x = 47; // no warning } + + void g2(int *x) { + if (! x) NR(); + // FIXME: this shouldn't cause a warning. + *x = 47; // expected-warning{{Dereference of null pointer}} + } } namespace PseudoDtor { |

