[PATCH] D70953: Allow negative offsets in MipsMCInstLower::LowerOperand

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 04:23:11 PST 2019


arichardson created this revision.
arichardson added a reviewer: atanasyan.
Herald added subscribers: llvm-commits, jrtc27, hiraditya, sdardis.
Herald added a project: LLVM.
arichardson updated this revision to Diff 231869.
arichardson added a comment.
arichardson updated this revision to Diff 231870.

Add missing changes to header


arichardson added a comment.

clang-format


We rely on this in our CHERI backend to address the GOT by generating a
$pc-relative addresses. For this we emit the following code sequence:

lui $1, %pcrel_hi(_CHERI_CAPABILITY_TABLE_-8)
daddiu $1, $1, %pcrel_lo(_CHERI_CAPABILITY_TABLE_-4)
cgetpccincoffset $c1, $1

However, without this change the addend is implicitly converted to
UINT32_MAX and an invalid pointer value is generated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70953

Files:
  llvm/lib/Target/Mips/MipsMCInstLower.cpp
  llvm/lib/Target/Mips/MipsMCInstLower.h


Index: llvm/lib/Target/Mips/MipsMCInstLower.h
===================================================================
--- llvm/lib/Target/Mips/MipsMCInstLower.h
+++ llvm/lib/Target/Mips/MipsMCInstLower.h
@@ -35,11 +35,11 @@
 
   void Initialize(MCContext *C);
   void Lower(const MachineInstr *MI, MCInst &OutMI) const;
-  MCOperand LowerOperand(const MachineOperand& MO, unsigned offset = 0) const;
+  MCOperand LowerOperand(const MachineOperand &MO, int64_t offset = 0) const;
 
 private:
   MCOperand LowerSymbolOperand(const MachineOperand &MO,
-                               MachineOperandType MOTy, unsigned Offset) const;
+                               MachineOperandType MOTy, int64_t Offset) const;
   MCOperand createSub(MachineBasicBlock *BB1, MachineBasicBlock *BB2,
                       MipsMCExpr::MipsExprKind Kind) const;
   void lowerLongBranchLUi(const MachineInstr *MI, MCInst &OutMI) const;
Index: llvm/lib/Target/Mips/MipsMCInstLower.cpp
===================================================================
--- llvm/lib/Target/Mips/MipsMCInstLower.cpp
+++ llvm/lib/Target/Mips/MipsMCInstLower.cpp
@@ -34,7 +34,7 @@
 
 MCOperand MipsMCInstLower::LowerSymbolOperand(const MachineOperand &MO,
                                               MachineOperandType MOTy,
-                                              unsigned Offset) const {
+                                              int64_t Offset) const {
   MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
   MipsMCExpr::MipsExprKind TargetKind = MipsMCExpr::MEK_None;
   bool IsGpOff = false;
@@ -161,9 +161,7 @@
   const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, Kind, *Ctx);
 
   if (Offset) {
-    // Assume offset is never negative.
-    assert(Offset > 0);
-
+    // Note: Offset can also be negative
     Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(Offset, *Ctx),
                                    *Ctx);
   }
@@ -177,7 +175,7 @@
 }
 
 MCOperand MipsMCInstLower::LowerOperand(const MachineOperand &MO,
-                                        unsigned offset) const {
+                                        int64_t offset) const {
   MachineOperandType MOTy = MO.getType();
 
   switch (MOTy) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70953.231870.patch
Type: text/x-patch
Size: 2211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191203/7c0c6f47/attachment.bin>


More information about the llvm-commits mailing list