https://github.com/kiran-isaac created https://github.com/llvm/llvm-project/pull/134282
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 >From 0de953bb0004ff4d75f456fbb73bb6db1b16861e Mon Sep 17 00:00:00 2001 From: kiran <kiranist...@outlook.com> Date: Mon, 31 Mar 2025 08:42:11 +0100 Subject: [PATCH] [Clang] Fix unnecessary extra return block emmited during function epilog after musttail call --- clang/lib/CodeGen/CGCall.cpp | 8 +++++++- clang/lib/CodeGen/CGExprComplex.cpp | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits