diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-08-25 01:06:23 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-08-25 01:06:23 +0000 |
commit | 0a0aa84da3300f4b5c8c7b5c7778940770a96323 (patch) | |
tree | 3d0b8d60e11b9a21ee8e823a7af980478f6f9225 /clang/test/Analysis/initializer.cpp | |
parent | cb889d8737694d928f765409a09395a97cff819e (diff) | |
download | bcm5719-llvm-0a0aa84da3300f4b5c8c7b5c7778940770a96323.tar.gz bcm5719-llvm-0a0aa84da3300f4b5c8c7b5c7778940770a96323.zip |
[analyzer] Use the common evalBind infrastructure for initializers.
This allows checkers (like the MallocChecker) to process the effects of the
bind. Previously, using a memory-allocating function (like strdup()) in an
initializer would result in a leak warning.
This does bend the expectations of checkBind a bit; since there is no
assignment expression, the statement being used is the initializer value.
In most cases this shouldn't matter because we'll use a PostInitializer
program point (rather than PostStmt) for any checker-generated nodes, though
we /will/ generate a PostStore node referencing the internal statement.
(In theory this could have funny effects if someone actually does an
assignment within an initializer; in practice, that seems like it would be
very rare.)
<rdar://problem/12171711>
llvm-svn: 162637
Diffstat (limited to 'clang/test/Analysis/initializer.cpp')
-rw-r--r-- | clang/test/Analysis/initializer.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/clang/test/Analysis/initializer.cpp b/clang/test/Analysis/initializer.cpp index 4f800d5d43b..8785a002c6c 100644 --- a/clang/test/Analysis/initializer.cpp +++ b/clang/test/Analysis/initializer.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=inlining -cfg-add-implicit-dtors -std=c++11 -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-ipa=inlining -cfg-add-implicit-dtors -std=c++11 -verify %s // We don't inline constructors unless we have destructors turned on. @@ -57,10 +57,6 @@ void testDelegatingConstructor() { } -// ------------------------------------ -// False negatives -// ------------------------------------ - struct RefWrapper { RefWrapper(int *p) : x(*p) {} RefWrapper(int &r) : x(r) {} @@ -69,10 +65,20 @@ struct RefWrapper { void testReferenceMember() { int *p = 0; - RefWrapper X(p); // should warn in the constructor + RefWrapper X(p); // expected-warning@61 {{Dereference of null pointer}} } void testReferenceMember2() { int *p = 0; - RefWrapper X(*p); // should warn here + // FIXME: We should warn here, since we're creating the reference here. + RefWrapper X(*p); // expected-warning@62 {{Dereference of null pointer}} } + + +extern "C" char *strdup(const char *); + +class StringWrapper { + char *str; +public: + StringWrapper(const char *input) : str(strdup(input)) {} // no-warning +}; |