[llvm] MC: Support quoted symbol names (PR #138817)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 7 19:18:25 PDT 2025
================
@@ -212,6 +212,27 @@ MCDataFragment *MCContext::allocInitialFragment(MCSection &Sec) {
MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
SmallString<128> NameSV;
StringRef NameRef = Name.toStringRef(NameSV);
+ if (NameRef.contains('\\')) {
+ NameSV = NameRef;
+ size_t S = 0;
+ // Support escaped \\ and \" as in GNU Assembler. GAS issues a warning for
+ // other characters following \\, which we do not implement due to code
+ // structure.
+ for (size_t I = 0, E = NameSV.size(); I < E; ++I) {
+ char C = NameSV[I];
+ if (C == '\\') {
+ switch (NameSV[I + 1]) {
+ case '"':
+ case '\\':
+ C = NameSV[++I];
+ break;
+ }
+ }
+ NameSV[S++] = C;
+ }
+ NameSV.resize(S);
+ NameRef = NameSV;
+ }
----------------
MaskRay wrote:
Sorry, just saw this message. I agree that ideally this should be limited to texual assembly in MC/MCParser/AsmParser.cpp. Unfortunately this is challenging because the wide-used API `AsmParser::parseIdentifier` (used ~107 times) takes a `StringRef` instead of an owned string. It seems a lot of work to fix parseIdentifier...
https://github.com/llvm/llvm-project/pull/138817
More information about the llvm-commits
mailing list