[flang] Fix crash due to overly broad assertion (#95809)

Fix https://github.com/llvm/llvm-project/issues/95689 and add a
regression test.
This commit is contained in:
Peter Klausler 2024-06-18 12:45:55 -07:00 committed by GitHub
parent ad2905e52c
commit d7b5741ad1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -185,11 +185,9 @@ void Prescanner::Statement() {
// a comment marker or directive sentinel. If so, disable line
// continuation, so that NextToken() won't consume anything from
// following lines.
if (IsLegalIdentifierStart(*at_)) {
CHECK(NextToken(tokens));
CHECK(tokens.SizeInTokens() == 1);
CharBlock id{tokens.TokenAt(0)};
if (preprocessor_.IsNameDefined(id) &&
if (IsLegalIdentifierStart(*at_) && NextToken(tokens) &&
tokens.SizeInTokens() > 0) {
if (CharBlock id{tokens.TokenAt(0)}; preprocessor_.IsNameDefined(id) &&
!preprocessor_.IsFunctionLikeDefinition(id)) {
if (auto replaced{preprocessor_.MacroReplacement(tokens, *this)}) {
auto newLineClass{ClassifyLine(*replaced, GetCurrentProvenance())};

View File

@ -0,0 +1,6 @@
! RUN: %flang -E %s 2>&1 | FileCheck --strict-whitespace %s
! CHECK: print *, 666
pr&
&i&
&nt *, 666
end