From c1b3f2594d79573f36d123627b92c2ff1fbca27e Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Fri, 24 Nov 2023 17:10:18 +0100 Subject: [PATCH] [cling] Support bare `#` in input line: fixes #11190. --- .../lib/MetaProcessor/InputValidator.cpp | 22 ++++++++++--------- .../cling/lib/MetaProcessor/MetaLexer.cpp | 7 ++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/interpreter/cling/lib/MetaProcessor/InputValidator.cpp b/interpreter/cling/lib/MetaProcessor/InputValidator.cpp index 9c0dba3aaea25c..e6543ca3649503 100644 --- a/interpreter/cling/lib/MetaProcessor/InputValidator.cpp +++ b/interpreter/cling/lib/MetaProcessor/InputValidator.cpp @@ -82,17 +82,19 @@ namespace cling { case tok::hash: Lex.SkipWhitespace(); Lex.LexAnyString(Tok); - const llvm::StringRef PPtk = Tok.getIdent(); - if (PPtk.startswith("if")) { - m_ParenStack.push_back(tok::hash); - } else if (PPtk.startswith("endif") && - (PPtk.size() == 5 || PPtk[5]=='/' || isspace(PPtk[5]))) { - if (m_ParenStack.empty() || m_ParenStack.back() != tok::hash) - Res = kMismatch; - else - m_ParenStack.pop_back(); + if (Tok.isNot(tok::eof)) { + const llvm::StringRef PPtk = Tok.getIdent(); + if (PPtk.startswith("if")) { + m_ParenStack.push_back(tok::hash); + } else if (PPtk.startswith("endif") && + (PPtk.size() == 5 || PPtk[5]=='/' || isspace(PPtk[5]))) { + if (m_ParenStack.empty() || m_ParenStack.back() != tok::hash) + Res = kMismatch; + else + m_ParenStack.pop_back(); + } + break; } - break; } } while (Tok.isNot(tok::eof) && Res != kMismatch); diff --git a/interpreter/cling/lib/MetaProcessor/MetaLexer.cpp b/interpreter/cling/lib/MetaProcessor/MetaLexer.cpp index 03c1bc08e14fdc..5fcc80133b77e3 100644 --- a/interpreter/cling/lib/MetaProcessor/MetaLexer.cpp +++ b/interpreter/cling/lib/MetaProcessor/MetaLexer.cpp @@ -102,6 +102,13 @@ namespace cling { void MetaLexer::LexAnyString(Token& Tok) { Tok.startToken(curPos); // consume until we reach one of the "AnyString" delimiters or EOF. + if (*curPos == '\0') { + Tok.setBufStart(curPos); + Tok.setKind(tok::eof); + Tok.setLength(0); + return; + } + while(*curPos != ' ' && *curPos != '\t' && *curPos != '\0') { curPos++; }