Skip to content

Commit 48f6814

Browse files
committed
[Inliner] Prevent adding pointer attributes to non-pointer arguments
Fixes a crash seen after #114311
1 parent 6b21cf8 commit 48f6814

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,15 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB,
14771477

14781478
// If so, propagate its access attributes.
14791479
AL = AL.addParamAttributes(Context, I, ValidObjParamAttrs[ArgNo]);
1480+
1481+
// If the argument is not a pointer type, remove attributes which only
1482+
// apply to pointer types.
1483+
if (!NewInnerCB->getArgOperand(I)->getType()->isPointerTy()) {
1484+
AL = AL.removeParamAttribute(Context, I, Attribute::ReadNone);
1485+
AL = AL.removeParamAttribute(Context, I, Attribute::ReadOnly);
1486+
continue;
1487+
}
1488+
14801489
// We can have conflicting attributes from the inner callsite and
14811490
// to-be-inlined callsite. In that case, choose the most
14821491
// restrictive.

llvm/test/Transforms/Inline/arg-attr-propagation.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,29 @@ define i32 @caller3(ptr dereferenceable(33) %t1) {
7676
ret i32 %t2
7777
}
7878

79+
; Make sure that we don't propagate a pointer-only attribute to a vector of pointers.
80+
81+
declare void @helper4(<4 x ptr> %ptr)
82+
83+
define void @callee4(ptr readonly %ptr, <4 x i64> %idx) {
84+
; CHECK-LABEL: define {{[^@]+}}@callee4
85+
; CHECK-SAME: (ptr readonly [[PTR:%.*]], <4 x i64> [[IDX:%.*]]) {
86+
; CHECK-NEXT: [[PTRS:%.*]] = getelementptr inbounds i8, ptr [[PTR]], <4 x i64> [[IDX]]
87+
; CHECK-NEXT: call void @helper4(<4 x ptr> [[PTRS]])
88+
; CHECK-NEXT: ret void
89+
;
90+
%ptrs = getelementptr inbounds i8, ptr %ptr, <4 x i64> %idx
91+
call void @helper4(<4 x ptr> %ptrs)
92+
ret void
93+
}
94+
95+
define void @caller4(ptr readonly %ptr, <4 x i64> %idx) {
96+
; CHECK-LABEL: define {{[^@]+}}@caller4
97+
; CHECK-SAME: (ptr readonly [[PTR:%.*]], <4 x i64> [[IDX:%.*]]) {
98+
; CHECK-NEXT: [[PTRS_I:%.*]] = getelementptr inbounds i8, ptr [[PTR]], <4 x i64> [[IDX]]
99+
; CHECK-NEXT: call void @helper4(<4 x ptr> [[PTRS_I]])
100+
; CHECK-NEXT: ret void
101+
;
102+
call void @callee4(ptr readonly %ptr, <4 x i64> %idx)
103+
ret void
104+
}

0 commit comments

Comments
 (0)