diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 814e985ebf7be..4d353c95b8930 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -1556,8 +1556,10 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn, ? Intrinsic::lifetime_start : Intrinsic::lifetime_end; rename(F); + // Old 2 argument form of these intrinsics have [Size, Ptr] as arguments. + // Use the Ptr argument to create new declaration. NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID, - F->getArg(0)->getType()); + F->getArg(1)->getType()); return true; } break; diff --git a/llvm/test/Assembler/autoupgrade-lifetime-intrinsics-invalid-decl.ll b/llvm/test/Assembler/autoupgrade-lifetime-intrinsics-invalid-decl.ll new file mode 100644 index 0000000000000..dec73f40bb451 --- /dev/null +++ b/llvm/test/Assembler/autoupgrade-lifetime-intrinsics-invalid-decl.ll @@ -0,0 +1,17 @@ +; Test to verify that autoupgrade does not end up creating an invalid +; declaration. +; RUN: llvm-as < %s | llvm-dis | FileCheck %s + +; CHECK-NOT: declare void @llvm.lifetime.start.i64(i64) +; CHECK-NOT: declare void @llvm.lifetime.end.i64(i64) + +define void @tests.lifetime.start.end() { + %a = alloca i8 + call void @llvm.lifetime.start(i64 1, ptr %a) + store i8 0, ptr %a + call void @llvm.lifetime.end(i64 1, ptr %a) + ret void +} + +declare void @llvm.lifetime.start.p0(i64, ptr) +declare void @llvm.lifetime.end.p0(i64, ptr)