blob: ac2a39a028406477f33fd8e3c339a95d033b2b7b [file] [log] [blame]
Artem Dergachev1084de52018-01-17 22:58:35 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
2
3void clang_analyzer_eval(bool);
Artem Dergachev50e03722018-01-24 20:32:26 +00004void clang_analyzer_warnIfReached();
Artem Dergachev1084de52018-01-17 22:58:35 +00005
6typedef __typeof__(sizeof(int)) size_t;
7
8void *operator new(size_t size) throw() {
9 return nullptr;
10}
11void *operator new[](size_t size) throw() {
12 return nullptr;
13}
14
15struct S {
16 int x;
Artem Dergachev50e03722018-01-24 20:32:26 +000017 S() : x(1) {
18 // FIXME: Constructor should not be called with null this, even if it was
19 // returned by operator new().
20 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
21 }
Artem Dergachev1084de52018-01-17 22:58:35 +000022 ~S() {}
23};
24
25void testArrays() {
26 S *s = new S[10]; // no-crash
27 s[0].x = 2; // expected-warning{{Dereference of null pointer}}
28}
Artem Dergachev50e03722018-01-24 20:32:26 +000029
30int global;
31void testInvalidationOnConstructionIntoNull() {
32 global = 0;
33 S *s = new S();
34 // FIXME: Should be FALSE - we should not invalidate globals.
35 clang_analyzer_eval(global); // expected-warning{{UNKNOWN}}
36}