From eb9f7c28e5fe6d75fed3587023e17f2997c8024b Mon Sep 17 00:00:00 2001 From: Tres Popp Date: Tue, 29 Sep 2020 10:24:54 +0200 Subject: Revert "OpaquePtr: Add type to sret attribute" This reverts commit 55c4ff91bd820d72014f63dcf7f3d5a0d3397986. Issues were introduced as discussed in https://reviews.llvm.org/D88241 where this change made previous bugs in the linker and BitCodeWriter visible. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 61 +++++++++++-------------------- 1 file changed, 22 insertions(+), 39 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1cb7113..4d69dd7 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -717,9 +717,9 @@ private: return getFnValueByID(ValNo, Ty); } - /// Upgrades old-style typeless byval or sret attributes by adding the - /// corresponding argument's pointee type. - void propagateByValSRetTypes(CallBase *CB, ArrayRef ArgsFullTys); + /// Upgrades old-style typeless byval attributes by adding the corresponding + /// argument's pointee type. + void propagateByValTypes(CallBase *CB, ArrayRef ArgsFullTys); /// Converts alignment exponent (i.e. power of two (or zero)) to the /// corresponding alignment to use. If alignment is too large, returns @@ -1611,8 +1611,6 @@ Error BitcodeReader::parseAttributeGroupBlock() { // this AttributeList with a function. if (Kind == Attribute::ByVal) B.addByValAttr(nullptr); - else if (Kind == Attribute::StructRet) - B.addStructRetAttr(nullptr); B.addAttribute(Kind); } else if (Record[i] == 1) { // Integer attribute @@ -1656,8 +1654,6 @@ Error BitcodeReader::parseAttributeGroupBlock() { return Err; if (Kind == Attribute::ByVal) { B.addByValAttr(HasType ? getTypeByID(Record[++i]) : nullptr); - } else if (Kind == Attribute::StructRet) { - B.addStructRetAttr(HasType ? getTypeByID(Record[++i]) : nullptr); } else if (Kind == Attribute::ByRef) { B.addByRefAttr(getTypeByID(Record[++i])); } else if (Kind == Attribute::Preallocated) { @@ -3292,24 +3288,17 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef Record) { Func->setLinkage(getDecodedLinkage(RawLinkage)); Func->setAttributes(getAttributes(Record[4])); - // Upgrade any old-style byval or sret without a type by propagating the - // argument's pointee type. There should be no opaque pointers where the byval - // type is implicit. + // Upgrade any old-style byval without a type by propagating the argument's + // pointee type. There should be no opaque pointers where the byval type is + // implicit. for (unsigned i = 0; i != Func->arg_size(); ++i) { - for (Attribute::AttrKind Kind : {Attribute::ByVal, Attribute::StructRet}) { - if (!Func->hasParamAttribute(i, Kind)) - continue; - - Func->removeParamAttr(i, Kind); + if (!Func->hasParamAttribute(i, Attribute::ByVal)) + continue; - Type *PTy = cast(FullFTy)->getParamType(i); - Type *PtrEltTy = getPointerElementFlatType(PTy); - Attribute NewAttr = - Kind == Attribute::ByVal - ? Attribute::getWithByValType(Context, PtrEltTy) - : Attribute::getWithStructRetType(Context, PtrEltTy); - Func->addParamAttr(i, NewAttr); - } + Type *PTy = cast(FullFTy)->getParamType(i); + Func->removeParamAttr(i, Attribute::ByVal); + Func->addParamAttr(i, Attribute::getWithByValType( + Context, getPointerElementFlatType(PTy))); } MaybeAlign Alignment; @@ -3770,22 +3759,16 @@ Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) { return Error::success(); } -void BitcodeReader::propagateByValSRetTypes(CallBase *CB, - ArrayRef ArgsFullTys) { +void BitcodeReader::propagateByValTypes(CallBase *CB, + ArrayRef ArgsFullTys) { for (unsigned i = 0; i != CB->arg_size(); ++i) { - for (Attribute::AttrKind Kind : {Attribute::ByVal, Attribute::StructRet}) { - if (!CB->paramHasAttr(i, Kind)) - continue; - - CB->removeParamAttr(i, Kind); + if (!CB->paramHasAttr(i, Attribute::ByVal)) + continue; - Type *PtrEltTy = getPointerElementFlatType(ArgsFullTys[i]); - Attribute NewAttr = - Kind == Attribute::ByVal - ? Attribute::getWithByValType(Context, PtrEltTy) - : Attribute::getWithStructRetType(Context, PtrEltTy); - CB->addParamAttr(i, NewAttr); - } + CB->removeParamAttr(i, Attribute::ByVal); + CB->addParamAttr( + i, Attribute::getWithByValType( + Context, getPointerElementFlatType(ArgsFullTys[i]))); } } @@ -4637,7 +4620,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) { cast(I)->setCallingConv( static_cast(CallingConv::MaxID & CCInfo)); cast(I)->setAttributes(PAL); - propagateByValSRetTypes(cast(I), ArgsFullTys); + propagateByValTypes(cast(I), ArgsFullTys); break; } @@ -5244,7 +5227,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) { TCK = CallInst::TCK_NoTail; cast(I)->setTailCallKind(TCK); cast(I)->setAttributes(PAL); - propagateByValSRetTypes(cast(I), ArgsFullTys); + propagateByValTypes(cast(I), ArgsFullTys); if (FMF.any()) { if (!isa(I)) return error("Fast-math-flags specified for call without " -- cgit v1.1