Skip to content

Conversation

@akuhlens
Copy link
Contributor

@akuhlens akuhlens commented Jul 2, 2025

TokenSequence::pop_back() had a check assumed that tokens are never empty. Loosen this check since isn't true.

towards #146362

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:parser labels Jul 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 2, 2025

@llvm/pr-subscribers-flang-parser

Author: Andre Kuhlenschmidt (akuhlens)

Changes

TokenSequence::pop_back() had a check assumed that tokens are never empty. Loosen this check since isn't true.


Full diff: https://github.com/llvm/llvm-project/pull/146613.diff

2 Files Affected:

  • (modified) flang/lib/Parser/token-sequence.cpp (+2-1)
  • (added) flang/test/Parser/issue-146362.1.f90 (+5)
diff --git a/flang/lib/Parser/token-sequence.cpp b/flang/lib/Parser/token-sequence.cpp
index 40a074eaf0a47..9deb513e4f64f 100644
--- a/flang/lib/Parser/token-sequence.cpp
+++ b/flang/lib/Parser/token-sequence.cpp
@@ -30,7 +30,8 @@ void TokenSequence::clear() {
 
 void TokenSequence::pop_back() {
   CHECK(!start_.empty());
-  CHECK(nextStart_ > start_.back());
+  // If the last token is empty then `nextStart_ == start_.back()`.
+  CHECK(nextStart_ >= start_.back());
   std::size_t bytes{nextStart_ - start_.back()};
   nextStart_ = start_.back();
   start_.pop_back();
diff --git a/flang/test/Parser/issue-146362.1.f90 b/flang/test/Parser/issue-146362.1.f90
new file mode 100644
index 0000000000000..a37fd4b182a7f
--- /dev/null
+++ b/flang/test/Parser/issue-146362.1.f90
@@ -0,0 +1,5 @@
+! RUN: %flang_fc1 -fsyntax-only -cpp %s 2>&1
+#define UNITY(k) 1_ ## k
+PROGRAM REPRODUCER
+WRITE(*,*) UNITY(4)
+END PROGRAM REPRODUCER
\ No newline at end of file

@akuhlens akuhlens merged commit 67d6679 into llvm:main Jul 3, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:parser flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants