From fce1b03ee7e64214389ab5e17394cb75d99f77aa Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 28 Aug 2013 08:04:08 +0000 Subject: [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 --- clang/test/Analysis/new-with-exceptions.cpp | 32 +++++++---------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'clang/test/Analysis/new-with-exceptions.cpp') 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; -- cgit v1.2.3