[llvm] 72ce310 - [GlobalISel][IRTranslator] Fix a use-after-free bug when translating trap-func-name traps.

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 7 23:51:44 PDT 2021


Author: Amara Emerson
Date: 2021-10-07T23:51:37-07:00
New Revision: 72ce310bf0deceea6929eebbfc0d65e799d86ad9

URL: https://github.com/llvm/llvm-project/commit/72ce310bf0deceea6929eebbfc0d65e799d86ad9
DIFF: https://github.com/llvm/llvm-project/commit/72ce310bf0deceea6929eebbfc0d65e799d86ad9.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Removed: 
    


################################################################################
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);


        


More information about the llvm-commits mailing list