Skip to content

[FLANG] Solved an issue with continuation lines #146027

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

EbinJose2002
Copy link
Contributor

Solved the issue with c style comment appearing between continuation lines
Wrote a test file for it.
Fixes #129455

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

llvmbot commented Jun 27, 2025

@llvm/pr-subscribers-flang-parser

Author: Ebin-McW (EbinJose2002)

Changes

Solved the issue with c style comment appearing between continuation lines
Wrote a test file for it.
Fixes #129455


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

2 Files Affected:

  • (modified) flang/lib/Parser/prescan.cpp (+4)
  • (added) flang/test/Parser/continuation-after-comment.f90 (+15)
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 9aef0c9981e3c..5c92974e3ebf2 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -1455,6 +1455,10 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) {
       return nullptr;
     }
   }
+  if (p[0] == '/' && p[1] == '*') {
+    p = SkipCComment(p);
+    p = SkipWhiteSpaceIncludingEmptyMacros(p);
+  }
   if (p[0] == '!' && p[1] == '$' && !preprocessingOnly_ &&
       features_.IsEnabled(LanguageFeature::OpenMP)) {
     // !$ conditional line can be a continuation
diff --git a/flang/test/Parser/continuation-after-comment.f90 b/flang/test/Parser/continuation-after-comment.f90
new file mode 100644
index 0000000000000..845aa8bc36e5c
--- /dev/null
+++ b/flang/test/Parser/continuation-after-comment.f90
@@ -0,0 +1,15 @@
+! RUN: %flang_fc1 -E %s 2>&1 | FileCheck %s
+
+!Checking comments appearing in between continuation lines.
+integer &
+i(1)
+/* \\\*/
+!CHECK: integer i(1)
+i(1)&
+/* \\\*/
+=1
+!CHECK: i(1) =1
+/* \*/
+if (i(1)/=1)write(6,*)'error',i(1)
+print *,'pass'
+end

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] Preprocessor does not work correctly when C old-style comments immediately precedes a continuation line.
2 participants