[flang-commits] [flang] [flang] Accept multiple spaces after compiler directive sentinel (PR #76541)
via flang-commits
flang-commits at lists.llvm.org
Thu Dec 28 14:47:49 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-parser
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/76541.diff
2 Files Affected:
- (modified) flang/lib/Parser/prescan.cpp (+5-3)
- (modified) flang/test/Parser/compiler-directives.f90 (+1)
``````````diff
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 79cdaccf1fbfec..68d7d9f0c53c47 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 88cfd0944faf0a..67e8d5b292aa07 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/76541
More information about the flang-commits
mailing list