[flang-commits] [flang] 3c2fc7a - [flang] Refine tokenization trick that hid macro name (#121990)
via flang-commits
flang-commits at lists.llvm.org
Wed Jan 8 13:17:19 PST 2025
Author: Peter Klausler
Date: 2025-01-08T13:17:16-08:00
New Revision: 3c2fc7a45ae230a32e473e093b4583079050a969
URL: https://github.com/llvm/llvm-project/commit/3c2fc7a45ae230a32e473e093b4583079050a969
DIFF: https://github.com/llvm/llvm-project/commit/3c2fc7a45ae230a32e473e093b4583079050a969.diff
LOG: [flang] Refine tokenization trick that hid macro name (#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.
Added:
flang/test/Preprocessing/bug129131.F
Modified:
flang/lib/Parser/prescan.cpp
Removed:
################################################################################
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index b7462ebfb09006..703a02792a1c4e 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