Skip to content

Commit 3c777f0

Browse files
authored
[Inliner] Don't propagate access attr to byval params (#112256)
- **[Inliner] Add tests for bad propagationg of access attr for `byval` param; NFC** - **[Inliner] Don't propagate access attr to `byval` params** We previously only handled the case where the `byval` attr was in the callbase's param attr list. This PR also handles the case if the `ByVal` was a param attr on the function's param attr list.
1 parent e100e4a commit 3c777f0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB,
13981398
if (!Arg)
13991399
continue;
14001400

1401-
if (AL.hasParamAttr(I, Attribute::ByVal))
1401+
if (NewInnerCB->paramHasAttr(I, Attribute::ByVal))
14021402
// It's unsound to propagate memory attributes to byval arguments.
14031403
// Even if CalledFunction doesn't e.g. write to the argument,
14041404
// the call to NewInnerCB may write to its by-value copy.

llvm/test/Transforms/Inline/access-attributes-prop.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,23 @@ define ptr @callee_bad_param_prop(ptr readonly %x) {
580580
%r = tail call ptr @llvm.ptrmask(ptr %x, i64 -1)
581581
ret ptr %r
582582
}
583+
584+
define dso_local void @foo_byval_readonly2(ptr readonly %p) {
585+
; CHECK-LABEL: define {{[^@]+}}@foo_byval_readonly2
586+
; CHECK-SAME: (ptr readonly [[P:%.*]]) {
587+
; CHECK-NEXT: call void @bar4(ptr [[P]])
588+
; CHECK-NEXT: ret void
589+
;
590+
call void @bar4(ptr %p)
591+
ret void
592+
}
593+
594+
define void @prop_byval_readonly2(ptr %p) {
595+
; CHECK-LABEL: define {{[^@]+}}@prop_byval_readonly2
596+
; CHECK-SAME: (ptr [[P:%.*]]) {
597+
; CHECK-NEXT: call void @bar4(ptr [[P]])
598+
; CHECK-NEXT: ret void
599+
;
600+
call void @foo_byval_readonly2(ptr %p)
601+
ret void
602+
}

0 commit comments

Comments
 (0)