diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -5562,8 +5562,8 @@ } } - // "Upgrade" older incorrect branch weights by dropping them. for (auto &I : instructions(F)) { + // "Upgrade" older incorrect branch weights by dropping them. if (auto *MD = I.getMetadata(LLVMContext::MD_prof)) { if (MD->getOperand(0) != nullptr && isa(MD->getOperand(0))) { MDString *MDS = cast(MD->getOperand(0)); @@ -5590,6 +5590,12 @@ I.setMetadata(LLVMContext::MD_prof, nullptr); } } + + // Remove align from return attribute on CallInst. + if (auto *CI = dyn_cast(&I)) { + if (CI->getFunctionType()->getReturnType()->isVoidTy()) + CI->removeAttribute(0, Attribute::Alignment); + } } // Look for functions that rely on old function attribute behavior. diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -4371,6 +4371,12 @@ Attribute NewAttr = Attribute::getWithByValType(F.getContext(), ByValTy); F.addParamAttr(0, NewAttr); } + + // If function has void return type, check it has align attribute. It has no + // affect on the return type and no longer passes the verifier. + if (F.getReturnType()->isVoidTy() && + F.hasAttribute(AttributeList::ReturnIndex, Attribute::Alignment)) + F.removeAttribute(AttributeList::ReturnIndex, Attribute::Alignment); } static bool isOldLoopArgument(Metadata *MD) { diff --git a/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll b/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll @@ -0,0 +1,14 @@ +; Check upgrade is removing the incompatible attributes on void return type. + +; RUN: llvm-dis < %s.bc | FileCheck %s + +; CHECK: define void @f() +define align 8 void @f() { + ret void +} + +define void @g() { +; CHECK: call void @f() + call align 8 void @f(); + ret void +} diff --git a/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll.bc b/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll.bc new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@