[flang-commits] [PATCH] D143105: [flang] Allow compiler directives in the specification part of a module

vdonaldson via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Feb 1 13:00:32 PST 2023


vdonaldson created this revision.
vdonaldson added a project: Flang.
Herald added subscribers: sunshaoce, mehdi_amini, jdoerfert.
Herald added a project: All.
vdonaldson requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Lowering code currently allows for directives inside a program or
subprogram, or outside any program unit. Directives may also appear
in the specification part of a module, as in:

  module mm
    interface
       subroutine ss(aa)
         !dir$ ignore_tkr(tkr) aa
         integer :: aa(*)
       end subroutine ss
    end interface
  end module

With some exceptions such as OpenMP directives, most directives are
currently ignored, so this code should generate an "ignoring all compiler
directives" message.


https://reviews.llvm.org/D143105

Files:
  flang/lib/Lower/PFTBuilder.cpp
  flang/test/Lower/pre-fir-tree02.f90


Index: flang/test/Lower/pre-fir-tree02.f90
===================================================================
--- flang/test/Lower/pre-fir-tree02.f90
+++ flang/test/Lower/pre-fir-tree02.f90
@@ -155,6 +155,13 @@
   !![disable]type, extends(a_type) :: b_type
   !![disable]  integer :: y
   !![disable]end type
+  interface
+     subroutine ss(aa)
+       ! CHECK: CompilerDirective
+       !DIR$ IGNORE_TKR aa
+       integer :: aa
+     end subroutine ss
+  end interface
 contains
   ! CHECK: Function foo
   function foo(x)
@@ -212,7 +219,7 @@
   ! CHECK: Subroutine sub
   subroutine sub(a)
     real(4):: a
-    ! CompilerDirective:
+    ! CHECK: CompilerDirective
     !DIR$ IGNORE_TKR a
   end subroutine
 
Index: flang/lib/Lower/PFTBuilder.cpp
===================================================================
--- flang/lib/Lower/PFTBuilder.cpp
+++ flang/lib/Lower/PFTBuilder.cpp
@@ -396,7 +396,7 @@
     assert(!evaluationListStack.empty() && "empty evaluation list stack");
     if (!constructAndDirectiveStack.empty())
       eval.parentConstruct = constructAndDirectiveStack.back();
-    auto &entryPointList = eval.getOwningProcedure()->entryPointList;
+    lower::pft::FunctionLikeUnit *owningProcedure = eval.getOwningProcedure();
     evaluationListStack.back()->emplace_back(std::move(eval));
     lower::pft::Evaluation *p = &evaluationListStack.back()->back();
     if (p->isActionStmt() || p->isConstructStmt() || p->isEndStmt() ||
@@ -408,11 +408,14 @@
         p->printIndex = 1;
       }
       lastLexicalEvaluation = p;
-      for (std::size_t entryIndex = entryPointList.size() - 1;
-           entryIndex && !entryPointList[entryIndex].second->lexicalSuccessor;
-           --entryIndex)
-        // Link to the entry's first executable statement.
-        entryPointList[entryIndex].second->lexicalSuccessor = p;
+      if (owningProcedure) {
+        auto &entryPointList = owningProcedure->entryPointList;
+        for (std::size_t entryIndex = entryPointList.size() - 1;
+             entryIndex && !entryPointList[entryIndex].second->lexicalSuccessor;
+             --entryIndex)
+          // Link to the entry's first executable statement.
+          entryPointList[entryIndex].second->lexicalSuccessor = p;
+      }
     } else if (const auto *entryStmt = p->getIf<parser::EntryStmt>()) {
       const semantics::Symbol *sym =
           std::get<parser::Name>(entryStmt->t).symbol;
@@ -420,7 +423,7 @@
         sym = details->specific();
       assert(sym->has<semantics::SubprogramDetails>() &&
              "entry must be a subprogram");
-      entryPointList.push_back(std::pair{sym, p});
+      owningProcedure->entryPointList.push_back(std::pair{sym, p});
     }
     if (p->label.has_value())
       labelEvaluationMap->try_emplace(*p->label, p);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143105.494046.patch
Type: text/x-patch
Size: 2792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230201/fc82440f/attachment-0001.bin>


More information about the flang-commits mailing list