forked from OSchip/llvm-project
[analyzer] Enable c++-allocator-inlining by default.
This allows the analyzer to analyze ("inline") custom operator new() calls and, even more importantly, inline constructors of objects that were allocated by any operator new() - not necessarily a custom one. All changes in the tests in the current commit are intended improvements, even if they didn't carry any explicit FIXME flag. It is possible to restore the old behavior via -analyzer-config c++-allocator-inlining=false (this flag is supported by scan-build as well, and it can be into a clang --analyze invocation via -Xclang .. -Xclang ..). There is no intention to remove the old behavior for now. Differential Revision: https://reviews.llvm.org/D42219 rdar://problem/12180598 llvm-svn: 323373
This commit is contained in:
parent
538921dc86
commit
a396df3472
|
@ -203,7 +203,7 @@ bool AnalyzerOptions::mayInlineTemplateFunctions() {
|
||||||
bool AnalyzerOptions::mayInlineCXXAllocator() {
|
bool AnalyzerOptions::mayInlineCXXAllocator() {
|
||||||
return getBooleanOption(InlineCXXAllocator,
|
return getBooleanOption(InlineCXXAllocator,
|
||||||
"c++-allocator-inlining",
|
"c++-allocator-inlining",
|
||||||
/*Default=*/false);
|
/*Default=*/true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnalyzerOptions::mayInlineCXXContainerMethods() {
|
bool AnalyzerOptions::mayInlineCXXContainerMethods() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -fblocks -verify %s
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=false -fblocks -verify %s
|
||||||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -DLEAKS=1 -fblocks -verify %s
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=false -DLEAKS=1 -fblocks -verify %s
|
||||||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DALLOCATOR_INLINING=1 -fblocks -verify %s
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -DALLOCATOR_INLINING=1 -fblocks -verify %s
|
||||||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 -DALLOCATOR_INLINING=1 -fblocks -verify %s
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -DLEAKS=1 -DALLOCATOR_INLINING=1 -fblocks -verify %s
|
||||||
#include "Inputs/system-header-simulator-cxx.h"
|
#include "Inputs/system-header-simulator-cxx.h"
|
||||||
|
|
||||||
#if !(LEAKS && !ALLOCATOR_INLINING)
|
#if !(LEAKS && !ALLOCATOR_INLINING)
|
||||||
|
|
|
@ -572,10 +572,9 @@ namespace ZeroInitialization {
|
||||||
}
|
}
|
||||||
|
|
||||||
void testNew() {
|
void testNew() {
|
||||||
// FIXME: Pending proper implementation of constructors for 'new'.
|
|
||||||
raw_pair *pp = new raw_pair();
|
raw_pair *pp = new raw_pair();
|
||||||
clang_analyzer_eval(pp->p1 == 0); // expected-warning{{UNKNOWN}}
|
clang_analyzer_eval(pp->p1 == 0); // expected-warning{{TRUE}}
|
||||||
clang_analyzer_eval(pp->p2 == 0); // expected-warning{{UNKNOWN}}
|
clang_analyzer_eval(pp->p2 == 0); // expected-warning{{TRUE}}
|
||||||
}
|
}
|
||||||
|
|
||||||
void testArrayNew() {
|
void testArrayNew() {
|
||||||
|
@ -679,8 +678,7 @@ namespace InitializerList {
|
||||||
|
|
||||||
void testDynamic() {
|
void testDynamic() {
|
||||||
List *list = new List{1, 2};
|
List *list = new List{1, 2};
|
||||||
// FIXME: When we handle constructors with 'new', this will be TRUE.
|
clang_analyzer_eval(list->usedInitializerList); // expected-warning{{TRUE}}
|
||||||
clang_analyzer_eval(list->usedInitializerList); // expected-warning{{UNKNOWN}}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ void *testPlacementNew() {
|
||||||
|
|
||||||
void *y = new (x) int;
|
void *y = new (x) int;
|
||||||
clang_analyzer_eval(x == y); // expected-warning{{TRUE}};
|
clang_analyzer_eval(x == y); // expected-warning{{TRUE}};
|
||||||
clang_analyzer_eval(*x == 1); // expected-warning{{UNKNOWN}};
|
clang_analyzer_eval(*x == 1); // expected-warning{{TRUE}};
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
@ -200,8 +200,7 @@ int testNoInitializationPlacement() {
|
||||||
int n;
|
int n;
|
||||||
new (&n) int;
|
new (&n) int;
|
||||||
|
|
||||||
// Should warn that n is uninitialized.
|
if (n) { // expected-warning{{Branch condition evaluates to a garbage value}}
|
||||||
if (n) { // no-warning
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -262,6 +262,9 @@ int main() {
|
||||||
//expected-note-re@-2 {{{{^}}Calling default constructor for 'M'}}
|
//expected-note-re@-2 {{{{^}}Calling default constructor for 'M'}}
|
||||||
#endif
|
#endif
|
||||||
Y *y = new Y;
|
Y *y = new Y;
|
||||||
|
#if !PUREONLY
|
||||||
|
//expected-note-re@-2 {{{{^}}Calling default constructor for 'Y'}}
|
||||||
|
#endif
|
||||||
delete y;
|
delete y;
|
||||||
header::Z z;
|
header::Z z;
|
||||||
#if !PUREONLY
|
#if !PUREONLY
|
||||||
|
|
Loading…
Reference in New Issue