From dfedae50018f321cb2189a95936511b2506e5bce Mon Sep 17 00:00:00 2001 From: Hideto Ueno Date: Fri, 29 Nov 2019 06:45:07 +0000 Subject: [PATCH] [Attributor] Remove dereferenceable_or_null when nonull is present Summary: This patch prevents the simultaneous presence of `dereferenceable` and `dereferenceable_or_null` attribute Reviewers: jdoerfert, sstefan1 Reviewed By: jdoerfert Subscribers: lebedev.ri, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70789 --- llvm/lib/Transforms/IPO/Attributor.cpp | 10 ++++++++++ llvm/test/Transforms/FunctionAttrs/dereferenceable.ll | 9 +++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index faf0cdf..e736986 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -2971,6 +2971,16 @@ struct AADereferenceableImpl : AADereferenceable { return TrackUse; } + /// See AbstractAttribute::manifest(...). + ChangeStatus manifest(Attributor &A) override { + ChangeStatus Change = AADereferenceable::manifest(A); + if (isAssumedNonNull() && hasAttr(Attribute::DereferenceableOrNull)) { + removeAttrs({Attribute::DereferenceableOrNull}); + return ChangeStatus::CHANGED; + } + return Change; + } + void getDeducedAttributes(LLVMContext &Ctx, SmallVectorImpl &Attrs) const override { // TODO: Add *_globally support diff --git a/llvm/test/Transforms/FunctionAttrs/dereferenceable.ll b/llvm/test/Transforms/FunctionAttrs/dereferenceable.ll index 1c285fa..951b504 100644 --- a/llvm/test/Transforms/FunctionAttrs/dereferenceable.ll +++ b/llvm/test/Transforms/FunctionAttrs/dereferenceable.ll @@ -30,8 +30,7 @@ define i32* @test3_1(i32* dereferenceable(8) %0) local_unnamed_addr { } define i32* @test3_2(i32* dereferenceable_or_null(32) %0) local_unnamed_addr { -; FIXME: We should not have both deref(x) and deref_or_null(y) with x >= y. -; ATTRIBUTOR: define nonnull dereferenceable(16) i32* @test3_2(i32* nofree nonnull readnone dereferenceable(32) dereferenceable_or_null(32) "no-capture-maybe-returned" %0) +; ATTRIBUTOR: define nonnull dereferenceable(16) i32* @test3_2(i32* nofree nonnull readnone dereferenceable(32) "no-capture-maybe-returned" %0) %ret = getelementptr inbounds i32, i32* %0, i64 4 ret i32* %ret } @@ -202,3 +201,9 @@ define i32* @test_for_minus_index(i32* %p) { store i32 1, i32* %q ret i32* %q } + +define void @deref_or_null_and_nonnull(i32* dereferenceable_or_null(100) %0) { +; ATTRIBUTOR: define void @deref_or_null_and_nonnull(i32* nocapture nofree nonnull writeonly dereferenceable(100) %0) + store i32 1, i32* %0 + ret void +} -- 2.7.4