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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 7 deletions
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

Lines changed: 8 additions & 1 deletion
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();

0 commit comments

Comments
 (0)