Skip to content

Commit

Permalink
Move some error handling down to MCStreamer.
Browse files Browse the repository at this point in the history
This makes sure we get the same redefinition rules regardless of who
is printing (asm parser, codegen) and to what (asm, obj).

This fixes an unintentional regression in r293936.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294752 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Feb 10, 2017
1 parent e5cabf7 commit 940b0c0
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion include/llvm/MC/MCELFStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MCELFStreamer : public MCObjectStreamer {

void InitSections(bool NoExecStack) override;
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
void EmitLabel(MCSymbol *Symbol) override;
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
void EmitThumbFunc(MCSymbol *Func) override;
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/MC/MCObjectStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class MCObjectStreamer : public MCStreamer {
/// \name MCStreamer Interface
/// @{

void EmitLabel(MCSymbol *Symbol) override;
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
void EmitValueImpl(const MCExpr *Value, unsigned Size,
SMLoc Loc = SMLoc()) override;
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class MCStreamer {
/// used in an assignment.
// FIXME: These emission are non-const because we mutate the symbol to
// add the section we're emitting it to later.
virtual void EmitLabel(MCSymbol *Symbol);
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc());

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

Expand Down
2 changes: 1 addition & 1 deletion include/llvm/MC/MCWinCOFFStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MCWinCOFFStreamer : public MCObjectStreamer {
/// \{

void InitSections(bool NoExecStack) override;
void EmitLabel(MCSymbol *Symbol) override;
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
void EmitThumbFunc(MCSymbol *Func) override;
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
Expand Down
7 changes: 3 additions & 4 deletions lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class MCAsmStreamer final : public MCStreamer {
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;

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

void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
void EmitLinkerOptions(ArrayRef<std::string> Options) override;
Expand Down Expand Up @@ -397,9 +397,8 @@ void MCAsmStreamer::ChangeSection(MCSection *Section,
Subsection);
}

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

Symbol->print(OS, MAI);
OS << MAI->getLabelSuffix();
Expand Down
6 changes: 2 additions & 4 deletions lib/MC/MCELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ void MCELFStreamer::InitSections(bool NoExecStack) {
SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx));
}

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

MCObjectStreamer::EmitLabel(Symbol);
MCObjectStreamer::EmitLabel(Symbol, Loc);

const MCSectionELF &Section =
static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
Expand Down
8 changes: 3 additions & 5 deletions lib/MC/MCMachOStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MCMachOStreamer : public MCObjectStreamer {
/// @{

void ChangeSection(MCSection *Sect, const MCExpr *Subsect) override;
void EmitLabel(MCSymbol *Symbol) override;
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
Expand Down Expand Up @@ -194,15 +194,13 @@ void MCMachOStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
EmitSymbolAttribute(EHSymbol, MCSA_PrivateExtern);
}

void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) {
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");

void MCMachOStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
// We have to create a new fragment if this is an atom defining symbol,
// fragments cannot span atoms.
if (getAssembler().isSymbolLinkerVisible(*Symbol))
insert(new MCDataFragment());

MCObjectStreamer::EmitLabel(Symbol);
MCObjectStreamer::EmitLabel(Symbol, Loc);

// This causes the reference type flag to be cleared. Darwin 'as' was "trying"
// to clear the weak reference and weak definition bits too, but the
Expand Down
4 changes: 2 additions & 2 deletions lib/MC/MCObjectStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
EmitLabel(Frame.End);
}

void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) {
MCStreamer::EmitLabel(Symbol);
void MCObjectStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
MCStreamer::EmitLabel(Symbol, Loc);

getAssembler().registerSymbol(*Symbol);

Expand Down
8 changes: 1 addition & 7 deletions lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,12 +1630,6 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
Sym = getContext().getOrCreateSymbol(IDVal);
} else
Sym = Ctx.createDirectionalLocalSymbol(LocalLabelVal);

Sym->redefineIfPossible();

if (!Sym->isUndefined() || Sym->isVariable())
return Error(IDLoc, "invalid symbol redefinition");

// End of Labels should be treated as end of line for lexing
// purposes but that information is not available to the Lexer who
// does not understand Labels. This may cause us to see a Hash
Expand All @@ -1654,7 +1648,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,

// Emit the label.
if (!ParsingInlineAsm)
Out.EmitLabel(Sym);
Out.EmitLabel(Sym, IDLoc);

// If we are generating dwarf for assembly source files then gather the
// info to make a dwarf label entry for this label if needed.
Expand Down
9 changes: 8 additions & 1 deletion lib/MC/MCStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,17 @@ void MCStreamer::AssignFragment(MCSymbol *Symbol, MCFragment *Fragment) {
SymbolOrdering[Symbol] = 1 + SymbolOrdering.size();
}

void MCStreamer::EmitLabel(MCSymbol *Symbol) {
void MCStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
Symbol->redefineIfPossible();

if (!Symbol->isUndefined() || Symbol->isVariable())
return getContext().reportError(Loc, "invalid symbol redefinition");

assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
assert(getCurrentSectionOnly() && "Cannot emit before setting section!");
assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!");
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");

Symbol->setFragment(&getCurrentSectionOnly()->getDummyFragment());

MCTargetStreamer *TS = getTargetStreamer();
Expand Down
5 changes: 2 additions & 3 deletions lib/MC/WinCOFFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ void MCWinCOFFStreamer::InitSections(bool NoExecStack) {
SwitchSection(getContext().getObjectFileInfo()->getTextSection());
}

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

void MCWinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Object/RecordStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void RecordStreamer::EmitInstruction(const MCInst &Inst,
MCStreamer::EmitInstruction(Inst, STI);
}

void RecordStreamer::EmitLabel(MCSymbol *Symbol) {
void RecordStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
MCStreamer::EmitLabel(Symbol);
markDefined(*Symbol);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Object/RecordStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RecordStreamer : public MCStreamer {
const_iterator end();
RecordStreamer(MCContext &Context);
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
void EmitLabel(MCSymbol *Symbol) override;
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void MipsELFStreamer::createPendingLabelRelocs() {
Labels.clear();
}

void MipsELFStreamer::EmitLabel(MCSymbol *Symbol) {
void MipsELFStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
MCELFStreamer::EmitLabel(Symbol);
Labels.push_back(Symbol);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MipsELFStreamer : public MCELFStreamer {
/// Overriding this function allows us to record all labels that should be
/// marked as microMIPS. Based on this data marking is done in
/// EmitInstruction.
void EmitLabel(MCSymbol *Symbol) override;
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;

/// Overriding this function allows us to dismiss all labels that are
/// candidates for marking as microMIPS when .section directive is processed.
Expand Down
8 changes: 8 additions & 0 deletions test/CodeGen/XCore/section-name.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; RUN: llc < %s -march=xcore

; we used to crash in this.
@bar = internal global i32 zeroinitializer

define void @".dp.bss"() {
ret void
}

0 comments on commit 940b0c0

Please sign in to comment.