Skip to content

Commit 8874eac

Browse files
author
Toma Tabacu
committedFeb 18, 2015
[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 llvm-svn: 229671
1 parent bbb377c commit 8874eac

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed
 

‎llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -3781,12 +3781,20 @@ bool MipsAsmParser::parseDirectiveCPSetup() {
37813781
if (!eatComma("unexpected token, expected comma"))
37823782
return true;
37833783

3784-
StringRef Name;
3785-
if (Parser.parseIdentifier(Name))
3786-
reportParseError("expected identifier");
3787-
MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
3784+
const MCExpr *Expr;
3785+
if (Parser.parseExpression(Expr)) {
3786+
reportParseError("expected expression");
3787+
return false;
3788+
}
3789+
3790+
if (Expr->getKind() != MCExpr::SymbolRef) {
3791+
reportParseError("expected symbol");
3792+
return false;
3793+
}
3794+
const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr *>(Expr);
37883795

3789-
getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save, *Sym, SaveIsReg);
3796+
getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save, Ref->getSymbol(),
3797+
SaveIsReg);
37903798
return false;
37913799
}
37923800

‎llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,10 @@ void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
706706
Inst.clear();
707707

708708
const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
709-
Sym.getName(), MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
709+
&Sym, MCSymbolRefExpr::VK_Mips_GPOFF_HI, MCA.getContext());
710710
const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
711-
Sym.getName(), MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
711+
&Sym, MCSymbolRefExpr::VK_Mips_GPOFF_LO, MCA.getContext());
712+
712713
// lui $gp, %hi(%neg(%gp_rel(funcSym)))
713714
Inst.setOpcode(Mips::LUi);
714715
Inst.addOperand(MCOperand::CreateReg(Mips::GP));

‎llvm/test/MC/Mips/cpsetup-bad.s

+8
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ t1:
1212
# ASM: :[[@LINE-1]]:23: error: expected save register or stack offset
1313
.cpsetup $31, $32, __cerror
1414
# ASM: :[[@LINE-1]]:23: error: invalid register
15+
.cpsetup $25, $2, $3
16+
# ASM: :[[@LINE-1]]:28: error: expected expression
17+
.cpsetup $25, $2, 4
18+
# ASM: :[[@LINE-1]]:28: error: expected symbol
19+
.cpsetup $25, $2, 4+65
20+
# ASM: :[[@LINE-1]]:31: error: expected symbol
21+
.cpsetup $25, $2, foo+4
22+
# ASM: :[[@LINE-1]]:32: error: expected symbol

‎llvm/test/MC/Mips/cpsetup.s

+35-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
# RUN: FileCheck -check-prefix=ASM %s
77

88
# RUN: llvm-mc -triple mips64-unknown-unknown -target-abi n32 -filetype=obj -o - %s | \
9-
# RUN: llvm-objdump -d -r -arch=mips64 - | \
9+
# RUN: llvm-objdump -d -r -t -arch=mips64 - | \
1010
# RUN: FileCheck -check-prefix=NXX -check-prefix=N32 %s
1111

1212
# RUN: llvm-mc -triple mips64-unknown-unknown -target-abi n32 %s | \
1313
# RUN: FileCheck -check-prefix=ASM %s
1414

1515
# RUN: llvm-mc -triple mips64-unknown-unknown %s -filetype=obj -o - | \
16-
# RUN: llvm-objdump -d -r -arch=mips64 - | \
16+
# RUN: llvm-objdump -d -r -t -arch=mips64 - | \
1717
# RUN: FileCheck -check-prefix=NXX -check-prefix=N64 %s
1818

1919
# RUN: llvm-mc -triple mips64-unknown-unknown %s | \
@@ -61,6 +61,35 @@ t2:
6161

6262
# ASM: .cpsetup $25, $2, __cerror
6363

64+
# .cpsetup with local labels (PR22518):
65+
1:
66+
.cpsetup $25, $2, 1b
67+
nop
68+
sub $3, $3, $2
69+
nop
70+
71+
# O32: t2:
72+
# O32: nop
73+
# O32: sub $3, $3, $2
74+
# O32: nop
75+
76+
# FIXME: Direct object emission for N32 is still under development.
77+
# N32 doesn't allow 3 operations to be specified in the same relocation
78+
# record like N64 does.
79+
80+
# NXX: move $2, $gp
81+
# NXX: lui $gp, 0
82+
# NXX: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_HI16 $tmp0
83+
# NXX: addiu $gp, $gp, 0
84+
# NXX: R_MIPS_GPREL16/R_MIPS_SUB/R_MIPS_LO16 $tmp0
85+
# N32: addu $gp, $gp, $25
86+
# N64: daddu $gp, $gp, $25
87+
# NXX: nop
88+
# NXX: sub $3, $3, $2
89+
# NXX: nop
90+
91+
# ASM: .cpsetup $25, $2, $tmp0
92+
6493
t3:
6594
.option pic0
6695
nop
@@ -76,3 +105,7 @@ t3:
76105
# ASM: nop
77106
# ASM: .cpsetup $25, 8, __cerror
78107
# ASM: nop
108+
109+
# For .cpsetup with local labels, we need to check if $tmp0 is in the symbol
110+
# table:
111+
# NXX: .text 00000000 $tmp0

0 commit comments

Comments
 (0)