[llvm] MIPS: Adding a check for JAL argument in PIC mode to prevent crashing on getExpr (PR #120356)
Renat Idrisov via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 19 19:57:28 PST 2024
https://github.com/parsifal-47 updated https://github.com/llvm/llvm-project/pull/120356
>From 0b91fccd81acf1b5a8cd776ec71dd2399a21a464 Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Wed, 18 Dec 2024 04:36:45 +0000
Subject: [PATCH 1/2] Adding a check for JAL argument in PIC mode to prevent
crashing on getExpr
---
llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index ed0f7e657299cd..0ee435c386b4ed 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, "jal needs a symbolic expression in PIC mode");
+ }
+
const MCExpr *JalExpr = Inst.getOperand(0).getExpr();
// We can do this expansion if there's only 1 symbol in the argument
>From ec12ecd1dd938ab1a2b0ca38ec663331f09d5ce3 Mon Sep 17 00:00:00 2001
From: Renat Idrisov <parsifal-47 at users.noreply.github.com>
Date: Fri, 20 Dec 2024 03:57:13 +0000
Subject: [PATCH 2/2] Addressing review feedback
---
llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index 0ee435c386b4ed..ae1f4545c6a498 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -2109,7 +2109,7 @@ bool MipsAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
warnIfNoMacro(IDLoc);
if (!Inst.getOperand(0).isExpr()) {
- return Error(IDLoc, "jal needs a symbolic expression in PIC mode");
+ return Error(IDLoc, "unsupported constant in relocation");
}
const MCExpr *JalExpr = Inst.getOperand(0).getExpr();
More information about the llvm-commits
mailing list