Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Accept multiple spaces after compiler directive sentinel #76541

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

klausler
Copy link
Contributor

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 #76537.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:parser labels Dec 28, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 28, 2023

@llvm/pr-subscribers-flang-parser

Author: Peter Klausler (klausler)

Changes

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 #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 --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

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

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

LGTM

EmitChar(tokens, ' ');
++at_, ++column_;
while (*at_ == ' ' || *at_ == '\t') {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I wonder if using SkipSpaces would look more consistent.

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 llvm#76537.
@klausler klausler merged commit 7c55dd8 into llvm:main Jan 2, 2024
4 checks passed
@klausler klausler deleted the bug76537 branch January 2, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:parser flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flang] Support multiple spaces in compiler directives
3 participants