Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit d9e7d26

Browse files
authored
Merge pull request #91 from pftbest/fix_asm
Move some error handling down to MCStreamer.
2 parents a5ef069 + 7cecd9e commit d9e7d26

16 files changed

+37
-34
lines changed

include/llvm/MC/MCELFStreamer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MCELFStreamer : public MCObjectStreamer {
4444

4545
void InitSections(bool NoExecStack) override;
4646
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
47-
void EmitLabel(MCSymbol *Symbol) override;
47+
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
4848
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
4949
void EmitThumbFunc(MCSymbol *Func) override;
5050
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;

include/llvm/MC/MCObjectStreamer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class MCObjectStreamer : public MCStreamer {
8989
/// \name MCStreamer Interface
9090
/// @{
9191

92-
void EmitLabel(MCSymbol *Symbol) override;
92+
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
9393
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
9494
void EmitValueImpl(const MCExpr *Value, unsigned Size,
9595
SMLoc Loc = SMLoc()) override;

include/llvm/MC/MCStreamer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class MCStreamer {
393393
/// used in an assignment.
394394
// FIXME: These emission are non-const because we mutate the symbol to
395395
// add the section we're emitting it to later.
396-
virtual void EmitLabel(MCSymbol *Symbol);
396+
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc());
397397

398398
virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
399399

include/llvm/MC/MCWinCOFFStreamer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MCWinCOFFStreamer : public MCObjectStreamer {
4141
/// \{
4242

4343
void InitSections(bool NoExecStack) override;
44-
void EmitLabel(MCSymbol *Symbol) override;
44+
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
4545
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
4646
void EmitThumbFunc(MCSymbol *Func) override;
4747
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;

lib/MC/MCAsmStreamer.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class MCAsmStreamer final : public MCStreamer {
130130
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
131131

132132
void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override;
133-
void EmitLabel(MCSymbol *Symbol) override;
133+
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
134134

135135
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
136136
void EmitLinkerOptions(ArrayRef<std::string> Options) override;
@@ -395,9 +395,8 @@ void MCAsmStreamer::ChangeSection(MCSection *Section,
395395
Section->PrintSwitchToSection(*MAI, OS, Subsection);
396396
}
397397

398-
void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
399-
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
400-
MCStreamer::EmitLabel(Symbol);
398+
void MCAsmStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
399+
MCStreamer::EmitLabel(Symbol, Loc);
401400

402401
Symbol->print(OS, MAI);
403402
OS << MAI->getLabelSuffix();

lib/MC/MCELFStreamer.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ void MCELFStreamer::InitSections(bool NoExecStack) {
9595
SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx));
9696
}
9797

98-
void MCELFStreamer::EmitLabel(MCSymbol *S) {
98+
void MCELFStreamer::EmitLabel(MCSymbol *S, SMLoc Loc) {
9999
auto *Symbol = cast<MCSymbolELF>(S);
100-
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
101-
102-
MCObjectStreamer::EmitLabel(Symbol);
100+
MCObjectStreamer::EmitLabel(Symbol, Loc);
103101

104102
const MCSectionELF &Section =
105103
static_cast<const MCSectionELF &>(*getCurrentSectionOnly());

lib/MC/MCMachOStreamer.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class MCMachOStreamer : public MCObjectStreamer {
7070
/// @{
7171

7272
void ChangeSection(MCSection *Sect, const MCExpr *Subsect) override;
73-
void EmitLabel(MCSymbol *Symbol) override;
73+
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
7474
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
7575
void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
7676
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
@@ -181,15 +181,13 @@ void MCMachOStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
181181
EmitSymbolAttribute(EHSymbol, MCSA_PrivateExtern);
182182
}
183183

184-
void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) {
185-
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
186-
184+
void MCMachOStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
187185
// We have to create a new fragment if this is an atom defining symbol,
188186
// fragments cannot span atoms.
189187
if (getAssembler().isSymbolLinkerVisible(*Symbol))
190188
insert(new MCDataFragment());
191189

192-
MCObjectStreamer::EmitLabel(Symbol);
190+
MCObjectStreamer::EmitLabel(Symbol, Loc);
193191

194192
// This causes the reference type flag to be cleared. Darwin 'as' was "trying"
195193
// to clear the weak reference and weak definition bits too, but the

lib/MC/MCObjectStreamer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
153153
EmitLabel(Frame.End);
154154
}
155155

156-
void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) {
157-
MCStreamer::EmitLabel(Symbol);
156+
void MCObjectStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
157+
MCStreamer::EmitLabel(Symbol, Loc);
158158

159159
getAssembler().registerSymbol(*Symbol);
160160

lib/MC/MCParser/AsmParser.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -1626,12 +1626,6 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
16261626
Sym = getContext().getOrCreateSymbol(IDVal);
16271627
} else
16281628
Sym = Ctx.createDirectionalLocalSymbol(LocalLabelVal);
1629-
1630-
Sym->redefineIfPossible();
1631-
1632-
if (!Sym->isUndefined() || Sym->isVariable())
1633-
return Error(IDLoc, "invalid symbol redefinition");
1634-
16351629
// End of Labels should be treated as end of line for lexing
16361630
// purposes but that information is not available to the Lexer who
16371631
// does not understand Labels. This may cause us to see a Hash
@@ -1650,7 +1644,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
16501644

16511645
// Emit the label.
16521646
if (!ParsingInlineAsm)
1653-
Out.EmitLabel(Sym);
1647+
Out.EmitLabel(Sym, IDLoc);
16541648

16551649
// If we are generating dwarf for assembly source files then gather the
16561650
// info to make a dwarf label entry for this label if needed.

lib/MC/MCStreamer.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,17 @@ void MCStreamer::AssignFragment(MCSymbol *Symbol, MCFragment *Fragment) {
290290
SymbolOrdering[Symbol] = 1 + SymbolOrdering.size();
291291
}
292292

293-
void MCStreamer::EmitLabel(MCSymbol *Symbol) {
293+
void MCStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
294+
Symbol->redefineIfPossible();
295+
296+
if (!Symbol->isUndefined() || Symbol->isVariable())
297+
return getContext().reportError(Loc, "invalid symbol redefinition");
298+
294299
assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
295300
assert(getCurrentSectionOnly() && "Cannot emit before setting section!");
296301
assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!");
302+
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
303+
297304
Symbol->setFragment(&getCurrentSectionOnly()->getDummyFragment());
298305

299306
MCTargetStreamer *TS = getTargetStreamer();

lib/MC/WinCOFFStreamer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ void MCWinCOFFStreamer::InitSections(bool NoExecStack) {
7575
SwitchSection(getContext().getObjectFileInfo()->getTextSection());
7676
}
7777

78-
void MCWinCOFFStreamer::EmitLabel(MCSymbol *S) {
78+
void MCWinCOFFStreamer::EmitLabel(MCSymbol *S, SMLoc Loc) {
7979
auto *Symbol = cast<MCSymbolCOFF>(S);
80-
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
81-
MCObjectStreamer::EmitLabel(Symbol);
80+
MCObjectStreamer::EmitLabel(Symbol, Loc);
8281
}
8382

8483
void MCWinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {

lib/Object/RecordStreamer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void RecordStreamer::EmitInstruction(const MCInst &Inst,
8282
MCStreamer::EmitInstruction(Inst, STI);
8383
}
8484

85-
void RecordStreamer::EmitLabel(MCSymbol *Symbol) {
85+
void RecordStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
8686
MCStreamer::EmitLabel(Symbol);
8787
markDefined(*Symbol);
8888
}

lib/Object/RecordStreamer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RecordStreamer : public MCStreamer {
3131
const_iterator end();
3232
RecordStreamer(MCContext &Context);
3333
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
34-
void EmitLabel(MCSymbol *Symbol) override;
34+
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
3535
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
3636
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
3737
void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,

lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void MipsELFStreamer::createPendingLabelRelocs() {
5151
Labels.clear();
5252
}
5353

54-
void MipsELFStreamer::EmitLabel(MCSymbol *Symbol) {
54+
void MipsELFStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
5555
MCELFStreamer::EmitLabel(Symbol);
5656
Labels.push_back(Symbol);
5757
}

lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class MipsELFStreamer : public MCELFStreamer {
5151
/// Overriding this function allows us to record all labels that should be
5252
/// marked as microMIPS. Based on this data marking is done in
5353
/// EmitInstruction.
54-
void EmitLabel(MCSymbol *Symbol) override;
54+
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
5555

5656
/// Overriding this function allows us to dismiss all labels that are
5757
/// candidates for marking as microMIPS when .section directive is processed.

test/CodeGen/XCore/section-name.ll

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: llc < %s -march=xcore
2+
3+
; we used to crash in this.
4+
@bar = internal global i32 zeroinitializer
5+
6+
define void @".dp.bss"() {
7+
ret void
8+
}

0 commit comments

Comments
 (0)