[flang-commits] [PATCH] D156759: [flang][openmp] Handle !$INCLUDE "foo" (bug #64128)

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jul 31 16:14:49 PDT 2023


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert, guansong, yaxunl.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: jplehr, sstefan1.

Detect and process INCLUDE lines that are guarded by OpenMP conditional
compilation markers (!$), when enabled.

Fixes https://github.com/llvm/llvm-project/issues/64128.


https://reviews.llvm.org/D156759

Files:
  flang/lib/Parser/prescan.cpp
  flang/test/Parser/OpenMP/cond-include.f90
  flang/test/Parser/OpenMP/cond-include.inc


Index: flang/test/Parser/OpenMP/cond-include.inc
===================================================================
--- /dev/null
+++ flang/test/Parser/OpenMP/cond-include.inc
@@ -0,0 +1 @@
+STOP "pass"
Index: flang/test/Parser/OpenMP/cond-include.f90
===================================================================
--- /dev/null
+++ flang/test/Parser/OpenMP/cond-include.f90
@@ -0,0 +1,4 @@
+! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck %s
+!CHECK: STOP "pass"
+!$ include "cond-include.inc"
+end
Index: flang/lib/Parser/prescan.cpp
===================================================================
--- flang/lib/Parser/prescan.cpp
+++ flang/lib/Parser/prescan.cpp
@@ -106,7 +106,7 @@
   case LineClassification::Kind::PreprocessorDirective:
     preprocessor_.Directive(TokenizePreprocessorDirective(), *this);
     return;
-  case LineClassification::Kind::CompilerDirective:
+  case LineClassification::Kind::CompilerDirective: {
     directiveSentinel_ = line.sentinel;
     CHECK(InCompilerDirective());
     BeginStatementAndAdvance();
@@ -118,22 +118,22 @@
       }
       CHECK(*at_ == '!');
     }
+    std::optional<int> condOffset;
     if (directiveSentinel_[0] == '$' && directiveSentinel_[1] == '\0') {
-      // OpenMP conditional compilation line.  Remove the sentinel and then
-      // treat the line as if it were normal source.
-      at_ += 2, column_ += 2;
-      if (inFixedForm_) {
-        LabelField(tokens);
-      } else {
-        SkipSpaces();
-      }
+      // OpenMP conditional compilation line.
+      condOffset = 2;
     } else if (directiveSentinel_[0] == '@' && directiveSentinel_[1] == 'c' &&
         directiveSentinel_[2] == 'u' && directiveSentinel_[3] == 'f' &&
         directiveSentinel_[4] == '\0') {
-      // CUDA conditional compilation line.  Remove the sentinel and then
-      // treat the line as if it were normal source.
-      at_ += 5, column_ += 5;
-      if (inFixedForm_) {
+      // CUDA conditional compilation line.
+      condOffset = 5;
+    }
+    if (condOffset) {
+      at_ += *condOffset, column_ += *condOffset;
+      if (auto payload{IsIncludeLine(at_)}) {
+        FortranInclude(at_ + *payload);
+        return;
+      } else if (inFixedForm_) {
         LabelField(tokens);
       } else {
         SkipSpaces();
@@ -153,6 +153,7 @@
       tokens.CloseToken();
     }
     break;
+  }
   case LineClassification::Kind::Source:
     BeginStatementAndAdvance();
     if (inFixedForm_) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156759.545854.patch
Type: text/x-patch
Size: 2484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230731/4ecd9137/attachment-0001.bin>


More information about the flang-commits mailing list