https://github.com/kiran-isaac updated https://github.com/llvm/llvm-project/pull/134282
>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 1/2] [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. >From 3f59a59130cd106571abfc559d7e3706502574f5 Mon Sep 17 00:00:00 2001 From: kiran <kiranist...@outlook.com> Date: Thu, 3 Apr 2025 18:35:36 +0100 Subject: [PATCH 2/2] format fix --- clang/lib/CodeGen/CGExprComplex.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index a9b0a15c0383c..fffa2148307b4 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -1491,7 +1491,7 @@ void CodeGenFunction::EmitComplexExprIntoLValue(const Expr *E, LValue dest, "Invalid complex expression to emit"); ComplexExprEmitter Emitter(*this); ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E)); - // The insert point may be empty if we have just emmited a + // The insert point may be empty if we have just emmited a // musttail call. if (HaveInsertPoint()) Emitter.EmitStoreOfComplex(Val, dest, isInit); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits