[CodeGen] -fno-delete-null-pointer-checks: change dereferenceable to dereferenceable_...
authorFangrui Song <i@maskray.me>
Mon, 30 Nov 2020 20:44:35 +0000 (12:44 -0800)
committerFangrui Song <i@maskray.me>
Mon, 30 Nov 2020 20:44:35 +0000 (12:44 -0800)
commit164410324d8bf3b5a99e39f7dfe3c6d6972dab30
treed1c657432348800fdab7705d63632c9bd09a3e29
parent66124098a88a564143a36869f495708502a35c50
[CodeGen] -fno-delete-null-pointer-checks: change dereferenceable to dereferenceable_or_null

After D17993, with -fno-delete-null-pointer-checks we add the dereferenceable attribute to the `this` pointer.

We have observed that one internal target which worked before fails even with -fno-delete-null-pointer-checks.
Switching to dereferenceable_or_null fixes the problem.

dereferenceable currently does not always respect NullPointerIsValid and may
imply nonnull and lead to aggressive optimization. The optimization may be
related to `CallBase::isReturnNonNull`, `Argument::hasNonNullAttr`, or
`Value::getPointerDereferenceableBytes`. See D66664 and D66618 for some discussions.

Reviewed By: bkramer, rsmith

Differential Revision: https://reviews.llvm.org/D92297
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGenCXX/this-nonnull.cpp