diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 110fd6de5c696..55ad2b6d62000 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1398,7 +1398,7 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB, if (!Arg) continue; - if (AL.hasParamAttr(I, Attribute::ByVal)) + if (NewInnerCB->paramHasAttr(I, Attribute::ByVal)) // It's unsound to propagate memory attributes to byval arguments. // Even if CalledFunction doesn't e.g. write to the argument, // the call to NewInnerCB may write to its by-value copy. diff --git a/llvm/test/Transforms/Inline/access-attributes-prop.ll b/llvm/test/Transforms/Inline/access-attributes-prop.ll index 2c55f5f3b1f6c..5051c92345ec7 100644 --- a/llvm/test/Transforms/Inline/access-attributes-prop.ll +++ b/llvm/test/Transforms/Inline/access-attributes-prop.ll @@ -580,3 +580,23 @@ define ptr @callee_bad_param_prop(ptr readonly %x) { %r = tail call ptr @llvm.ptrmask(ptr %x, i64 -1) ret ptr %r } + +define dso_local void @foo_byval_readonly2(ptr readonly %p) { +; CHECK-LABEL: define {{[^@]+}}@foo_byval_readonly2 +; CHECK-SAME: (ptr readonly [[P:%.*]]) { +; CHECK-NEXT: call void @bar4(ptr [[P]]) +; CHECK-NEXT: ret void +; + call void @bar4(ptr %p) + ret void +} + +define void @prop_byval_readonly2(ptr %p) { +; CHECK-LABEL: define {{[^@]+}}@prop_byval_readonly2 +; CHECK-SAME: (ptr [[P:%.*]]) { +; CHECK-NEXT: call void @bar4(ptr [[P]]) +; CHECK-NEXT: ret void +; + call void @foo_byval_readonly2(ptr %p) + ret void +}