[RISCV][FMV] Support target_clones (#85786)
[llvm-project.git] / clang / test / Analysis / new-ctor-null.cpp
blob7b4d67a610220b05813f69c98135599038926bc0
1 // RUN: %clang_analyze_cc1 -std=c++14 \
2 // RUN: -analyzer-checker=core,debug.ExprInspection \
3 // RUN: -verify %s
5 void clang_analyzer_eval(bool);
6 void clang_analyzer_warnIfReached();
8 typedef __typeof__(sizeof(int)) size_t;
10 void *operator new(size_t size) throw() {
11 return nullptr;
12 // expected-warning@-1 {{null returned from function that requires a non-null return value}}
14 void *operator new[](size_t size) throw() {
15 return nullptr;
16 // expected-warning@-1 {{null returned from function that requires a non-null return value}}
19 struct S {
20 int x;
21 S() : x(1) {
22 // FIXME: Constructor should not be called with null this, even if it was
23 // returned by operator new().
24 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
26 ~S() {}
29 void testArrays() {
30 S *s = new S[10]; // no-crash
31 s[0].x = 2;
32 // no-warning: 'Dereference of null pointer' suppressed by ReturnVisitor.
35 int global;
36 void testInvalidationOnConstructionIntoNull() {
37 global = 0;
38 S *s = new S();
39 // FIXME: Should be FALSE - we should not invalidate globals.
40 clang_analyzer_eval(global); // expected-warning{{UNKNOWN}}