[llvm] c5ce603 - Linker: Fix linking of byref types

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 17 08:02:21 PST 2020


Author: Matt Arsenault
Date: 2020-11-17T11:02:04-05:00
New Revision: c5ce6036c169522eebd2ed330de58f4980cfb45a

URL: https://github.com/llvm/llvm-project/commit/c5ce6036c169522eebd2ed330de58f4980cfb45a
DIFF: https://github.com/llvm/llvm-project/commit/c5ce6036c169522eebd2ed330de58f4980cfb45a.diff

LOG: Linker: Fix linking of byref types

This wasn't properly remapping the type like with the other
attributes, so this would end up hitting a verifier error after
linking different modules using byref.

Added: 
    llvm/test/Linker/Inputs/byref-type-input.ll
    llvm/test/Linker/byref-types.ll

Modified: 
    llvm/lib/Linker/IRMover.cpp
    llvm/lib/Transforms/Utils/ValueMapper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 47018509a776..953f2c31a55f 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -639,7 +639,7 @@ GlobalVariable *IRLinker::copyGlobalVariableProto(const GlobalVariable *SGVar) {
 AttributeList IRLinker::mapAttributeTypes(LLVMContext &C, AttributeList Attrs) {
   for (unsigned i = 0; i < Attrs.getNumAttrSets(); ++i) {
     for (Attribute::AttrKind TypedAttr :
-         {Attribute::ByVal, Attribute::StructRet}) {
+         {Attribute::ByVal, Attribute::StructRet, Attribute::ByRef}) {
       if (Attrs.hasAttribute(i, TypedAttr)) {
         if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) {
           Attrs = Attrs.replaceAttributeType(C, i, TypedAttr, TypeMap.get(Ty));

diff  --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index b2cb8cb8e319..ec5769309f86 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -901,7 +901,7 @@ void Mapper::remapInstruction(Instruction *I) {
     AttributeList Attrs = CB->getAttributes();
     for (unsigned i = 0; i < Attrs.getNumAttrSets(); ++i) {
       for (Attribute::AttrKind TypedAttr :
-           {Attribute::ByVal, Attribute::StructRet}) {
+           {Attribute::ByVal, Attribute::StructRet, Attribute::ByRef}) {
         if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) {
           Attrs = Attrs.replaceAttributeType(C, i, TypedAttr,
                                              TypeMapper->remapType(Ty));

diff  --git a/llvm/test/Linker/Inputs/byref-type-input.ll b/llvm/test/Linker/Inputs/byref-type-input.ll
new file mode 100644
index 000000000000..1ca8a897327b
--- /dev/null
+++ b/llvm/test/Linker/Inputs/byref-type-input.ll
@@ -0,0 +1,13 @@
+%a = type { i64 }
+%struct = type { i32, i8 }
+
+define void @g(%a* byref(%a)) {
+  ret void
+}
+
+declare void @baz(%struct* byref(%struct))
+
+define void @foo(%struct* byref(%struct) %a) {
+  call void @baz(%struct* byref(%struct) %a)
+  ret void
+}

diff  --git a/llvm/test/Linker/byref-types.ll b/llvm/test/Linker/byref-types.ll
new file mode 100644
index 000000000000..b79fb2d9df8e
--- /dev/null
+++ b/llvm/test/Linker/byref-types.ll
@@ -0,0 +1,25 @@
+; RUN: llvm-link %s %p/Inputs/byref-type-input.ll -S | FileCheck %s
+
+%a = type { i64 }
+%struct = type { i32, i8 }
+
+; CHECK-LABEL: define void @f(%a* byref(%a) %0)
+define void @f(%a* byref(%a)) {
+  ret void
+}
+
+; CHECK-LABEL: define void @bar(
+; CHECK: call void @foo(%struct* byref(%struct) %ptr)
+define void @bar() {
+  %ptr = alloca %struct
+  call void @foo(%struct* byref(%struct) %ptr)
+  ret void
+}
+
+; CHECK-LABEL: define void @g(%a* byref(%a) %0)
+
+; CHECK-LABEL: define void @foo(%struct* byref(%struct) %a)
+; CHECK-NEXT:   call void @baz(%struct* byref(%struct) %a)
+declare void @foo(%struct* byref(%struct) %a)
+
+; CHECK: declare void @baz(%struct* byref(%struct))


        


More information about the llvm-commits mailing list