[llvm] [InstCombine] Add an option to skip simplification on call instruction where a non-void return value is expected while the callee returns void (PR #98536)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 13:22:45 PDT 2024
https://github.com/yozhu created https://github.com/llvm/llvm-project/pull/98536
Add an option to skip simplification on call instruction where a non-void
return value is expected but the callee returns void, which is undefined
behavior and can lead to non-determinism runtime behaviors or crashes.
>From 03bb6f3b5d309c9dd9f0c901ca006783ca98bfca Mon Sep 17 00:00:00 2001
From: YongKang Zhu <yongzhu at fb.com>
Date: Thu, 11 Jul 2024 13:20:54 -0700
Subject: [PATCH] [InstCombine] Add an option to not take advantage of void to
non-void conversion on return value
---
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 0ca56f08c333d..880932159f570 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -89,6 +89,11 @@ static cl::opt<unsigned> GuardWideningWindow(
cl::desc("How wide an instruction window to bypass looking for "
"another guard"));
+static cl::opt<bool> SkipRetTypeVoidToNonVoidCallInst(
+ "instcombine-skip-call-ret-type-void-to-nonvoid", cl::init(false),
+ cl::desc("skip simplifying call instruction which expects a non-void "
+ "return value but the callee returns void"));
+
/// Return the specified type promoted as it would be to pass though a va_arg
/// area.
static Type *getPromotedType(Type *Ty) {
@@ -4073,7 +4078,7 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) {
if (!Caller->use_empty() &&
// void -> non-void is handled specially
- !NewRetTy->isVoidTy())
+ (SkipRetTypeVoidToNonVoidCallInst || !NewRetTy->isVoidTy()))
return false; // Cannot transform this return value.
}
More information about the llvm-commits
mailing list