[clang]: Add support for "-fno-delete-null-pointer-checks"
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
2018-07-19 08:44:52 +08:00
|
|
|
// RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,NULL-INVALID
|
|
|
|
// RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-apple-darwin10 -fno-delete-null-pointer-checks -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,NULL-VALID
|
2014-07-18 23:52:10 +08:00
|
|
|
|
|
|
|
// For a reference to a complete type, output the dereferenceable attribute (in
|
|
|
|
// any address space).
|
|
|
|
|
|
|
|
typedef int a __attribute__((address_space(1)));
|
|
|
|
|
|
|
|
a & foo(a &x, a & y) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2020-05-19 02:29:11 +08:00
|
|
|
// CHECK: define align 4 dereferenceable(4) i32 addrspace(1)* @_Z3fooRU3AS1iS0_(i32 addrspace(1)* align 4 dereferenceable(4) %x, i32 addrspace(1)* align 4 dereferenceable(4) %y)
|
2014-07-18 23:52:10 +08:00
|
|
|
|
|
|
|
// For a reference to an incomplete type in an alternate address space, output
|
|
|
|
// neither dereferenceable nor nonnull.
|
|
|
|
|
|
|
|
class bc;
|
|
|
|
typedef bc b __attribute__((address_space(1)));
|
|
|
|
|
|
|
|
b & bar(b &x, b & y) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2020-05-19 02:29:11 +08:00
|
|
|
// CHECK: define align 1 %class.bc addrspace(1)* @_Z3barRU3AS12bcS1_(%class.bc addrspace(1)* align 1 %x, %class.bc addrspace(1)* align 1 %y)
|
2014-07-18 23:52:10 +08:00
|
|
|
|
|
|
|
// For a reference to an incomplete type in addrspace(0), output nonnull.
|
|
|
|
|
|
|
|
bc & bar2(bc &x, bc & y) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2020-05-19 02:29:11 +08:00
|
|
|
// NULL-INVALID: define nonnull align 1 %class.bc* @_Z4bar2R2bcS0_(%class.bc* nonnull align 1 %x, %class.bc* nonnull align 1 %y)
|
|
|
|
// NULL-VALID: define align 1 %class.bc* @_Z4bar2R2bcS0_(%class.bc* align 1 %x, %class.bc* align 1 %y)
|
2014-07-18 23:52:10 +08:00
|
|
|
|
|
|
|
|