diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 05e692915f2b4..c16433cc52895 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -785,7 +785,9 @@ static void PropagateCallSiteMetadata(CallBase &CB, ValueToValueMapTy &VMap) { for (ValueToValueMapTy::iterator VMI = VMap.begin(), VMIE = VMap.end(); VMI != VMIE; ++VMI) { - if (!VMI->second) + // Check that key is an instruction, to skip the Argument mapping, which + // points to an instruction in the original function, not the inlined one. + if (!VMI->second || !isa(VMI->first)) continue; Instruction *NI = dyn_cast(VMI->second); diff --git a/llvm/test/Transforms/Inline/pr48209.ll b/llvm/test/Transforms/Inline/pr48209.ll index c36a1729182a0..94d33bec4fce0 100644 --- a/llvm/test/Transforms/Inline/pr48209.ll +++ b/llvm/test/Transforms/Inline/pr48209.ll @@ -11,7 +11,7 @@ define internal void @inlined_function(i8* %arg) { ; TODO: This is a miscompile. define void @test(i8** %p) { ; CHECK-LABEL: @test( -; CHECK-NEXT: [[ARG:%.*]] = load i8*, i8** [[P:%.*]], align 8, !alias.scope !0, !noalias !0 +; CHECK-NEXT: [[ARG:%.*]] = load i8*, i8** [[P:%.*]], align 8, !alias.scope !0 ; CHECK-NEXT: call void @external_function(i8* [[ARG]]), !noalias !0 ; CHECK-NEXT: ret void ;