llvm-capstone/clang/test/CodeGen/delete-null-pointer-checks.c
Nikita Popov 39db5e1ed8 [CodeGen] Convert tests to opaque pointers (NFC)
Conversion performed using the script at:
https://gist.github.com/nikic/98357b71fd67756b0f064c9517b62a34

These are only tests where no manual fixup was required.
2022-10-07 14:22:00 +02:00

21 lines
872 B
C

// 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 ptr %P, null
// NULL-POINTER-INVALID-NOT: icmp eq
// NULL-POINTER-VALID: %[[SEL:.*]] = select i1 %[[TOBOOL:.*]], ptr null, ptr
// NULL-POINTER-INVALID-NOT: select i1
// NULL-POINTER-VALID: load i32, ptr %[[SEL:.*]]
int *Q = P;
if (P) {
Q = P + 2;
}
return *Q;
}
// NULL-POINTER-INVALID-NOT: attributes #0 = {{.*}} null_pointer_is_valid
// NULL-POINTER-VALID: attributes #0 = {{.*}} null_pointer_is_valid