From b47c88eaefcde1dbfe8d94f62b4eb25851734ffe Mon Sep 17 00:00:00 2001 From: V Donaldson Date: Wed, 1 Feb 2023 12:52:42 -0800 Subject: [PATCH] [flang] Allow compiler directives in the specification part of a module 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. --- flang/lib/Lower/PFTBuilder.cpp | 17 ++++++++++------- flang/test/Lower/pre-fir-tree02.f90 | 9 ++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/flang/lib/Lower/PFTBuilder.cpp b/flang/lib/Lower/PFTBuilder.cpp index a5f1ed7fb0fd..b9215f5ba2f4 100644 --- a/flang/lib/Lower/PFTBuilder.cpp +++ b/flang/lib/Lower/PFTBuilder.cpp @@ -396,7 +396,7 @@ private: 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 @@ private: 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()) { const semantics::Symbol *sym = std::get(entryStmt->t).symbol; @@ -420,7 +423,7 @@ private: sym = details->specific(); assert(sym->has() && "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); diff --git a/flang/test/Lower/pre-fir-tree02.f90 b/flang/test/Lower/pre-fir-tree02.f90 index 551cd454f8a0..f4fa626ba654 100644 --- a/flang/test/Lower/pre-fir-tree02.f90 +++ b/flang/test/Lower/pre-fir-tree02.f90 @@ -155,6 +155,13 @@ module test !![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 @@ contains ! CHECK: Subroutine sub subroutine sub(a) real(4):: a - ! CompilerDirective: + ! CHECK: CompilerDirective !DIR$ IGNORE_TKR a end subroutine