From adf5b62e464eab1eb2834138bd0ddf4276738963 Mon Sep 17 00:00:00 2001 From: Aadesh PremKumar Date: Tue, 22 Jul 2025 17:51:01 +0530 Subject: [PATCH] --Fix for issue #127426 --- flang/lib/Parser/prescan.cpp | 7 ++++--- flang/test/Parser/inc.h | 4 ++++ flang/test/Parser/test.F | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 flang/test/Parser/inc.h create mode 100644 flang/test/Parser/test.F 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 badColumn; + SkipCComments(); for (; *at_ != '\n' && column_ <= 6; ++at_) { if (*at_ == '\t') { ++at_; @@ -1218,7 +1219,7 @@ std::optional 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 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