[flang-commits] [flang] [FLANG] Fix for issue #127426 (PR #150008)
via flang-commits
flang-commits at lists.llvm.org
Tue Jul 22 05:23:09 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-parser
Author: Aadesh Premkumar (aadeshps-mcw)
<details>
<summary>Changes</summary>
---
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/150008
More information about the flang-commits
mailing list