From d690862bbcb9dd298b71f72da0c8595886597df2 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Tue, 11 Sep 2018 11:51:29 +0000 Subject: [PATCH] [FuncAttrs] Remove "access range attributes" for read-none functions The presence of readnone and an access range attribute (argmemonly, inaccessiblememonly, inaccessiblemem_or_argmemonly) is considered an error by the verifier. This seems strict but also not wrong. This patch makes sure function attribute detection will remove all access range attributes for readnone functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341927 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/FunctionAttrs.cpp | 7 ++++ .../FunctionAttrs/incompatible_fn_attrs.ll | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp index d40ee30f453..72c850fca99 100644 --- a/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/lib/Transforms/IPO/FunctionAttrs.cpp @@ -281,6 +281,13 @@ static bool addReadAttrs(const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter) { F->removeFnAttr(Attribute::ReadNone); F->removeFnAttr(Attribute::WriteOnly); + if (!WritesMemory && !ReadsMemory) { + // Clear out any "access range attributes" if readnone was deduced. + F->removeFnAttr(Attribute::ArgMemOnly); + F->removeFnAttr(Attribute::InaccessibleMemOnly); + F->removeFnAttr(Attribute::InaccessibleMemOrArgMemOnly); + } + // Add in the new attribute. if (WritesMemory && !ReadsMemory) F->addFnAttr(Attribute::WriteOnly); diff --git a/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll b/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll new file mode 100644 index 00000000000..79af817ff03 --- /dev/null +++ b/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll @@ -0,0 +1,32 @@ +; RUN: opt -S -o - -functionattrs %s | FileCheck %s +; RUN: opt -S -o - -passes=function-attrs %s | FileCheck %s + +; Verify we remove argmemonly/inaccessiblememonly/inaccessiblemem_or_argmemonly +; function attributes when we derive readnone. + +; Function Attrs: argmemonly +define i32* @given_argmem_infer_readnone(i32* %p) #0 { +; CHECK: define i32* @given_argmem_infer_readnone(i32* readnone returned %p) #0 { +entry: + ret i32* %p +} + +; Function Attrs: inaccessiblememonly +define i32* @given_inaccessible_infer_readnone(i32* %p) #1 { +; CHECK: define i32* @given_inaccessible_infer_readnone(i32* readnone returned %p) #0 { +entry: + ret i32* %p +} + +; Function Attrs: inaccessiblemem_or_argmemonly +define i32* @given_inaccessible_or_argmem_infer_readnone(i32* %p) #2 { +; CHECK: define i32* @given_inaccessible_or_argmem_infer_readnone(i32* readnone returned %p) #0 { +entry: + ret i32* %p +} + +attributes #0 = { argmemonly } +attributes #1 = { inaccessiblememonly } +attributes #2 = { inaccessiblemem_or_argmemonly } +; CHECK: attributes #0 = { norecurse nounwind readnone } +; CHECK-NOT: attributes