Skip to content

Commit ccaded2

Browse files
authored
[Inliner] Prevent adding pointer attributes to non-pointer arguments (#115569)
Fixes a crash seen after #114311
1 parent 958e37c commit ccaded2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,18 +1465,21 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB,
14651465
}
14661466
}
14671467
AL = AL.addParamAttributes(Context, I, NewAB);
1468-
} else {
1468+
} else if (NewInnerCB->getArgOperand(I)->getType()->isPointerTy()) {
14691469
// Check if the underlying value for the parameter is an argument.
14701470
const Value *UnderlyingV =
14711471
getUnderlyingObject(InnerCB->getArgOperand(I));
14721472
Arg = dyn_cast<Argument>(UnderlyingV);
14731473
if (!Arg)
14741474
continue;
14751475
ArgNo = Arg->getArgNo();
1476+
} else {
1477+
continue;
14761478
}
14771479

14781480
// If so, propagate its access attributes.
14791481
AL = AL.addParamAttributes(Context, I, ValidObjParamAttrs[ArgNo]);
1482+
14801483
// We can have conflicting attributes from the inner callsite and
14811484
// to-be-inlined callsite. In that case, choose the most
14821485
// 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)