[clang] [clang][win] MSVC-compat: Use `__global_delete` wrapper in deleting destructors instead of directly referencing `::operator delete` (PR #188372)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 26 07:44:50 PDT 2026
================
@@ -1337,9 +1337,11 @@ static void EmitNewInitializer(CodeGenFunction &CGF, const CXXNewExpr *E,
static RValue EmitNewDeleteCall(CodeGenFunction &CGF,
const FunctionDecl *CalleeDecl,
const FunctionProtoType *CalleeType,
- const CallArgList &Args) {
+ const CallArgList &Args,
+ llvm::Constant *CalleeOverride = nullptr) {
llvm::CallBase *CallOrInvoke;
- llvm::Constant *CalleePtr = CGF.CGM.GetAddrOfFunction(CalleeDecl);
+ llvm::Constant *CalleePtr =
+ CalleeOverride ? CalleeOverride : CGF.CGM.GetAddrOfFunction(CalleeDecl);
----------------
Fznamznon wrote:
CodeGen usually tries to be smart about functions that are emitted in the resulting LLVM IR module. If something is never used and there is no way to use it outside of the current translation unit - it won't be emitted, the simplest example of that case is unused static function.
I was thinking since we always replace the calls to the operator delete with a wrapper call, It may happen that we never see the actual (user defined) operator delete (in my compiler explorer link it is function with `std::type_identity` argument, its mangling name is `??3 at YAXU?$type_identity at UKernelBase@@@std@@PEAX_KW4align_val_t at 1@@Z` in the LLVM IR) in the codegen as something referenced within the TU and therefore it might be missing due to CodeGen being too smart about it.
However in my compiler explorer link I see it emitted even though I never create an object of the class this function intended for and therefore that example is not good.
https://github.com/llvm/llvm-project/pull/188372
More information about the cfe-commits
mailing list