[clang] [Clang] Fix unnecessary extra return block emmited during function epilog after musttail call (PR #134282)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 3 10:29:41 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Kiran (kiran-isaac)
<details>
<summary>Changes</summary>
closes #<!-- -->104770.
We clear the insert point after musttail call, and check for this when generating the function epilog.
We also check for a return point when emitting the return statement for a complex value
---
Full diff: https://github.com/llvm/llvm-project/pull/134282.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGCall.cpp (+7-1)
- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+4-1)
``````````diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index b202255c3a15b..81a915ed7de22 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3897,6 +3897,13 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
return;
}
+ // If there is no valid insert point, we won't emit a return.
+ // The insert point could be null if we have already emitted a return
+ // (e.g. if musttail)
+ if (!HaveInsertPoint()) {
+ return;
+ }
+
llvm::DebugLoc RetDbgLoc;
llvm::Value *RV = nullptr;
QualType RetTy = FI.getReturnType();
@@ -5990,7 +5997,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
else
Builder.CreateRet(CI);
Builder.ClearInsertionPoint();
- EnsureInsertPoint();
return GetUndefRValue(RetTy);
}
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp
index f556594f4a9ec..a9b0a15c0383c 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -1491,7 +1491,10 @@ void CodeGenFunction::EmitComplexExprIntoLValue(const Expr *E, LValue dest,
"Invalid complex expression to emit");
ComplexExprEmitter Emitter(*this);
ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E));
- Emitter.EmitStoreOfComplex(Val, dest, isInit);
+ // The insert point may be empty if we have just emmited a
+ // musttail call.
+ if (HaveInsertPoint())
+ Emitter.EmitStoreOfComplex(Val, dest, isInit);
}
/// EmitStoreOfComplex - Store a complex number into the specified l-value.
``````````
</details>
https://github.com/llvm/llvm-project/pull/134282
More information about the cfe-commits
mailing list