aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/diagnostics')
-rw-r--r--test/Analysis/diagnostics/dtors.cpp19
-rw-r--r--test/Analysis/diagnostics/invalid-srcloc-fix.cpp12
-rw-r--r--test/Analysis/diagnostics/macros.cpp30
-rw-r--r--test/Analysis/diagnostics/no-store-func-path-notes.c12
-rw-r--r--test/Analysis/diagnostics/plist-diagnostics-include-check.cpp2
-rw-r--r--test/Analysis/diagnostics/plist-multi-file.c2
6 files changed, 65 insertions, 12 deletions
diff --git a/test/Analysis/diagnostics/dtors.cpp b/test/Analysis/diagnostics/dtors.cpp
index 094917e432..b3fe7ec803 100644
--- a/test/Analysis/diagnostics/dtors.cpp
+++ b/test/Analysis/diagnostics/dtors.cpp
@@ -1,9 +1,11 @@
-// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus -verify %s
-
-// expected-no-diagnostics
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus -analyzer-output=text -verify %s
namespace no_crash_on_delete_dtor {
-// We were crashing when producing diagnostics for this code.
+// We were crashing when producing diagnostics for this code, but not for the
+// report that it currently emits. Instead, Static Analyzer was thinking that
+// p.get()->foo() is a null dereference because it was dropping
+// constraints over x too early and took a different branch next time
+// we call .get().
struct S {
void foo();
~S();
@@ -14,12 +16,15 @@ struct smart_ptr {
S *s;
smart_ptr(S *);
S *get() {
- return (x || 0) ? nullptr : s;
+ return (x || 0) ? nullptr : s; // expected-note{{Left side of '||' is false}}
+ // expected-note@-1{{'?' condition is false}}
+ // expected-warning@-2{{Use of memory after it is freed}}
+ // expected-note@-3{{Use of memory after it is freed}}
}
};
void bar(smart_ptr p) {
- delete p.get();
- p.get()->foo();
+ delete p.get(); // expected-note{{Memory is released}}
+ p.get()->foo(); // expected-note{{Calling 'smart_ptr::get'}}
}
} // namespace no_crash_on_delete_dtor
diff --git a/test/Analysis/diagnostics/invalid-srcloc-fix.cpp b/test/Analysis/diagnostics/invalid-srcloc-fix.cpp
new file mode 100644
index 0000000000..0cef5e3d0f
--- /dev/null
+++ b/test/Analysis/diagnostics/invalid-srcloc-fix.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN: -analyzer-output=plist -o %t.plist \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ReportStmts
+
+struct h {
+ operator int();
+};
+
+int k() {
+ return h(); // expected-warning 3 {{Statement}}
+}
diff --git a/test/Analysis/diagnostics/macros.cpp b/test/Analysis/diagnostics/macros.cpp
index 5aa2c03ab0..b3887b39a4 100644
--- a/test/Analysis/diagnostics/macros.cpp
+++ b/test/Analysis/diagnostics/macros.cpp
@@ -3,7 +3,7 @@
#include "../Inputs/system-header-simulator.h"
#include "../Inputs/system-header-simulator-cxx.h"
-void testIntMacro(unsigned int i) {
+void testUnsignedIntMacro(unsigned int i) {
if (i == UINT32_MAX) { // expected-note {{Assuming 'i' is equal to UINT32_MAX}}
// expected-note@-1 {{Taking true branch}}
char *p = NULL; // expected-note {{'p' initialized to a null pointer value}}
@@ -12,6 +12,20 @@ void testIntMacro(unsigned int i) {
}
}
+
+// FIXME: 'i' can never be equal to UINT32_MAX - it doesn't even fit into its
+// type ('int'). This should say "Assuming 'i' is equal to -1".
+void testIntMacro(int i) {
+ if (i == UINT32_MAX) { // expected-note {{Assuming 'i' is equal to UINT32_MAX}}
+ // expected-note@-1 {{Taking true branch}}
+ char *p = NULL; // expected-note {{'p' initialized to a null pointer value}}
+ *p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
+ // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
+ }
+}
+
+
+
void testNULLMacro(int *p) {
if (p == NULL) { // expected-note {{Assuming 'p' is equal to NULL}}
// expected-note@-1 {{Taking true branch}}
@@ -30,7 +44,8 @@ void testnullptrMacro(int *p) {
// There are no path notes on the comparison to float types.
void testDoubleMacro(double d) {
- if (d == DBL_MAX) { // expected-note {{Taking true branch}}
+ if (d == DBL_MAX) { // expected-note {{Assuming 'd' is equal to DBL_MAX}}
+ // expected-note@-1 {{Taking true branch}}
char *p = NULL; // expected-note {{'p' initialized to a null pointer value}}
*p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
@@ -46,3 +61,14 @@ void testboolMacro(bool b, int *p) {
// expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
}
}
+
+#define nested_null_split(x) if ((x) != UINT32_MAX) {}
+
+void testNestedNullSplitMacro(int i, int *p) {
+ nested_null_split(i); // expected-note {{Assuming 'i' is equal to -1}}
+ // expected-note@-1 {{Taking false branch}}
+ if (!p) // expected-note {{Assuming 'p' is null}}
+ // expected-note@-1 {{Taking true branch}}
+ *p = 1; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
+ // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
+}
diff --git a/test/Analysis/diagnostics/no-store-func-path-notes.c b/test/Analysis/diagnostics/no-store-func-path-notes.c
index 2050f6217c..c0208214cc 100644
--- a/test/Analysis/diagnostics/no-store-func-path-notes.c
+++ b/test/Analysis/diagnostics/no-store-func-path-notes.c
@@ -1,4 +1,5 @@
-// RUN: %clang_analyze_cc1 -x c -analyzer-checker=core -analyzer-output=text -verify %s
+// RUN: %clang_analyze_cc1 -w -x c -analyzer-checker=core -analyzer-output=text\
+// RUN: -verify %s
typedef __typeof(sizeof(int)) size_t;
void *memset(void *__s, int __c, size_t __n);
@@ -244,3 +245,12 @@ int useInitializeMaybeInStruct() {
return z; // expected-warning{{Undefined or garbage value returned to caller}}
// expected-note@-1{{Undefined or garbage value returned to caller}}
}
+
+void test_implicit_function_decl(int *x) {
+ if (x) {} // expected-note{{Assuming 'x' is null}}
+ // expected-note@-1{{Taking false branch}}
+ implicit_function(x);
+ *x = 4; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
+ // expected-note@-1{{Dereference of null pointer (loaded from variable 'x')}}
+}
+int implicit_function(int *y) {}
diff --git a/test/Analysis/diagnostics/plist-diagnostics-include-check.cpp b/test/Analysis/diagnostics/plist-diagnostics-include-check.cpp
index dd86129e2f..26beda5300 100644
--- a/test/Analysis/diagnostics/plist-diagnostics-include-check.cpp
+++ b/test/Analysis/diagnostics/plist-diagnostics-include-check.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -analyzer-output=plist-multi-file %s -o %t.plist
-// RUN: tail -n +11 %t.plist | diff -u -w -I "<string>/" -I "<string>.:" -I "version" - %S/Inputs/expected-plists/plist-diagnostics-include-check.cpp.plist
+// RUN: tail -n +11 %t.plist | %diff_plist %S/Inputs/expected-plists/plist-diagnostics-include-check.cpp.plist -
#include "Inputs/include/plist-diagnostics-include-check-macro.h"
diff --git a/test/Analysis/diagnostics/plist-multi-file.c b/test/Analysis/diagnostics/plist-multi-file.c
index 878f373aac..a70c9aa935 100644
--- a/test/Analysis/diagnostics/plist-multi-file.c
+++ b/test/Analysis/diagnostics/plist-multi-file.c
@@ -1,5 +1,5 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-html -o %t.plist -verify %s
-// RUN: tail -n +11 %t.plist | diff -u -w -I "<string>/" -I "<string>.:" -I "version" --ignore-matching-lines=report - %S/Inputs/expected-plists/plist-multi-file.c.plist
+// RUN: tail -n +11 %t.plist | %diff_plist --ignore-matching-lines=report %S/Inputs/expected-plists/plist-multi-file.c.plist -
#include "plist-multi-file.h"