From 72ce310bf0deceea6929eebbfc0d65e799d86ad9 Mon Sep 17 00:00:00 2001 From: Amara Emerson Date: Thu, 7 Oct 2021 23:26:35 -0700 Subject: [PATCH] [GlobalISel][IRTranslator] Fix a use-after-free bug when translating trap-func-name traps. This was using MachineFunction::createExternalSymbolName() before, which seems reasonable, but in fact this is freed before the asm emitter which tries to access the function name string. Switching it to use the string returned by the attribute seems to fix the problem. --- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index 711006df0245..40d58d555d3d 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -2246,8 +2246,7 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID, Info.OrigArgs.push_back({getOrCreateVRegs(*CI.getArgOperand(0)), CI.getArgOperand(0)->getType(), 0}); } - Info.Callee = - MachineOperand::CreateES(MF->createExternalSymbolName(TrapFuncName)); + Info.Callee = MachineOperand::CreateES(TrapFuncName.data()); Info.CB = &CI; Info.OrigRet = {Register(), Type::getVoidTy(CI.getContext()), 0}; return CLI->lowerCall(MIRBuilder, Info);