summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-07-26 20:04:30 +0000
committerJordan Rose <jordan_rose@apple.com>2012-07-26 20:04:30 +0000
commit25bc20f846d4268bbd0dac0ecfee019d59f0bfae (patch)
treec270593100fefd0197d7e13f46a2b9998e4ddc11 /clang/test/Analysis
parent20edae8749c7967718d2f2bfca76b1a6d39eca8f (diff)
downloadbcm5719-llvm-25bc20f846d4268bbd0dac0ecfee019d59f0bfae.tar.gz
bcm5719-llvm-25bc20f846d4268bbd0dac0ecfee019d59f0bfae.zip
[analyzer] Don't crash on implicit statements inside initializers.
Our BugReporter knows how to deal with implicit statements: it looks in the ParentMap until it finds a parent with a valid location. However, since initializers are not in the body of a constructor, their sub-expressions are not in the ParentMap. That was easy enough to fix in AnalysisDeclContext. ...and then even once THAT was fixed, there's still an extra funny case of Objective-C object pointer fields under ARC, which are initialized with a top-level ImplicitValueInitExpr. To catch these cases, PathDiagnosticLocation will now fall back to the start of the current function if it can't find any other valid SourceLocations. This isn't great, but it's miles better than a crash. (All of this is only relevant when constructors and destructors are being inlined, i.e. under -cfg-add-initializers and -cfg-add-implicit-dtors.) llvm-svn: 160810
Diffstat (limited to 'clang/test/Analysis')
-rw-r--r--clang/test/Analysis/ctor-inlining.mm11
-rw-r--r--clang/test/Analysis/dtor.cpp21
2 files changed, 31 insertions, 1 deletions
diff --git a/clang/test/Analysis/ctor-inlining.mm b/clang/test/Analysis/ctor-inlining.mm
new file mode 100644
index 00000000000..000e8657516
--- /dev/null
+++ b/clang/test/Analysis/ctor-inlining.mm
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -fobjc-arc -cfg-add-initializers -cfg-add-implicit-dtors -Wno-null-dereference -verify %s
+
+struct Wrapper {
+ __strong id obj;
+};
+
+void test() {
+ Wrapper w;
+ // force a diagnostic
+ *(char *)0 = 1; // expected-warning{{Dereference of null pointer}}
+}
diff --git a/clang/test/Analysis/dtor.cpp b/clang/test/Analysis/dtor.cpp
index 4e3c0017f4a..18884c5f910 100644
--- a/clang/test/Analysis/dtor.cpp
+++ b/clang/test/Analysis/dtor.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store region -analyzer-ipa=inlining -cfg-add-implicit-dtors -cfg-add-initializers -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store region -analyzer-ipa=inlining -cfg-add-implicit-dtors -cfg-add-initializers -Wno-null-dereference -verify %s
void clang_analyzer_eval(bool);
@@ -154,3 +154,22 @@ void testArrayInvalidation() {
clang_analyzer_eval(i == 42); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(j == 42); // expected-warning{{UNKNOWN}}
}
+
+
+
+// Don't crash on a default argument inside an initializer.
+struct DefaultArg {
+ DefaultArg(int x = 0) {}
+ ~DefaultArg();
+};
+
+struct InheritsDefaultArg : DefaultArg {
+ InheritsDefaultArg() {}
+ virtual ~InheritsDefaultArg();
+};
+
+void testDefaultArg() {
+ InheritsDefaultArg a;
+ // Force a bug to be emitted.
+ *(char *)0 = 1; // expected-warning{{Dereference of null pointer}}
+}
OpenPOWER on IntegriCloud