From 51561b5e8017a3153629ba45b89d013ffa665f6c Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Tue, 12 Apr 2022 15:16:11 -0700 Subject: [PATCH] [ArgPromo][OpaquePointer] Don't promote mismatched function types Mismatched call/callee function types is considered an indirect call. Fixes crash in https://reviews.llvm.org/D123300#3446023. --- llvm/lib/Transforms/IPO/ArgumentPromotion.cpp | 3 ++- llvm/test/Transforms/ArgumentPromotion/opaque-ptr.ll | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp index 354971a..18a1b83 100644 --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -793,7 +793,8 @@ promoteArguments(Function *F, function_ref AARGetter, for (Use &U : F->uses()) { CallBase *CB = dyn_cast(U.getUser()); // Must be a direct call. - if (CB == nullptr || !CB->isCallee(&U)) + if (CB == nullptr || !CB->isCallee(&U) || + CB->getFunctionType() != F->getFunctionType()) return nullptr; // Can't change signature of musttail callee diff --git a/llvm/test/Transforms/ArgumentPromotion/opaque-ptr.ll b/llvm/test/Transforms/ArgumentPromotion/opaque-ptr.ll index 25939bc..70cdf0c 100644 --- a/llvm/test/Transforms/ArgumentPromotion/opaque-ptr.ll +++ b/llvm/test/Transforms/ArgumentPromotion/opaque-ptr.ll @@ -80,3 +80,21 @@ define void @caller_overlap(ptr %p) { call i32 @callee_overlap(ptr %p) ret void } + +; Don't promote calls with function type mismatch. +define void @caller_type_mismatch() { +; CHECK-LABEL: define {{[^@]+}}@caller_type_mismatch() { +; CHECK-NEXT: [[TMP1:%.*]] = call i32 @callee_type_mismatch(ptr null) +; CHECK-NEXT: ret void +; + call i32 @callee_type_mismatch(ptr null) + ret void +} + +define internal void @callee_type_mismatch(ptr %p) { +; CHECK-LABEL: define {{[^@]+}}@callee_type_mismatch +; CHECK-SAME: (ptr [[P:%.*]]) { +; CHECK-NEXT: ret void +; + ret void +} -- 2.7.4