summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/delete-null-pointer-checks.c
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/CodeGen/delete-null-pointer-checks.c')
-rw-r--r--clang/test/CodeGen/delete-null-pointer-checks.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/test/CodeGen/delete-null-pointer-checks.c b/clang/test/CodeGen/delete-null-pointer-checks.c
new file mode 100644
index 00000000000..a3c1460f0a0
--- /dev/null
+++ b/clang/test/CodeGen/delete-null-pointer-checks.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -O2 -o - %s | FileCheck -check-prefix=NULL-POINTER-INVALID %s
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -O2 -o - %s -fno-delete-null-pointer-checks | FileCheck -check-prefix=NULL-POINTER-VALID %s
+
+// Test that clang does not remove the null pointer check with
+// -fno-delete-null-pointer-checks.
+int null_check(int *P) {
+// NULL-POINTER-VALID: %[[TOBOOL:.*]] = icmp eq i32* %P, null
+// NULL-POINTER-INVALID-NOT: icmp eq
+// NULL-POINTER-VALID: %[[SEL:.*]] = select i1 %[[TOBOOL:.*]], i32* null, i32*
+// NULL-POINTER-INVALID-NOT: select i1
+// NULL-POINTER-VALID: load i32, i32* %[[SEL:.*]]
+ int *Q = P;
+ if (P) {
+ Q = P + 2;
+ }
+ return *Q;
+}
+
+// NULL-POINTER-INVALID-NOT: attributes #0 = {{.*}} "null-pointer-is-valid"="true"
+// NULL-POINTER-VALID: attributes #0 = {{.*}} "null-pointer-is-valid"="true"
OpenPOWER on IntegriCloud