[flang-commits] [flang] [flang] Accept multiple spaces after compiler directive sentinel (PR #76541)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Dec 28 14:47:21 PST 2023


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/76541

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.

>From f77764884c45416a734840a894aa39a0eef21796 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 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



More information about the flang-commits mailing list