[llvm] MC: Support quoted symbol names (PR #138817)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 09:18:54 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;
+ }
----------------
nikic wrote:
Yes, this is a problem. I put up https://github.com/llvm/llvm-project/pull/158106 to put at least some of these uses behind a common API.
A simple option would be to just keep StringRef and have the backing storage in an Allocator. This would avoid API changes and should not really be a performance or memory usage problem as long as quoted symbols are rare.
Though I'm not sure whether all uses of parseIdentifier should parse quoted strings or not.
https://github.com/llvm/llvm-project/pull/138817
More information about the llvm-commits
mailing list