Skip to content

Commit e52c75a

Browse files
committed
Revert "MC: Better handle backslash-escaped symbols (llvm#158780)"
This reverts commit 4847d90.
1 parent 4847d90 commit e52c75a

File tree

12 files changed

+48
-65
lines changed

12 files changed

+48
-65
lines changed

llvm/include/llvm/MC/MCContext.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,6 @@ class MCContext {
489489
/// \param Name - The symbol name, which must be unique across all symbols.
490490
LLVM_ABI MCSymbol *getOrCreateSymbol(const Twine &Name);
491491

492-
/// Variant of getOrCreateSymbol that handles backslash-escaped symbols.
493-
/// For example, parse "a\"b\\" as a"\.
494-
LLVM_ABI MCSymbol *parseSymbol(const Twine &Name);
495-
496492
/// Gets a symbol that will be defined to the final stack offset of a local
497493
/// variable after codegen.
498494
///

llvm/lib/MC/MCContext.cpp

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,27 @@ MCDataFragment *MCContext::allocInitialFragment(MCSection &Sec) {
217217
MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
218218
SmallString<128> NameSV;
219219
StringRef NameRef = Name.toStringRef(NameSV);
220+
if (NameRef.contains('\\')) {
221+
NameSV = NameRef;
222+
size_t S = 0;
223+
// Support escaped \\ and \" as in GNU Assembler. GAS issues a warning for
224+
// other characters following \\, which we do not implement due to code
225+
// structure.
226+
for (size_t I = 0, E = NameSV.size(); I != E; ++I) {
227+
char C = NameSV[I];
228+
if (C == '\\' && I + 1 != E) {
229+
switch (NameSV[I + 1]) {
230+
case '"':
231+
case '\\':
232+
C = NameSV[++I];
233+
break;
234+
}
235+
}
236+
NameSV[S++] = C;
237+
}
238+
NameSV.resize(S);
239+
NameRef = NameSV;
240+
}
220241

221242
assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
222243

@@ -237,34 +258,6 @@ MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
237258
return Entry.second.Symbol;
238259
}
239260

240-
MCSymbol *MCContext::parseSymbol(const Twine &Name) {
241-
SmallString<128> SV;
242-
StringRef NameRef = Name.toStringRef(SV);
243-
if (NameRef.contains('\\')) {
244-
SV = NameRef;
245-
size_t S = 0;
246-
// Support escaped \\ and \" as in GNU Assembler. GAS issues a warning for
247-
// other characters following \\, which we do not implement due to code
248-
// structure.
249-
for (size_t I = 0, E = SV.size(); I != E; ++I) {
250-
char C = SV[I];
251-
if (C == '\\' && I + 1 != E) {
252-
switch (SV[I + 1]) {
253-
case '"':
254-
case '\\':
255-
C = SV[++I];
256-
break;
257-
}
258-
}
259-
SV[S++] = C;
260-
}
261-
SV.resize(S);
262-
NameRef = SV;
263-
}
264-
265-
return getOrCreateSymbol(NameRef);
266-
}
267-
268261
MCSymbol *MCContext::getOrCreateFrameAllocSymbol(const Twine &FuncName,
269262
unsigned Idx) {
270263
return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + FuncName +

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,8 +1222,8 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
12221222

12231223
MCSymbol *Sym = getContext().getInlineAsmLabel(SymbolName);
12241224
if (!Sym)
1225-
Sym = getContext().parseSymbol(MAI.isHLASM() ? SymbolName.upper()
1226-
: SymbolName);
1225+
Sym = getContext().getOrCreateSymbol(MAI.isHLASM() ? SymbolName.upper()
1226+
: SymbolName);
12271227

12281228
// If this is an absolute variable reference, substitute it now to preserve
12291229
// semantics in the face of reassignment.
@@ -1854,7 +1854,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
18541854
RewrittenLabel);
18551855
IDVal = RewrittenLabel;
18561856
}
1857-
Sym = getContext().parseSymbol(IDVal);
1857+
Sym = getContext().getOrCreateSymbol(IDVal);
18581858
} else
18591859
Sym = Ctx.createDirectionalLocalSymbol(LocalLabelVal);
18601860
// End of Labels should be treated as end of line for lexing
@@ -4953,7 +4953,7 @@ bool AsmParser::parseDirectiveSymbolAttribute(MCSymbolAttr Attr) {
49534953
if (discardLTOSymbol(Name))
49544954
return false;
49554955

4956-
MCSymbol *Sym = getContext().parseSymbol(Name);
4956+
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
49574957

49584958
// Assembler local symbols don't make any sense here, except for directives
49594959
// that the symbol should be tagged.
@@ -6213,7 +6213,7 @@ bool HLASMAsmParser::parseAsHLASMLabel(ParseStatementInfo &Info,
62136213
return Error(LabelLoc,
62146214
"Cannot have just a label for an HLASM inline asm statement");
62156215

6216-
MCSymbol *Sym = getContext().parseSymbol(
6216+
MCSymbol *Sym = getContext().getOrCreateSymbol(
62176217
getContext().getAsmInfo()->isHLASM() ? LabelVal.upper() : LabelVal);
62186218

62196219
// Emit the label.
@@ -6340,7 +6340,7 @@ bool parseAssignmentExpression(StringRef Name, bool allow_redef,
63406340
Parser.getStreamer().emitValueToOffset(Value, 0, EqualLoc);
63416341
return false;
63426342
} else
6343-
Sym = Parser.getContext().parseSymbol(Name);
6343+
Sym = Parser.getContext().getOrCreateSymbol(Name);
63446344

63456345
Sym->setRedefinable(allow_redef);
63466346

llvm/lib/MC/MCParser/COFFMasmParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ bool COFFMasmParser::parseDirectiveAlias(StringRef Directive, SMLoc Loc) {
511511
getParser().parseAngleBracketString(ActualName))
512512
return Error(getTok().getLoc(), "expected <actualName>");
513513

514-
MCSymbol *Alias = getContext().parseSymbol(AliasName);
515-
MCSymbol *Actual = getContext().parseSymbol(ActualName);
514+
MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
515+
MCSymbol *Actual = getContext().getOrCreateSymbol(ActualName);
516516

517517
getStreamer().emitWeakReference(Alias, Actual);
518518

llvm/lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ bool ELFAsmParser::parseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
164164
continue;
165165
}
166166

167-
MCSymbol *Sym = getContext().parseSymbol(Name);
167+
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
168168

169169
getStreamer().emitSymbolAttribute(Sym, Attr);
170170

llvm/lib/MC/MCParser/MCAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ bool MCAsmParser::parseSymbol(MCSymbol *&Res) {
168168
if (parseIdentifier(Name))
169169
return true;
170170

171-
Res = getContext().parseSymbol(Name);
171+
Res = getContext().getOrCreateSymbol(Name);
172172
return false;
173173
}
174174

llvm/lib/MC/MCParser/MCAsmParserExtension.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ bool MCAsmParserExtension::parseDirectiveCGProfile(StringRef, SMLoc) {
5050
if (getLexer().isNot(AsmToken::EndOfStatement))
5151
return TokError("unexpected token in directive");
5252

53-
MCSymbol *FromSym = getContext().parseSymbol(From);
54-
MCSymbol *ToSym = getContext().parseSymbol(To);
53+
MCSymbol *FromSym = getContext().getOrCreateSymbol(From);
54+
MCSymbol *ToSym = getContext().getOrCreateSymbol(To);
5555

5656
getStreamer().emitCGProfileEntry(
5757
MCSymbolRefExpr::create(FromSym, getContext(), FromLoc),

llvm/lib/MC/MCParser/MasmParser.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ bool MasmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
14801480
auto VarIt = Variables.find(SymbolName.lower());
14811481
if (VarIt != Variables.end())
14821482
SymbolName = VarIt->second.Name;
1483-
Sym = getContext().parseSymbol(SymbolName);
1483+
Sym = getContext().getOrCreateSymbol(SymbolName);
14841484
}
14851485

14861486
// If this is an absolute variable reference, substitute it now to preserve
@@ -1965,7 +1965,7 @@ bool MasmParser::parseStatement(ParseStatementInfo &Info,
19651965
if (IDVal == "@@") {
19661966
Sym = Ctx.createDirectionalLocalSymbol(0);
19671967
} else {
1968-
Sym = getContext().parseSymbol(IDVal);
1968+
Sym = getContext().getOrCreateSymbol(IDVal);
19691969
}
19701970

19711971
// End of Labels should be treated as end of line for lexing
@@ -3009,7 +3009,8 @@ bool MasmParser::parseDirectiveEquate(StringRef IDVal, StringRef Name,
30093009
return false;
30103010
}
30113011

3012-
auto *Sym = getContext().parseSymbol(Var.Name);
3012+
MCSymbol *Sym = getContext().getOrCreateSymbol(Var.Name);
3013+
30133014
const MCConstantExpr *PrevValue =
30143015
Sym->isVariable()
30153016
? dyn_cast_or_null<MCConstantExpr>(Sym->getVariableValue())
@@ -3317,7 +3318,7 @@ bool MasmParser::parseDirectiveNamedValue(StringRef TypeName, unsigned Size,
33173318
StringRef Name, SMLoc NameLoc) {
33183319
if (StructInProgress.empty()) {
33193320
// Initialize named data value.
3320-
MCSymbol *Sym = getContext().parseSymbol(Name);
3321+
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
33213322
getStreamer().emitLabel(Sym);
33223323
unsigned Count;
33233324
if (emitIntegralValues(Size, &Count))
@@ -3508,7 +3509,7 @@ bool MasmParser::parseDirectiveNamedRealValue(StringRef TypeName,
35083509
SMLoc NameLoc) {
35093510
if (StructInProgress.empty()) {
35103511
// Initialize named data value.
3511-
MCSymbol *Sym = getContext().parseSymbol(Name);
3512+
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
35123513
getStreamer().emitLabel(Sym);
35133514
unsigned Count;
35143515
if (emitRealValues(Semantics, &Count))
@@ -4002,7 +4003,7 @@ bool MasmParser::parseDirectiveNamedStructValue(const StructInfo &Structure,
40024003
SMLoc DirLoc, StringRef Name) {
40034004
if (StructInProgress.empty()) {
40044005
// Initialize named data value.
4005-
MCSymbol *Sym = getContext().parseSymbol(Name);
4006+
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
40064007
getStreamer().emitLabel(Sym);
40074008
unsigned Count;
40084009
if (emitStructValues(Structure, &Count))

llvm/lib/MC/MCParser/WasmAsmParser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ class WasmAsmParser : public MCAsmParserExtension {
240240
if (!Lexer->is(AsmToken::Identifier))
241241
return error("Expected label after .type directive, got: ",
242242
Lexer->getTok());
243-
auto *WasmSym = cast<MCSymbolWasm>(
244-
getStreamer().getContext().parseSymbol(Lexer->getTok().getString()));
243+
auto WasmSym = cast<MCSymbolWasm>(
244+
getStreamer().getContext().getOrCreateSymbol(
245+
Lexer->getTok().getString()));
245246
Lex();
246247
if (!(isNext(AsmToken::Comma) && isNext(AsmToken::At) &&
247248
Lexer->is(AsmToken::Identifier)))

llvm/test/CodeGen/X86/symbol-name.ll

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)