mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-24 05:55:43 -04:00

I.e. not after. In the c++-allocator-inlining=true mode, we need to make the assumption that the conservatively evaluated operator new() has returned a non-null value. Previously we did this on CXXNewExpr, but now we have to do that before calling the constructor, because some clever constructors are sometimes assuming that their "this" is null and doing weird stuff. We would also crash upon evaluating CXXNewExpr when the allocator was inlined and returned null and had a throw specification; this is UB even for custom allocators, but we still need not to crash. Added more FIXME tests to ensure that eventually we fix calling the constructor for null return values. Differential Revision: https://reviews.llvm.org/D42192 llvm-svn: 323370
37 lines
952 B
C++
37 lines
952 B
C++
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
|
|
|
|
void clang_analyzer_eval(bool);
|
|
void clang_analyzer_warnIfReached();
|
|
|
|
typedef __typeof__(sizeof(int)) size_t;
|
|
|
|
void *operator new(size_t size) throw() {
|
|
return nullptr;
|
|
}
|
|
void *operator new[](size_t size) throw() {
|
|
return nullptr;
|
|
}
|
|
|
|
struct S {
|
|
int x;
|
|
S() : x(1) {
|
|
// FIXME: Constructor should not be called with null this, even if it was
|
|
// returned by operator new().
|
|
clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
|
|
}
|
|
~S() {}
|
|
};
|
|
|
|
void testArrays() {
|
|
S *s = new S[10]; // no-crash
|
|
s[0].x = 2; // expected-warning{{Dereference of null pointer}}
|
|
}
|
|
|
|
int global;
|
|
void testInvalidationOnConstructionIntoNull() {
|
|
global = 0;
|
|
S *s = new S();
|
|
// FIXME: Should be FALSE - we should not invalidate globals.
|
|
clang_analyzer_eval(global); // expected-warning{{UNKNOWN}}
|
|
}
|