[flang-commits] [flang] [Flang][OpenMP] Fix comments that should not be Sentinels on fixed format. (PR #68911)

Roger Ferrer Ibáñez via flang-commits flang-commits at lists.llvm.org
Thu Oct 12 13:44:28 PDT 2023


================
@@ -1174,18 +1174,19 @@ Prescanner::IsFixedFormCompilerDirectiveLine(const char *start) const {
   if (!IsFixedFormCommentChar(col1)) {
     return std::nullopt;
   }
+  if (p[0] != '$') {
----------------
rofirrim wrote:

Two of the sentinels we register are `dir$` and `@cuf`. Those break the usual form of `$xyz` (or `$` for OpenMP conditionals), so I don't think this can work.

For example, this fixed-form program should issue a diagnostic (the directive is misplaced), but it will not after this change (because the line will be assumed as a comment)

```fortran
!dir$ ignore_tkr

      program main
      end program main
```

Surprisingly we do not have any test with `dir$` directives with fixed-form (but sev, so the current set of tests won't catch this. I suggest to add at least one as part of this change.

Maybe @klausler has better ideas here, but I think we can at least assume that, in fixed form, sentinels must be spelled contiguous (without intervening blanks) after the column 1. For the common case of sentinels of length 4 (such as `$omp`, `@cuf`, `dir!`, etc. this is the only spelling possible, as using blanks would require more than 4 columns). For the sentinel `$` used in OpenMP conditional, the OpenMP spec seems to suggest that the `$` must appear in column 2 (see screenshot below), so it also fulfills this property. If in the future we have shorter sentinels (imagine a hypothetical `@fp`) I guess it is OK if we enforce this rule (i.e. we would reject spellings like `@f p` or `@ fp` and only allow `@fp `).

![OpenMP Spec](https://github.com/llvm/llvm-project/assets/1222352/ab5b21dd-1bba-4d66-9a3c-d137c50a0548)



https://github.com/llvm/llvm-project/pull/68911


More information about the flang-commits mailing list