aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/casts.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/casts.c')
-rw-r--r--test/Analysis/casts.c67
1 files changed, 65 insertions, 2 deletions
diff --git a/test/Analysis/casts.c b/test/Analysis/casts.c
index 86fb7da58ec2..2d96aa3571d3 100644
--- a/test/Analysis/casts.c
+++ b/test/Analysis/casts.c
@@ -1,5 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region -verify %s
-// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region -verify -analyzer-config eagerly-assume=false %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -DEAGERLY_ASSUME=1 -w %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin9 -analyzer-checker=core,alpha.core,debug.ExprInspection -verify -DEAGERLY_ASSUME=1 -DBIT32=1 -w %s
extern void clang_analyzer_eval(_Bool);
@@ -16,6 +18,8 @@ struct sockaddr_storage {};
void getsockname();
+#ifndef EAGERLY_ASSUME
+
void f(int sock) {
struct sockaddr_storage storage;
struct sockaddr* sockaddr = (struct sockaddr*)&storage; // expected-warning{{Casting data to a larger structure type and accessing a field can lead to memory access errors or data corruption}}
@@ -182,3 +186,62 @@ void testLocNonLocSymbolRemainder(int a, int *b) {
c += 1;
}
}
+
+void testSwitchWithSizeofs() {
+ switch (sizeof(char) == 1) { // expected-warning{{switch condition has boolean value}}
+ case sizeof(char):; // no-crash
+ }
+}
+
+#endif
+
+#ifdef EAGERLY_ASSUME
+
+int globalA;
+extern int globalFunc();
+void no_crash_on_symsym_cast_to_long() {
+ char c = globalFunc() - 5;
+ c == 0;
+ globalA -= c;
+ globalA == 3;
+ (long)globalA << 48;
+ #ifdef BIT32
+ // expected-warning@-2{{The result of the left shift is undefined due to shifting by '48', which is greater or equal to the width of type 'long'}}
+ #else
+ // expected-no-diagnostics
+ #endif
+}
+
+#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;
+}
+