From 3ec44c22b1d60cf63ab93a4a9097d8c2a0ad08aa Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 14 Mar 2022 13:03:04 +0100 Subject: [PATCH] [DeadArgElim] Guard against function type mismatch If the call function type and function type don't match, we should consider the function live (there is effectively a bitcast sitting in between). --- llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp | 3 ++- llvm/test/Transforms/DeadArgElim/opaque-ptr.ll | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp index d7d6c7d..1e25c77 100644 --- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -560,7 +560,8 @@ void DeadArgumentEliminationPass::SurveyFunction(const Function &F) { // If the function is PASSED IN as an argument, its address has been // taken. const auto *CB = dyn_cast(U.getUser()); - if (!CB || !CB->isCallee(&U)) { + if (!CB || !CB->isCallee(&U) || + CB->getFunctionType() != F.getFunctionType()) { MarkLive(F); return; } diff --git a/llvm/test/Transforms/DeadArgElim/opaque-ptr.ll b/llvm/test/Transforms/DeadArgElim/opaque-ptr.ll index 039614d..02f2e01 100644 --- a/llvm/test/Transforms/DeadArgElim/opaque-ptr.ll +++ b/llvm/test/Transforms/DeadArgElim/opaque-ptr.ll @@ -21,3 +21,21 @@ define void @caller() { call void @callee(i32 42, i32 24) ret void } + +define internal i16 @callee2(i16 %p1, i16 %p2) { +; CHECK-LABEL: define {{[^@]+}}@callee2 +; CHECK-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) { +; CHECK-NEXT: ret i16 [[P2]] +; + ret i16 %p2 +} + +define i16 @caller2(i16 %a) { +; CHECK-LABEL: define {{[^@]+}}@caller2 +; CHECK-SAME: (i16 [[A:%.*]]) { +; CHECK-NEXT: [[CALL:%.*]] = call i16 @callee2(i16 [[A]], i32 42) +; CHECK-NEXT: ret i16 [[CALL]] +; + %call = call i16 @callee2(i16 %a, i32 42) + ret i16 %call +} -- 2.7.4