From cb3580e7ad247dfdcf2ad279895f52bb73c4cee4 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Tue, 29 Jun 2021 11:38:18 -0700 Subject: [PATCH] [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 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 3 +++ llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 5 +++++ llvm/test/Assembler/opaque-ptr.ll | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 8f8bd73f2082..854243ee95bc 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3333,6 +3333,9 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef Record) { if (!Func->hasParamAttribute(i, Kind)) continue; + if (Func->getParamAttribute(i, Kind).getValueAsType()) + continue; + Func->removeParamAttr(i, Kind); Type *PTy = cast(FTy)->getParamType(i); diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index 2be3ca741f16..d86db61ee1f4 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 5ee57fae18f0..c168fda39bf7 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 +}