[flang-commits] [flang] [flang] Refine tokenization trick that hid macro name (PR #121990)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Jan 7 12:31:21 PST 2025
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/121990
In order to properly expose the Hollerith editing item in something like FORMAT(3I9HHOLLERITH) as its own token, the tokenization routine in the prescanner has special handling for digit strings followed by letters ("3I" above). This handler's effects are too broad, and prevent a macro name from being recognized as such in a reported bug; make the test for a hidden Hollerith more precise.
Fixes https://github.com/llvm/llvm-project/issues/121931.
>From 032dc154c8e9ea5fd43d7d5cd656f1226df7b8d9 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 7 Jan 2025 12:25:55 -0800
Subject: [PATCH] [flang] Refine tokenization trick that hid macro name
In order to properly expose the Hollerith editing item in
something like FORMAT(3I9HHOLLERITH) as its own token, the
tokenization routine in the prescanner has special handling
for digit strings followed by letters ("3I" above). This
handler's effects are too broad, and prevent a macro name
from being recognized as such in a reported bug; make the
test for a hidden Hollerith more precise.
Fixes https://github.com/llvm/llvm-project/issues/121931.
---
flang/lib/Parser/prescan.cpp | 19 ++++++++++++++++---
flang/test/Preprocessing/bug129131.F | 5 +++++
2 files changed, 21 insertions(+), 3 deletions(-)
create mode 100644 flang/test/Preprocessing/bug129131.F
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 3cd32d7e6c92e8..9cf093b012ccd8 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -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);
+ }
+ 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_ == '.') {
diff --git a/flang/test/Preprocessing/bug129131.F b/flang/test/Preprocessing/bug129131.F
new file mode 100644
index 00000000000000..5b1a914a2c9e35
--- /dev/null
+++ b/flang/test/Preprocessing/bug129131.F
@@ -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
More information about the flang-commits
mailing list