[llvm] r229671 - [mips] [IAS] Fix using .cpsetup with local labels (PR22518).
Toma Tabacu
toma.tabacu at imgtec.com
Wed Feb 18 05:46:54 PST 2015
Author: tomatabacu
Date: Wed Feb 18 07:46:53 2015
New Revision: 229671
URL: http://llvm.org/viewvc/llvm-project?rev=229671&view=rev
Log:
[mips] [IAS] Fix using .cpsetup with local labels (PR22518).
Summary:
Parse for an MCExpr instead of an Identifier and use the symbol for relocations, not just the symbol's name.
This fixes errors when using local labels in .cpsetup (PR22518).
Reviewers: dsanders
Reviewed By: dsanders
Subscribers: seanbruno, emaste, llvm-commits
Differential Revision: http://reviews.llvm.org/D7697
Modified:
llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
llvm/trunk/test/MC/Mips/cpsetup-bad.s
llvm/trunk/test/MC/Mips/cpsetup.s
Modified: llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp?rev=229671&r1=229670&r2=229671&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp Wed Feb 18 07:46:53 2015
@@ -3781,12 +3781,20 @@ bool MipsAsmParser::parseDirectiveCPSetu
if (!eatComma("unexpected token, expected comma"))
return true;
- StringRef Name;
- if (Parser.parseIdentifier(Name))
- reportParseError("expected identifier");
- MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
+ const MCExpr *Expr;
+ if (Parser.parseExpression(Expr)) {
+ reportParseError("expected expression");
+ return false;
+ }
- getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save, *Sym, SaveIsReg);
+ if (Expr->getKind() != MCExpr::SymbolRef) {
+ reportParseError("expected symbol");
+ return false;
+ }
+ const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr *>(Expr);
+
+ getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save, Ref->getSymbol(),
+ SaveIsReg);
return false;
}
Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp?rev=229671&r1=229670&r2=229671&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp Wed Feb 18 07:46:53 2015
@@ -706,9 +706,10 @@ void MipsTargetELFStreamer::emitDirectiv
Inst.clear();
const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
- Sym.getName(), MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
+ &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
- Sym.getName(), MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
+ &Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
+
// lui $gp, %hi(%neg(%gp_rel(funcSym)))
Inst.setOpcode(Mips::LUi);
Inst.addOperand(MCOperand::CreateReg(Mips::GP));
Modified: llvm/trunk/test/MC/Mips/cpsetup-bad.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/cpsetup-bad.s?rev=229671&r1=229670&r2=229671&view=diff
==============================================================================
--- llvm/trunk/test/MC/Mips/cpsetup-bad.s (original)
+++ llvm/trunk/test/MC/Mips/cpsetup-bad.s Wed Feb 18 07:46:53 2015
@@ -12,3 +12,11 @@ t1:
# ASM: :[[@LINE-1]]:23: error: expected save register or stack offset
.cpsetup $31, $32, __cerror
# ASM: :[[@LINE-1]]:23: error: invalid register
+ .cpsetup $25, $2, $3
+# ASM: :[[@LINE-1]]:28: error: expected expression
+ .cpsetup $25, $2, 4
+# ASM: :[[@LINE-1]]:28: error: expected symbol
+ .cpsetup $25, $2, 4+65
+# ASM: :[[@LINE-1]]:31: error: expected symbol
+ .cpsetup $25, $2, foo+4
+# ASM: :[[@LINE-1]]:32: error: expected symbol
Modified: llvm/trunk/test/MC/Mips/cpsetup.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/cpsetup.s?rev=229671&r1=229670&r2=229671&view=diff
==============================================================================
--- llvm/trunk/test/MC/Mips/cpsetup.s (original)
+++ llvm/trunk/test/MC/Mips/cpsetup.s Wed Feb 18 07:46:53 2015
@@ -6,14 +6,14 @@
# RUN: FileCheck -check-prefix=ASM %s
# RUN: llvm-mc -triple mips64-unknown-unknown -target-abi n32 -filetype=obj -o - %s | \
-# RUN: llvm-objdump -d -r -arch=mips64 - | \
+# RUN: llvm-objdump -d -r -t -arch=mips64 - | \
# RUN: FileCheck -check-prefix=NXX -check-prefix=N32 %s
# RUN: llvm-mc -triple mips64-unknown-unknown -target-abi n32 %s | \
# RUN: FileCheck -check-prefix=ASM %s
# RUN: llvm-mc -triple mips64-unknown-unknown %s -filetype=obj -o - | \
-# RUN: llvm-objdump -d -r -arch=mips64 - | \
+# RUN: llvm-objdump -d -r -t -arch=mips64 - | \
# RUN: FileCheck -check-prefix=NXX -check-prefix=N64 %s
# RUN: llvm-mc -triple mips64-unknown-unknown %s | \
@@ -61,6 +61,35 @@ t2:
# ASM: .cpsetup $25, $2, __cerror
+# .cpsetup with local labels (PR22518):
+1:
+ .cpsetup $25, $2, 1b
+ nop
+ sub $3, $3, $2
+ nop
+
+# O32: t2:
+# O32: nop
+# O32: sub $3, $3, $2
+# O32: nop
+
+# FIXME: Direct object emission for N32 is still under development.
+# N32 doesn't allow 3 operations to be specified in the same relocation
+# record like N64 does.
+
+# NXX: move $2, $gp
+# NXX: lui $gp, 0
+# NXX: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_HI16 $tmp0
+# NXX: addiu $gp, $gp, 0
+# NXX: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_LO16 $tmp0
+# N32: addu $gp, $gp, $25
+# N64: daddu $gp, $gp, $25
+# NXX: nop
+# NXX: sub $3, $3, $2
+# NXX: nop
+
+# ASM: .cpsetup $25, $2, $tmp0
+
t3:
.option pic0
nop
@@ -76,3 +105,7 @@ t3:
# ASM: nop
# ASM: .cpsetup $25, 8, __cerror
# ASM: nop
+
+# For .cpsetup with local labels, we need to check if $tmp0 is in the symbol
+# table:
+# NXX: .text 00000000 $tmp0
More information about the llvm-commits
mailing list