diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -401,9 +401,16 @@ // Enumerate types used by function bodies and argument lists. for (const Function &F : M) { - for (const Argument &A : F.args()) + for (const Argument &A : F.args()) { EnumerateType(A.getType()); + if (A.hasAttribute(Attribute::ByVal)) + EnumerateType(A.getParamByValType()); + + if (A.hasAttribute(Attribute::StructRet)) + EnumerateType(A.getParamStructRetType()); + } + // Enumerate metadata attached to this function. MDs.clear(); F.getAllMetadata(MDs); @@ -971,8 +978,6 @@ // Adding function arguments to the value table. for (const auto &I : F.args()) { EnumerateValue(&I); - if (I.hasAttribute(Attribute::ByVal)) - EnumerateType(I.getParamByValType()); } FirstFuncConstantID = Values.size(); diff --git a/llvm/test/Linker/Inputs/sret-types-1.ll b/llvm/test/Linker/Inputs/sret-types-1.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Linker/Inputs/sret-types-1.ll @@ -0,0 +1,5 @@ +%v = type { i32 } + +define void @f(%v* sret(%v) %0) { + ret void +} diff --git a/llvm/test/Linker/sret-types.ll b/llvm/test/Linker/sret-types.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Linker/sret-types.ll @@ -0,0 +1,10 @@ +; RUN: llvm-link %s %p/Inputs/sret-types-1.ll | llvm-dis | FileCheck %s + +%v = type { i32 } + +define void @g(%v* %0) { + ret void +} + +; CHECK: define void @g(%v* %0) +; CHECK: define void @f(%v* sret(%v) %0)