Skip to content

Commit 776e25a

Browse files
authored
[flang] Inhibit case of false tokenization of Hollerith (#79029)
#78927 contains a case of fixed-form source in which a Hollerith literal is mistakenly tokenized, leading to grief later due to apparently unbalanced parentheses. The source looks like "REAL*8 R8HEAP(SCRSIZE)" and the Hollerith literal is misrecognized as such because it follows "8R". In order to properly tokenize Hollerith literals in old comma-free FORMAT statements like "1 FORMAT(3I5HFLANG)", the tokenizer in the prescanner treats a letter after an integer token ("3I") as a special case. The fix is to do this only when the characters involved are nested in parentheses and Hollerith is a possibility. Fixes #78927.
1 parent 4299d9b commit 776e25a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

flang/lib/Parser/prescan.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,14 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
608608
do {
609609
EmitCharAndAdvance(tokens, *at_);
610610
} while (IsHexadecimalDigit(*at_));
611-
} else if (IsLetter(*at_)) {
612-
// Handles FORMAT(3I9HHOLLERITH) by skipping over the first I so that
613-
// we don't misrecognize I9HOLLERITH as an identifier in the next case.
614-
EmitCharAndAdvance(tokens, *at_);
615611
} else if (at_[0] == '_' && (at_[1] == '\'' || at_[1] == '"')) { // 4_"..."
616612
EmitCharAndAdvance(tokens, *at_);
617613
QuotedCharacterLiteral(tokens, start);
614+
} else if (IsLetter(*at_) && !preventHollerith_ &&
615+
parenthesisNesting_ > 0) {
616+
// Handles FORMAT(3I9HHOLLERITH) by skipping over the first I so that
617+
// we don't misrecognize I9HOLLERITH as an identifier in the next case.
618+
EmitCharAndAdvance(tokens, *at_);
618619
}
619620
preventHollerith_ = false;
620621
} else if (*at_ == '.') {

0 commit comments

Comments
 (0)