[llvm] cb3580e - [OpaquePtr][BitcodeWriter] Handle attributes with types

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 29 14:47:57 PDT 2021


Author: Arthur Eubanks
Date: 2021-06-29T14:47:29-07:00
New Revision: cb3580e7ad247dfdcf2ad279895f52bb73c4cee4

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

LOG: [OpaquePtr][BitcodeWriter] Handle attributes with types

For example, byval.

Skip the type attribute auto-upgrade if we already have the type.

I've actually seen this error of the ValueEnumerator missing a type
attribute's type in a non-opaque pointer context.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D105138

Added: 
    

Modified: 
    llvm/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
    llvm/test/Assembler/opaque-ptr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 8f8bd73f2082c..854243ee95bc6 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3333,6 +3333,9 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef<uint64_t> Record) {
       if (!Func->hasParamAttribute(i, Kind))
         continue;
 
+      if (Func->getParamAttribute(i, Kind).getValueAsType())
+        continue;
+
       Func->removeParamAttr(i, Kind);
 
       Type *PTy = cast<FunctionType>(FTy)->getParamType(i);

diff  --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
index 2be3ca741f165..d86db61ee1f46 100644
--- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -1045,6 +1045,11 @@ void ValueEnumerator::EnumerateAttributes(AttributeList PAL) {
     if (Entry == 0) {
       AttributeGroups.push_back(Pair);
       Entry = AttributeGroups.size();
+
+      for (Attribute Attr : AS) {
+        if (Attr.isTypeAttribute())
+          EnumerateType(Attr.getValueAsType());
+      }
     }
   }
 }

diff  --git a/llvm/test/Assembler/opaque-ptr.ll b/llvm/test/Assembler/opaque-ptr.ll
index 5ee57fae18f06..c168fda39bf70 100644
--- a/llvm/test/Assembler/opaque-ptr.ll
+++ b/llvm/test/Assembler/opaque-ptr.ll
@@ -141,3 +141,8 @@ cleanup:
     cleanup
   ret void
 }
+
+; CHECK: define void @byval(ptr byval({ i32, i32 }) %0)
+define void @byval(ptr byval({ i32, i32 }) %0) {
+  ret void
+}


        


More information about the llvm-commits mailing list