Skip to content

Commit 3311eb4

Browse files
klauslerAlexisPerry
authored andcommitted
[flang] Fix crash due to overly broad assertion (llvm#95809)
Fix llvm#95689 and add a regression test.
1 parent 5b62398 commit 3311eb4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

flang/lib/Parser/prescan.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,9 @@ void Prescanner::Statement() {
185185
// a comment marker or directive sentinel. If so, disable line
186186
// continuation, so that NextToken() won't consume anything from
187187
// following lines.
188-
if (IsLegalIdentifierStart(*at_)) {
189-
CHECK(NextToken(tokens));
190-
CHECK(tokens.SizeInTokens() == 1);
191-
CharBlock id{tokens.TokenAt(0)};
192-
if (preprocessor_.IsNameDefined(id) &&
188+
if (IsLegalIdentifierStart(*at_) && NextToken(tokens) &&
189+
tokens.SizeInTokens() > 0) {
190+
if (CharBlock id{tokens.TokenAt(0)}; preprocessor_.IsNameDefined(id) &&
193191
!preprocessor_.IsFunctionLikeDefinition(id)) {
194192
if (auto replaced{preprocessor_.MacroReplacement(tokens, *this)}) {
195193
auto newLineClass{ClassifyLine(*replaced, GetCurrentProvenance())};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
! RUN: %flang -E %s 2>&1 | FileCheck --strict-whitespace %s
2+
! CHECK: print *, 666
3+
pr&
4+
&i&
5+
&nt *, 666
6+
end

0 commit comments

Comments
 (0)