diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h --- a/llvm/include/llvm/MC/MCAsmInfo.h +++ b/llvm/include/llvm/MC/MCAsmInfo.h @@ -196,6 +196,9 @@ /// Defaults to false. bool AllowAtInName = false; + /// This is true if the assembler allows '?' characters in symbol names. + bool AllowQuestionInName = true; + /// This is true if the assembler allows the "?" character at the start of /// of a string to be lexed as an AsmToken::Identifier. /// If the AsmLexer determines that the string can be lexed as a possible @@ -686,6 +689,7 @@ unsigned getAssemblerDialect() const { return AssemblerDialect; } bool doesAllowAtInName() const { return AllowAtInName; } void setAllowAtInName(bool V) { AllowAtInName = V; } + bool doesAllowQuestionInName() const { return AllowQuestionInName; } bool doesAllowQuestionAtStartOfIdentifier() const { return AllowQuestionAtStartOfIdentifier; } diff --git a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h --- a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h +++ b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h @@ -47,6 +47,7 @@ bool SkipSpace = true; bool AllowAtInIdentifier = false; bool AllowHashInIdentifier = false; + bool AllowQuestionInIdentifier = false; bool IsAtStartOfStatement = true; bool LexMasmHexFloats = false; bool LexMasmIntegers = false; diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp --- a/llvm/lib/MC/MCParser/AsmLexer.cpp +++ b/llvm/lib/MC/MCParser/AsmLexer.cpp @@ -33,6 +33,7 @@ AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) { AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@"); + AllowQuestionInIdentifier = MAI.doesAllowQuestionInName(); LexMotorolaIntegers = MAI.shouldUseMotorolaIntegers(); } @@ -145,9 +146,11 @@ } /// LexIdentifier: [a-zA-Z_$.@?][a-zA-Z0-9_$.@#?]* -static bool isIdentifierChar(char C, bool AllowAt, bool AllowHash) { - return isAlnum(C) || C == '_' || C == '$' || C == '.' || C == '?' || - (AllowAt && C == '@') || (AllowHash && C == '#'); +static bool isIdentifierChar(char C, bool AllowAt, bool AllowHash, + bool AllowQuestion) { + return isAlnum(C) || C == '_' || C == '$' || C == '.' || + (AllowAt && C == '@') || (AllowHash && C == '#') || + (AllowQuestion && C == '?'); } AsmToken AsmLexer::LexIdentifier() { @@ -157,13 +160,14 @@ while (isDigit(*CurPtr)) ++CurPtr; - if (!isIdentifierChar(*CurPtr, AllowAtInIdentifier, - AllowHashInIdentifier) || + if (!isIdentifierChar(*CurPtr, AllowAtInIdentifier, AllowHashInIdentifier, + AllowQuestionInIdentifier) || *CurPtr == 'e' || *CurPtr == 'E') return LexFloatLiteral(); } - while (isIdentifierChar(*CurPtr, AllowAtInIdentifier, AllowHashInIdentifier)) + while (isIdentifierChar(*CurPtr, AllowAtInIdentifier, AllowHashInIdentifier, + AllowQuestionInIdentifier)) ++CurPtr; // Handle . as a special case.