Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2024
Merged

Conversation

klausler
Copy link
Contributor

Fix #95689 and add a regression test.

@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2024

@llvm/pr-subscribers-flang-parser

Author: Peter Klausler (klausler)

Changes

Fix #95689 and add a regression test.


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

2 Files Affected:

  • (modified) flang/lib/Parser/prescan.cpp (+3-5)
  • (added) flang/test/Preprocessing/multi-cont.F90 (+6)
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 8efcd617cf0f9..2a6ecfbb0830e 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -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())};
diff --git a/flang/test/Preprocessing/multi-cont.F90 b/flang/test/Preprocessing/multi-cont.F90
new file mode 100644
index 0000000000000..5a2c0b9c47976
--- /dev/null
+++ b/flang/test/Preprocessing/multi-cont.F90
@@ -0,0 +1,6 @@
+! RUN: %flang -E %s 2>&1 | FileCheck --strict-whitespace %s
+! CHECK:      print *, 666
+pr&
+&i&
+&nt *, 666
+end

Copy link
Contributor

@psteinfeld psteinfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All builds and tests correctly and looks good.

@klausler klausler merged commit d7b5741 into llvm:main Jun 18, 2024
10 checks passed
@klausler klausler deleted the bug95689 branch June 18, 2024 19:45
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
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.

[Flang] fatal internal error: CHECK(tokens.SizeInTokens() == 1) failed at /root/llvm-project/flang/lib/Parser/prescan.cpp(190)
3 participants