[flang] Skip over fixed form spaces when prescanning exponents & kind… (#145347)

… suffixes

When performing conditional tokenization of exponents and numeric kind
suffixes, be sure to skip over spaces in fixed form source.

Fixes https://github.com/llvm/llvm-project/issues/145333.
This commit is contained in:
Peter Klausler 2025-06-30 10:22:50 -07:00 committed by GitHub
parent a93d843ab3
commit f3d57590bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -915,12 +915,21 @@ bool Prescanner::HandleExponent(TokenSequence &tokens) {
int startColumn{column_};
TokenSequence possible;
EmitCharAndAdvance(possible, *at_);
if (InFixedFormSource()) {
SkipSpaces();
}
if (*at_ == '+' || *at_ == '-') {
EmitCharAndAdvance(possible, *at_);
if (InFixedFormSource()) {
SkipSpaces();
}
}
if (IsDecimalDigit(*at_)) { // it's an exponent; scan it
while (IsDecimalDigit(*at_)) {
EmitCharAndAdvance(possible, *at_);
if (InFixedFormSource()) {
SkipSpaces();
}
}
possible.CloseToken();
tokens.AppendRange(possible, 0); // appends to current token
@ -940,13 +949,22 @@ bool Prescanner::HandleKindSuffix(TokenSequence &tokens) {
TokenSequence withUnderscore, separate;
EmitChar(withUnderscore, '_');
EmitCharAndAdvance(separate, '_');
if (InFixedFormSource()) {
SkipSpaces();
}
if (IsLegalInIdentifier(*at_)) {
separate.CloseToken();
EmitChar(withUnderscore, *at_);
EmitCharAndAdvance(separate, *at_);
if (InFixedFormSource()) {
SkipSpaces();
}
while (IsLegalInIdentifier(*at_)) {
EmitChar(withUnderscore, *at_);
EmitCharAndAdvance(separate, *at_);
if (InFixedFormSource()) {
SkipSpaces();
}
}
}
withUnderscore.CloseToken();

View File

@ -1,5 +1,5 @@
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
! CHECK: k=1_4
k= 1_99999999
&4
& 4
end