Skip to content

[FLANG] Fix for issue #127426 #150008

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 1 commit into
base: main
Choose a base branch
from
Open

Conversation

aadeshps-mcw
Copy link
Contributor

No description provided.

@aadeshps-mcw aadeshps-mcw marked this pull request as draft July 22, 2025 12:22
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:parser labels Jul 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 22, 2025

@llvm/pr-subscribers-flang-parser

Author: Aadesh Premkumar (aadeshps-mcw)

Changes

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

3 Files Affected:

  • (modified) flang/lib/Parser/prescan.cpp (+4-3)
  • (added) flang/test/Parser/inc.h (+4)
  • (added) flang/test/Parser/test.F (+14)
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 3a9a475c365ee..06c9456b203a9 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -175,7 +175,7 @@ void Prescanner::Statement() {
       EmitChar(tokens, '!');
       ++at_, ++column_;
       for (const char *sp{directiveSentinel_}; *sp != '\0';
-           ++sp, ++at_, ++column_) {
+          ++sp, ++at_, ++column_) {
         EmitChar(tokens, *sp);
       }
       if (inFixedForm_) {
@@ -435,6 +435,7 @@ void Prescanner::LabelField(TokenSequence &token) {
   int outCol{1};
   const char *start{at_};
   std::optional<int> badColumn;
+  SkipCComments();
   for (; *at_ != '\n' && column_ <= 6; ++at_) {
     if (*at_ == '\t') {
       ++at_;
@@ -1218,7 +1219,7 @@ std::optional<std::size_t> Prescanner::IsIncludeLine(const char *start) const {
   }
   if (IsDecimalDigit(*p)) { // accept & ignore a numeric kind prefix
     for (p = SkipWhiteSpace(p + 1); IsDecimalDigit(*p);
-         p = SkipWhiteSpace(p + 1)) {
+        p = SkipWhiteSpace(p + 1)) {
     }
     if (*p != '_') {
       return std::nullopt;
@@ -1266,7 +1267,7 @@ void Prescanner::FortranInclude(const char *firstQuote) {
   llvm::raw_string_ostream error{buf};
   Provenance provenance{GetProvenance(nextLine_)};
   std::optional<std::string> prependPath;
-  if (const SourceFile * currentFile{allSources_.GetSourceFile(provenance)}) {
+  if (const SourceFile *currentFile{allSources_.GetSourceFile(provenance)}) {
     prependPath = DirectoryName(currentFile->path());
   }
   const SourceFile *included{
diff --git a/flang/test/Parser/inc.h b/flang/test/Parser/inc.h
new file mode 100644
index 0000000000000..1e31cb035ccf1
--- /dev/null
+++ b/flang/test/Parser/inc.h
@@ -0,0 +1,4 @@
+/* Old-style C comments
+ * Comments
+ */
+#define VAL 1
diff --git a/flang/test/Parser/test.F b/flang/test/Parser/test.F
new file mode 100644
index 0000000000000..c482bc0023b66
--- /dev/null
+++ b/flang/test/Parser/test.F
@@ -0,0 +1,14 @@
+! RUN: %flang_fc1 -fdebug-unparse-no-sema %s 2>&1 | FileCheck %s
+
+! CHECK: SUBROUTINE foo
+! CHECK: INTEGER i
+! CHECK: i = 1
+! CHECK: PRINT *, i
+! CHECK: END SUBROUTINE foo
+
+subroutine foo()
+#include "inc.h"
+  integer :: i
+  i = VAL
+  print *, i
+end subroutine foo

@aadeshps-mcw aadeshps-mcw marked this pull request as ready for review July 22, 2025 14:05
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.

2 participants