[llvm] 85a7989 - MIPS: Adding a check for JAL argument in PIC mode to prevent crashing on getExpr (#120356)

via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 22 18:24:41 PST 2024


Author: Renat Idrisov
Date: 2024-12-23T10:24:37+08:00
New Revision: 85a7989770136c8bcecffff960862045fbdb2161

URL: https://github.com/llvm/llvm-project/commit/85a7989770136c8bcecffff960862045fbdb2161
DIFF: https://github.com/llvm/llvm-project/commit/85a7989770136c8bcecffff960862045fbdb2161.diff

LOG: MIPS: Adding a check for JAL argument in PIC mode to prevent crashing on getExpr (#120356)

Only an Expr is supported by JAL.
Let's check it before getExpr.
https://github.com/llvm/llvm-project/issues/80535

---------

Co-authored-by: Renat Idrisov <parsifal-47 at users.noreply.github.com>

Added: 
    

Modified: 
    llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index ed0f7e657299cd..ae1f4545c6a498 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -2108,6 +2108,10 @@ bool MipsAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
   if ((Opcode == Mips::JAL || Opcode == Mips::JAL_MM) && inPicMode()) {
     warnIfNoMacro(IDLoc);
 
+    if (!Inst.getOperand(0).isExpr()) {
+      return Error(IDLoc, "unsupported constant in relocation");
+    }
+
     const MCExpr *JalExpr = Inst.getOperand(0).getExpr();
 
     // We can do this expansion if there's only 1 symbol in the argument


        


More information about the llvm-commits mailing list