[flang-commits] [flang] 82d7a6b - [flang] Diagnose fixed form statement that begins with continuation line
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Sat Jan 28 10:51:29 PST 2023
Author: Peter Klausler
Date: 2023-01-28T10:16:43-08:00
New Revision: 82d7a6b2bbc9642b84cf068ae923f5ec316e9d6c
URL: https://github.com/llvm/llvm-project/commit/82d7a6b2bbc9642b84cf068ae923f5ec316e9d6c
DIFF: https://github.com/llvm/llvm-project/commit/82d7a6b2bbc9642b84cf068ae923f5ec316e9d6c.diff
LOG: [flang] Diagnose fixed form statement that begins with continuation line
A fixed form continuation line should not be the first line of a statement;
emit a warning if it looks like one is so that the programmer can look
for a missing card.
Differential Revision: https://reviews.llvm.org/D142763
Added:
Modified:
flang/lib/Parser/prescan.cpp
flang/test/Preprocessing/pp044.F
Removed:
################################################################################
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index ae8decfdf8369..9da30d2e6a093 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -269,9 +269,9 @@ void Prescanner::NextLine() {
}
void Prescanner::LabelField(TokenSequence &token) {
- const char *bad{nullptr};
int outCol{1};
const char *start{at_};
+ std::optional<int> badColumn;
for (; *at_ != '\n' && column_ <= 6; ++at_) {
if (*at_ == '\t') {
++at_;
@@ -282,18 +282,24 @@ void Prescanner::LabelField(TokenSequence &token) {
!(*at_ == '0' && column_ == 6)) { // '0' in column 6 becomes space
EmitChar(token, *at_);
++outCol;
- if (!bad && !IsDecimalDigit(*at_)) {
- bad = at_;
+ if (!badColumn && (column_ == 6 || !IsDecimalDigit(*at_))) {
+ badColumn = column_;
}
}
++column_;
}
- if (bad && !preprocessor_.IsNameDefined(token.CurrentOpenToken())) {
- Say(GetProvenance(bad),
- "Character in fixed-form label field must be a digit"_warn_en_US);
+ if (badColumn && !preprocessor_.IsNameDefined(token.CurrentOpenToken())) {
+ Say(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);
token.clear();
- at_ = start;
- return;
+ if (*badColumn < 6) {
+ at_ = start;
+ column_ = 1;
+ return;
+ }
+ outCol = 1;
}
if (outCol == 1) { // empty label field
// Emit a space so that, if the line is rescanned after preprocessing,
diff --git a/flang/test/Preprocessing/pp044.F b/flang/test/Preprocessing/pp044.F
index 6304fa4290b27..530753443a007 100644
--- a/flang/test/Preprocessing/pp044.F
+++ b/flang/test/Preprocessing/pp044.F
@@ -1,14 +1,15 @@
! RUN: %flang -E %s 2>&1 | FileCheck %s
! CHECK-NOT:z = 111
-* #define directive amid continuations
- integer, parameter :: KWM = 222, KWM111 = 333, KWM222 = 555
- integer, parameter :: KWMKWM = 333
+! CHECK:warning: Statement should not begin with a continuation line
+! CHECK:j=111+444
+* #define directive amid continuations.
+ integer, parameter :: KWM = 222
integer, parameter :: z = KWM
#define KWM 111
- +KWM+444
- if (z .EQ. 777) then
+ ,j=KWM+444
+ if (z .EQ. 222 .AND. j .EQ. 555) then
print *, 'yes'
else
- print *, 'no', z
+ print *, 'no', z, _4
end if
end
More information about the flang-commits
mailing list