[llvm] dd48c57 - [Mips] Error if a non-immediate operand is used while an immediate is expected
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 19 22:09:10 PDT 2020
Author: Wang Rui
Date: 2020-06-19T22:08:59-07:00
New Revision: dd48c57da35e069c739361ce822b98c6e42f555e
URL: https://github.com/llvm/llvm-project/commit/dd48c57da35e069c739361ce822b98c6e42f555e
DIFF: https://github.com/llvm/llvm-project/commit/dd48c57da35e069c739361ce822b98c6e42f555e.diff
LOG: [Mips] Error if a non-immediate operand is used while an immediate is expected
The 32-bit type relocation (R_MIPS_32) cannot be used for instructions below:
ori $4, $4, start
ori $4, $4, (start - .)
We should print an error instead.
Reviewed By: atanasyan, MaskRay
Differential Revision: https://reviews.llvm.org/D81908
Added:
llvm/test/MC/Mips/imm-operand-err.s
Modified:
llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
index c483dc46a34f..9de34cc0e787 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
@@ -723,21 +723,8 @@ getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
return 0;
}
- if (Kind == MCExpr::SymbolRef) {
- Mips::Fixups FixupKind = Mips::Fixups(0);
-
- switch(cast<MCSymbolRefExpr>(Expr)->getKind()) {
- default: llvm_unreachable("Unknown fixup kind!");
- break;
- case MCSymbolRefExpr::VK_None:
- // FIXME: This is ok for O32/N32 but not N64.
- FixupKind = Mips::fixup_Mips_32;
- break;
- } // switch
-
- Fixups.push_back(MCFixup::create(0, Expr, MCFixupKind(FixupKind)));
- return 0;
- }
+ if (Kind == MCExpr::SymbolRef)
+ Ctx.reportError(Expr->getLoc(), "expected an immediate");
return 0;
}
diff --git a/llvm/test/MC/Mips/imm-operand-err.s b/llvm/test/MC/Mips/imm-operand-err.s
new file mode 100644
index 000000000000..8ded4a21b480
--- /dev/null
+++ b/llvm/test/MC/Mips/imm-operand-err.s
@@ -0,0 +1,15 @@
+## Print an error if a non-immediate operand is used while an immediate is expected
+# RUN: not llvm-mc -filetype=obj -triple=mips -o /dev/null %s 2>&1 | FileCheck %s
+# RUN: not llvm-mc -filetype=obj -triple=mips64 -o /dev/null %s 2>&1 | FileCheck %s
+
+# CHECK: [[#@LINE+1]]:16: error: expected an immediate
+ ori $4, $4, start
+# CHECK: [[#@LINE+1]]:17: error: expected an immediate
+ ori $4, $4, (start - .)
+
+# CHECK: [[#@LINE+1]]:18: error: expected an immediate
+ addiu $4, $4, start
+# CHECK: [[#@LINE+1]]:19: error: expected an immediate
+ addiu $4, $4, (start - .)
+
+start:
More information about the llvm-commits
mailing list