[flang-commits] [flang] b4f9012 - [flang] Make a non-digit in fixed-form label field an error unless -E (#174836)
via flang-commits
flang-commits at lists.llvm.org
Thu Jan 8 08:58:49 PST 2026
Author: Peter Klausler
Date: 2026-01-08T08:58:45-08:00
New Revision: b4f9012464144fc0f5c430dd97736c4e868a5de3
URL: https://github.com/llvm/llvm-project/commit/b4f9012464144fc0f5c430dd97736c4e868a5de3
DIFF: https://github.com/llvm/llvm-project/commit/b4f9012464144fc0f5c430dd97736c4e868a5de3.diff
LOG: [flang] Make a non-digit in fixed-form label field an error unless -E (#174836)
A character in a fixed-form source line (as opposed to a comment or
compiler directive) can't have a non-digit in its label field, columns 1
through 5. The prescanner presently emits only a warning for this case.
Retain the warning for -E output, but otherwise diagnose an error.
(This change affected a number of tests that relied on this situation
being a warning just so that they could test prescanner warnings, and
those tests were adjusted to use another warning.)
Fixes https://github.com/llvm/llvm-project/issues/50563.
Added:
flang/test/Parser/bug50563.f
Modified:
flang/lib/Parser/prescan.cpp
flang/lib/Parser/prescan.h
flang/test/Driver/Inputs/free-form-test.f90
flang/test/Driver/color-diagnostics-scan.f
flang/test/Driver/fixed-free-detection.f90
flang/test/Driver/fixed-free-flag.f90
flang/test/Driver/werror-scan.f
flang/test/Parser/badlabel.f
flang/test/Preprocessing/pp039.F
Removed:
################################################################################
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 5e8d50be277a0..bcd23873b99c7 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -443,21 +443,31 @@ void Prescanner::LabelField(TokenSequence &token) {
++column_;
}
if (badColumn && !preprocessor_.IsNameDefined(token.CurrentOpenToken())) {
- if ((prescannerNesting_ > 0 && *badColumn == 6 &&
- cooked_.BufferedBytes() == firstCookedCharacterOffset_) ||
- afterPreprocessingDirective_) {
- // This is the first source line in #include'd text or conditional
- // code under #if, or the first source line after such.
- // If it turns out that the preprocessed text begins with a
- // fixed form continuation line, the newline at the end
- // of the latest source line beforehand will be deleted in
- // CookedSource::Marshal().
- cooked_.MarkPossibleFixedFormContinuation();
- } else if (features_.ShouldWarn(common::UsageWarning::Scanning)) {
- Say(common::UsageWarning::Scanning, GetProvenance(start + *badColumn - 1),
- *badColumn == 6
- ? "Statement should not begin with a continuation line"_warn_en_US
- : "Character in fixed-form label field must be a digit"_warn_en_US);
+ if (*badColumn == 6) {
+ if ((prescannerNesting_ > 0 &&
+ cooked_.BufferedBytes() == firstCookedCharacterOffset_) ||
+ afterPreprocessingDirective_) {
+ // This is the first source line in #include'd text or conditional
+ // code under #if, or the first source line after such.
+ // If it turns out that the preprocessed text begins with a
+ // fixed form continuation line, the newline at the end
+ // of the latest source line beforehand will be deleted in
+ // CookedSource::Marshal().
+ cooked_.MarkPossibleFixedFormContinuation();
+ } else if (features_.ShouldWarn(common::UsageWarning::Scanning)) {
+ Say(common::UsageWarning::Scanning,
+ GetProvenance(start + *badColumn - 1),
+ "Statement should not begin with a continuation line"_warn_en_US);
+ }
+ } else if (preprocessingOnly_) {
+ if (features_.ShouldWarn(common::UsageWarning::Scanning)) {
+ Say(common::UsageWarning::Scanning,
+ GetProvenance(start + *badColumn - 1),
+ "Character in fixed-form label field should be a digit"_warn_en_US);
+ }
+ } else {
+ Say(GetProvenance(start + *badColumn - 1),
+ "Character in fixed-form label field must be a digit"_err_en_US);
}
token.clear();
if (*badColumn < 6) {
@@ -467,7 +477,7 @@ void Prescanner::LabelField(TokenSequence &token) {
}
outCol = 1;
}
- if (outCol == 1) { // empty label field
+ if (outCol == 1) { // empty or ignored label field
// Emit a space so that, if the line is rescanned after preprocessing,
// a leading 'C' or 'D' won't be left-justified and then accidentally
// misinterpreted as a comment card.
diff --git a/flang/lib/Parser/prescan.h b/flang/lib/Parser/prescan.h
index 4f691d56975a9..efbeb3709a94c 100644
--- a/flang/lib/Parser/prescan.h
+++ b/flang/lib/Parser/prescan.h
@@ -90,7 +90,6 @@ class Prescanner {
template <typename... A> Message &Say(A &&...a) {
return messages_.Say(std::forward<A>(a)...);
}
-
template <typename... A>
Message *Warn(common::UsageWarning warning, A &&...a) {
return messages_.Warn(false, features_, warning, std::forward<A>(a)...);
diff --git a/flang/test/Driver/Inputs/free-form-test.f90 b/flang/test/Driver/Inputs/free-form-test.f90
index 7933954f38ef0..6aba8346a6f9c 100644
--- a/flang/test/Driver/Inputs/free-form-test.f90
+++ b/flang/test/Driver/Inputs/free-form-test.f90
@@ -1,2 +1,2 @@
-program FreeForm
-end
+ xy z=1
+ end
diff --git a/flang/test/Driver/color-diagnostics-scan.f b/flang/test/Driver/color-diagnostics-scan.f
index 1c02e732f9537..4554867438181 100644
--- a/flang/test/Driver/color-diagnostics-scan.f
+++ b/flang/test/Driver/color-diagnostics-scan.f
@@ -22,9 +22,9 @@
! RUN: not %flang_fc1 -E -Werror %s 2>&1 | FileCheck %s --check-prefix=CHECK_NCD
-! CHECK_CD: {{.*}}[0;1;35mwarning: {{.*}}[0mCharacter in fixed-form label field must be a digit
+! CHECK_CD: {{.*}}[0;1;35mwarning: {{.*}}[0mStatement should not begin with a continuation line
-! CHECK_NCD: warning: Character in fixed-form label field must be a digit
+! CHECK_NCD: warning: Statement should not begin with a continuation line
-1 continue
-end
+ +continue
+ end
diff --git a/flang/test/Driver/fixed-free-detection.f90 b/flang/test/Driver/fixed-free-detection.f90
index c2deef73f39a0..2ac469d05e1b7 100644
--- a/flang/test/Driver/fixed-free-detection.f90
+++ b/flang/test/Driver/fixed-free-detection.f90
@@ -16,14 +16,14 @@
! RUN: %flang_fc1 -E -fno-reformat %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXEDFORM
! RUN: %flang_fc1 -E -fno-reformat %S/Inputs/free-form-test.f90 %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=MULTIPLEFORMS
-! FREEFORM:program freeform
-! FREEFORM-NOT:programfixedform
+! FREEFORM:y z=1
+! FREEFORM-NOT:yz=1
! FIXEDFORM:programfixedform
! FIXEDFORM-NOT:program freeform
-! MULTIPLEFORMS:program freeform
-! MULTIPLEFORMS-NOT:programfixedform
+! MULTIPLEFORMS:xy z=1
+! MULTIPLEFORMS-NOT:xyz=1
! MULTIPLEFORMS-NEXT:end
! MULTIPLEFORMS-NEXT:programfixedform
! MULTIPLEFORMS-NOT:program freeform
diff --git a/flang/test/Driver/fixed-free-flag.f90 b/flang/test/Driver/fixed-free-flag.f90
index 454d642114d31..acdb7e5a1520d 100644
--- a/flang/test/Driver/fixed-free-flag.f90
+++ b/flang/test/Driver/fixed-free-flag.f90
@@ -14,4 +14,4 @@
! FREEFORM: Could not parse
-! FIXEDFORM:free-form-test.f90:1:1: warning: Character in fixed-form label field must be a digit
+! FIXEDFORM:free-form-test.f90:1:6: warning: Statement should not begin with a continuation line [-Wscanning]
diff --git a/flang/test/Driver/werror-scan.f b/flang/test/Driver/werror-scan.f
index b28169b0c2b95..5685b5c165679 100644
--- a/flang/test/Driver/werror-scan.f
+++ b/flang/test/Driver/werror-scan.f
@@ -15,5 +15,5 @@
! WITHOUT-NOT: Could not scan
-1 continue
-end
+ +continue
+ end
diff --git a/flang/test/Parser/badlabel.f b/flang/test/Parser/badlabel.f
index 7842803dadd04..8431fd3467775 100644
--- a/flang/test/Parser/badlabel.f
+++ b/flang/test/Parser/badlabel.f
@@ -6,9 +6,7 @@
! CHECK-NOT: Label is not in fixed-form label field
con
3 tinue
-! CHECK: Character in fixed-form label field must be a digit
-end
+ end
! CHECK: 1continue
! CHECK: 12continue
-! CHECK: continue
! CHECK: end
diff --git a/flang/test/Parser/bug50563.f b/flang/test/Parser/bug50563.f
new file mode 100644
index 0000000000000..d4ea93c86f9e4
--- /dev/null
+++ b/flang/test/Parser/bug50563.f
@@ -0,0 +1,4 @@
+!RUN: not %flang -fsyntax-only %s 2>&1 | FileCheck %s
+!CHECK: bug50563.f:3:1: error: Character in fixed-form label field must be a digit
+pi=3
+ end
diff --git a/flang/test/Preprocessing/pp039.F b/flang/test/Preprocessing/pp039.F
index b7fd99ba1f3f0..81e139ffdee82 100644
--- a/flang/test/Preprocessing/pp039.F
+++ b/flang/test/Preprocessing/pp039.F
@@ -1,4 +1,5 @@
! RUN: %flang -E %s 2>&1 | FileCheck %s
+! CHECK: warning: Character in fixed-form label field should be a digit
! CHECK: res = IFLM
! CHECK: (666)
! CHECK-NOT: res = ((666)+111)
More information about the flang-commits
mailing list