mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-19 11:35:51 -04:00

Summary: Support for this option is needed for building Linux kernel. This is a very frequently requested feature by kernel developers. More details : https://lkml.org/lkml/2018/4/4/601 GCC option description for -fdelete-null-pointer-checks: This Assume that programs cannot safely dereference null pointers, and that no code or data element resides at address zero. -fno-delete-null-pointer-checks is the inverse of this implying that null pointer dereferencing is not undefined. This feature is implemented in as the function attribute "null-pointer-is-valid"="true". This CL only adds the attribute on the function. It also strips "nonnull" attributes from function arguments but keeps the related warnings unchanged. Corresponding LLVM change rL336613 already updated the optimizations to not treat null pointer dereferencing as undefined if the attribute is present. Reviewers: t.p.northover, efriedma, jyknight, chandlerc, rnk, srhines, void, george.burgess.iv Reviewed By: jyknight Subscribers: drinkcat, xbolva00, cfe-commits Differential Revision: https://reviews.llvm.org/D47894 llvm-svn: 337433
21 lines
894 B
C
21 lines
894 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 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"
|