Skip to content

Commit 2182665

Browse files
committed
[Bitcode] Don't confuse type attributes on declaration and call
We should not be using APIs here that try to fetch the attribute from both the call attributes and the function attributes. Otherwise we'll try to upgrade a non-existent sret attribute on the call using the attribute on the function.
1 parent a803cb9 commit 2182665

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,15 +4086,14 @@ Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) {
40864086

40874087
Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
40884088
ArrayRef<unsigned> ArgTyIDs) {
4089+
AttributeList Attrs = CB->getAttributes();
40894090
for (unsigned i = 0; i != CB->arg_size(); ++i) {
40904091
for (Attribute::AttrKind Kind : {Attribute::ByVal, Attribute::StructRet,
40914092
Attribute::InAlloca}) {
4092-
if (!CB->paramHasAttr(i, Kind) ||
4093-
CB->getParamAttr(i, Kind).getValueAsType())
4093+
if (!Attrs.hasParamAttr(i, Kind) ||
4094+
Attrs.getParamAttr(i, Kind).getValueAsType())
40944095
continue;
40954096

4096-
CB->removeParamAttr(i, Kind);
4097-
40984097
Type *PtrEltTy = getPtrElementTypeByID(ArgTyIDs[i]);
40994098
if (!PtrEltTy)
41004099
return error("Missing element type for typed attribute upgrade");
@@ -4114,7 +4113,7 @@ Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
41144113
llvm_unreachable("not an upgraded type attribute");
41154114
}
41164115

4117-
CB->addParamAttr(i, NewAttr);
4116+
Attrs = Attrs.addParamAttribute(Context, i, NewAttr);
41184117
}
41194118
}
41204119

@@ -4125,12 +4124,13 @@ Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
41254124
if (!CI.hasArg())
41264125
continue;
41274126

4128-
if (CI.isIndirect && !CB->getParamElementType(ArgNo)) {
4127+
if (CI.isIndirect && !Attrs.getParamElementType(ArgNo)) {
41294128
Type *ElemTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
41304129
if (!ElemTy)
41314130
return error("Missing element type for inline asm upgrade");
4132-
CB->addParamAttr(
4133-
ArgNo, Attribute::get(Context, Attribute::ElementType, ElemTy));
4131+
Attrs = Attrs.addParamAttribute(
4132+
Context, ArgNo,
4133+
Attribute::get(Context, Attribute::ElementType, ElemTy));
41344134
}
41354135

41364136
ArgNo++;
@@ -4140,18 +4140,19 @@ Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
41404140
switch (CB->getIntrinsicID()) {
41414141
case Intrinsic::preserve_array_access_index:
41424142
case Intrinsic::preserve_struct_access_index:
4143-
if (!CB->getParamElementType(0)) {
4143+
if (!Attrs.getParamElementType(0)) {
41444144
Type *ElTy = getPtrElementTypeByID(ArgTyIDs[0]);
41454145
if (!ElTy)
41464146
return error("Missing element type for elementtype upgrade");
41474147
Attribute NewAttr = Attribute::get(Context, Attribute::ElementType, ElTy);
4148-
CB->addParamAttr(0, NewAttr);
4148+
Attrs = Attrs.addParamAttribute(Context, 0, NewAttr);
41494149
}
41504150
break;
41514151
default:
41524152
break;
41534153
}
41544154

4155+
CB->setAttributes(Attrs);
41554156
return Error::success();
41564157
}
41574158

Binary file not shown.

llvm/test/Bitcode/invalid.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ RUN: FileCheck --check-prefix=INVALID-DIIMPORTEDENTITY-RECORD %s
292292

293293
INVALID-DIIMPORTEDENTITY-RECORD: Invalid DIImportedEntity record
294294

295-
RUN: not llvm-dis -disable-output -opaque-pointers %p/Inputs/missing-element-type-for-attribute.bc 2>&1 | \
296-
RUN: FileCheck --check-prefix=MISSING-ELEMENT-TYPE-FOR-ATTRIBUTE %s
297-
298-
MISSING-ELEMENT-TYPE-FOR-ATTRIBUTE: Missing element type for typed attribute upgrade
299295
RUN: not llvm-dis -disable-output -opaque-pointers %p/Inputs/invalid-forward-declare.bc 2>&1 | \
300296
RUN: FileCheck --check-prefix=INVALID-FORWARD-DECLARE %s
301297

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: llvm-as -opaque-pointers < %s | llvm-dis -opaque-pointers | FileCheck %s
2+
3+
; CHECK: declare void @decl(ptr sret(i64))
4+
; CHECK: call void @decl(ptr %arg)
5+
6+
declare void @decl(i64* sret(i64))
7+
8+
define void @test(i64* %arg) {
9+
call void @decl(i64* %arg)
10+
ret void
11+
}

0 commit comments

Comments
 (0)