diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp --- a/flang/lib/Parser/prescan.cpp +++ b/flang/lib/Parser/prescan.cpp @@ -269,9 +269,9 @@ } void Prescanner::LabelField(TokenSequence &token) { - const char *bad{nullptr}; int outCol{1}; const char *start{at_}; + std::optional badColumn; for (; *at_ != '\n' && column_ <= 6; ++at_) { if (*at_ == '\t') { ++at_; @@ -282,18 +282,24 @@ !(*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 --- 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