[PATCH] D88423: Fix llvm-link assert failure in BitCodeWriter

Sanne Wouda via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 08:32:24 PDT 2020


sanwou01 created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
sanwou01 requested review of this revision.

In some cases, the attribute group table contains a reference to a type
that was not enumerated.  Enumerate the type parameters of byval and
sret during the construction of ValueEnumerator.  In the case of sret,
its type was not enumerated at all.

This bug was recently introduced by D88241 <https://reviews.llvm.org/D88241>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88423

Files:
  llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
  llvm/test/Linker/Inputs/sret-types-1.ll
  llvm/test/Linker/sret-types.ll


Index: llvm/test/Linker/sret-types.ll
===================================================================
--- /dev/null
+++ 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)
Index: llvm/test/Linker/Inputs/sret-types-1.ll
===================================================================
--- /dev/null
+++ llvm/test/Linker/Inputs/sret-types-1.ll
@@ -0,0 +1,5 @@
+%v = type { i32 }
+
+define void @f(%v* sret(%v) %0) {
+  ret void
+}
Index: llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
===================================================================
--- llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ 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();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88423.294717.patch
Type: text/x-patch
Size: 1673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200928/55b0d162/attachment.bin>


More information about the llvm-commits mailing list