[flang-commits] [flang] [flang] Accept multiple spaces after compiler directive sentinel (PR #76541)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Jan 2 07:54:11 PST 2024
https://github.com/klausler updated https://github.com/llvm/llvm-project/pull/76541
>From cfd70d24c31f95434a5f6d7c3f2b7632d4380846 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Thu, 28 Dec 2023 14:44:56 -0800
Subject: [PATCH] [flang] Accept multiple spaces after compiler directive
sentinel
The prescanner allows multiple spaces within a compiler directive,
but not between the directive's sentinel (e.g., !DIR$) and the
directive's first token.
Fixes https://github.com/llvm/llvm-project/issues/76537.
---
flang/lib/Parser/prescan.cpp | 8 +++++---
flang/test/Parser/compiler-directives.f90 | 1 +
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 79cdaccf1fbfec1..68d7d9f0c53c475 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -139,16 +139,18 @@ void Prescanner::Statement() {
SkipSpaces();
}
} else {
- // Compiler directive. Emit normalized sentinel.
+ // Compiler directive. Emit normalized sentinel, squash following spaces.
EmitChar(tokens, '!');
++at_, ++column_;
for (const char *sp{directiveSentinel_}; *sp != '\0';
++sp, ++at_, ++column_) {
EmitChar(tokens, *sp);
}
- if (*at_ == ' ') {
+ if (*at_ == ' ' || *at_ == '\t') {
EmitChar(tokens, ' ');
- ++at_, ++column_;
+ while (*at_ == ' ' || *at_ == '\t') {
+ ++at_, ++column_;
+ }
}
tokens.CloseToken();
}
diff --git a/flang/test/Parser/compiler-directives.f90 b/flang/test/Parser/compiler-directives.f90
index 88cfd0944faf0a8..67e8d5b292aa07c 100644
--- a/flang/test/Parser/compiler-directives.f90
+++ b/flang/test/Parser/compiler-directives.f90
@@ -17,6 +17,7 @@ module m
!dir$ integer
!dir$ integer=64
!dir$ integer = 64
+ !dir$ integer = 64
PROC(4)
!dir$ optimize:1
!dir$ optimize : 1
More information about the flang-commits
mailing list