summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/casts.c32
-rw-r--r--clang/test/Analysis/casts.cpp12
-rw-r--r--clang/test/Analysis/expr-inspection.cpp4
-rw-r--r--clang/test/Analysis/svalbuilder-float-cast.c20
4 files changed, 66 insertions, 2 deletions
diff --git a/clang/test/Analysis/casts.c b/clang/test/Analysis/casts.c
index 45ce1940dfa..2d96aa3571d 100644
--- a/clang/test/Analysis/casts.c
+++ b/clang/test/Analysis/casts.c
@@ -213,3 +213,35 @@ void no_crash_on_symsym_cast_to_long() {
}
#endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+ *p += 1;
+ return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+ extern float x;
+ char (*f)() = no_crash_SymbolCast_of_float_type_aux;
+ f(&x);
+}
+
+double no_crash_reinterpret_double_as_int(double a) {
+ *(int *)&a = 1;
+ return a * a;
+}
+
+double no_crash_reinterpret_double_as_ptr(double a) {
+ *(void **)&a = 0;
+ return a * a;
+}
+
+double no_crash_reinterpret_double_as_sym_int(double a, int b) {
+ *(int *)&a = b;
+ return a * a;
+}
+
+double no_crash_reinterpret_double_as_sym_ptr(double a, void * b) {
+ *(void **)&a = b;
+ return a * a;
+}
+
diff --git a/clang/test/Analysis/casts.cpp b/clang/test/Analysis/casts.cpp
index e920bd96da0..aa2bd9c1fad 100644
--- a/clang/test/Analysis/casts.cpp
+++ b/clang/test/Analysis/casts.cpp
@@ -102,3 +102,15 @@ void foo(VeryOpaqueRef ORef) {
castToDerived(reinterpret_cast<Transparent *>(ORef))->getNotInt();
}
} // namespace base_to_derived_opaque_class
+
+namespace bool_to_nullptr {
+struct S {
+ int *a[1];
+ bool b;
+};
+void foo(S s) {
+ s.b = true;
+ for (int i = 0; i < 2; ++i)
+ (void)(s.a[i] != nullptr); // no-crash
+}
+} // namespace bool_to_nullptr
diff --git a/clang/test/Analysis/expr-inspection.cpp b/clang/test/Analysis/expr-inspection.cpp
index 28f35b3eace..609b44ca6d4 100644
--- a/clang/test/Analysis/expr-inspection.cpp
+++ b/clang/test/Analysis/expr-inspection.cpp
@@ -24,7 +24,7 @@ void foo(int x, unsigned y) {
clang_analyzer_denote(1, "$z"); // expected-warning{{Not a symbol}}
clang_analyzer_express(1); // expected-warning{{Not a symbol}}
- clang_analyzer_denote(x + 1, "$w"); // expected-warning{{Not an atomic symbol}}
- clang_analyzer_express(x + 1); // expected-warning{{$x + 1}}
+ clang_analyzer_denote(x + 1, "$w");
+ clang_analyzer_express(x + 1); // expected-warning{{$w}}
clang_analyzer_express(y + 1); // expected-warning{{$y + 1U}}
}
diff --git a/clang/test/Analysis/svalbuilder-float-cast.c b/clang/test/Analysis/svalbuilder-float-cast.c
new file mode 100644
index 00000000000..0f5760cbfca
--- /dev/null
+++ b/clang/test/Analysis/svalbuilder-float-cast.c
@@ -0,0 +1,20 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection -verify %s
+void clang_analyzer_denote(int, const char *);
+void clang_analyzer_express(int);
+
+void SymbolCast_of_float_type_aux(int *p) {
+ *p += 0;
+ // FIXME: Ideally, all unknown values should be symbolicated.
+ clang_analyzer_denote(*p, "$x"); // expected-warning{{Not a symbol}}
+
+ *p += 1;
+ // This should NOT be (float)$x + 1. Symbol $x was never casted to float.
+ // FIXME: Ideally, this should be $x + 1.
+ clang_analyzer_express(*p); // expected-warning{{Not a symbol}}
+}
+
+void SymbolCast_of_float_type() {
+ extern float x;
+ void (*f)() = SymbolCast_of_float_type_aux;
+ f(&x);
+}
OpenPOWER on IntegriCloud