Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,22 @@ bool Prescanner::NextToken(TokenSequence &tokens) {
QuotedCharacterLiteral(tokens, start);
} else if (IsLetter(*at_) && !preventHollerith_ &&
parenthesisNesting_ > 0) {
// Handles FORMAT(3I9HHOLLERITH) by skipping over the first I so that
// we don't misrecognize I9HOLLERITH as an identifier in the next case.
EmitCharAndAdvance(tokens, *at_);
const char *p{at_};
int digits{0};
for (;; ++digits) {
++p;
if (InFixedFormSource()) {
p = SkipWhiteSpace(p);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could p possibly walk off the end of the buffer here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Ghithub had issues. My comment was meant for line 715 ++p.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so; source files are normalized so that their last lines always end with a newline.

}
if (!IsDecimalDigit(*p)) {
break;
}
}
if (digits > 0 && (*p == 'h' || *p == 'H')) {
// Handles FORMAT(3I9HHOLLERITH) by skipping over the first I so that
// we don't misrecognize I9HOLLERITH as an identifier in the next case.
EmitCharAndAdvance(tokens, *at_);
}
}
preventHollerith_ = false;
} else if (*at_ == '.') {
Expand Down
5 changes: 5 additions & 0 deletions flang/test/Preprocessing/bug129131.F
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
! RUN: %flang -fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
! CHECK: PRINT *, 2_4
#define a ,3
print *, mod(5 a)
end
Loading