summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/new-with-exceptions.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2013-08-28 08:04:08 +0000
committerPavel Labath <labath@google.com>2013-08-28 08:04:08 +0000
commitfce1b03ee7e64214389ab5e17394cb75d99f77aa (patch)
tree75cac3d6400681f45f249f2764220b24cbcabc94 /clang/test/Analysis/new-with-exceptions.cpp
parent65b79829c365042eac1d5ad4f7e2a17a152034b8 (diff)
downloadbcm5719-llvm-fce1b03ee7e64214389ab5e17394cb75d99f77aa.tar.gz
bcm5719-llvm-fce1b03ee7e64214389ab5e17394cb75d99f77aa.zip
[analyzer] Assume new returns non-null even under -fno-exceptions
Summary: -fno-exceptions does not implicitly attach a nothrow specifier to every operator new. Even in this mode, non-nothrow new must not return a null pointer. Failure to allocate memory can be signalled by other means, or just by killing the program. This behaviour is consistent with the compiler - even with -fno-exceptions, the generated code never tests for null (and would segfault if the opeator actually happened to return null). Reviewers: jordan_rose CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1528 llvm-svn: 189452
Diffstat (limited to 'clang/test/Analysis/new-with-exceptions.cpp')
-rw-r--r--clang/test/Analysis/new-with-exceptions.cpp32
1 files changed, 7 insertions, 25 deletions
diff --git a/clang/test/Analysis/new-with-exceptions.cpp b/clang/test/Analysis/new-with-exceptions.cpp
index d909f1fb8b6..84d77c22302 100644
--- a/clang/test/Analysis/new-with-exceptions.cpp
+++ b/clang/test/Analysis/new-with-exceptions.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -std=c++11 -fexceptions -fcxx-exceptions -verify -DEXCEPTIONS %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -std=c++11 -fexceptions -fcxx-exceptions -verify %s
// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -std=c++11 -verify %s
void clang_analyzer_eval(bool);
@@ -32,33 +32,15 @@ void testNew() {
clang_analyzer_eval(new NoThrow); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(new NoExcept); // expected-warning{{UNKNOWN}}
- clang_analyzer_eval(new DefaultThrow);
- clang_analyzer_eval(new ExplicitThrow);
-#ifdef EXCEPTIONS
- // expected-warning@-3 {{TRUE}}
- // expected-warning@-3 {{TRUE}}
-#else
- // expected-warning@-6 {{UNKNOWN}}
- // expected-warning@-6 {{UNKNOWN}}
-#endif
+ clang_analyzer_eval(new DefaultThrow); // expected-warning{{TRUE}}
+ clang_analyzer_eval(new ExplicitThrow); // expected-warning{{TRUE}}
}
void testNewArray() {
- clang_analyzer_eval(new NoThrow[2]);
- clang_analyzer_eval(new NoExcept[2]);
- clang_analyzer_eval(new DefaultThrow[2]);
- clang_analyzer_eval(new ExplicitThrow[2]);
-#ifdef EXCEPTIONS
- // expected-warning@-5 {{TRUE}}
- // expected-warning@-5 {{TRUE}}
- // expected-warning@-5 {{TRUE}}
- // expected-warning@-5 {{TRUE}}
-#else
- // expected-warning@-10 {{UNKNOWN}}
- // expected-warning@-10 {{UNKNOWN}}
- // expected-warning@-10 {{UNKNOWN}}
- // expected-warning@-10 {{UNKNOWN}}
-#endif
+ clang_analyzer_eval(new NoThrow[2]); // expected-warning{{TRUE}}
+ clang_analyzer_eval(new NoExcept[2]); // expected-warning{{TRUE}}
+ clang_analyzer_eval(new DefaultThrow[2]); // expected-warning{{TRUE}}
+ clang_analyzer_eval(new ExplicitThrow[2]); // expected-warning{{TRUE}}
}
extern void *operator new[](size_t, int) noexcept;
OpenPOWER on IntegriCloud