[flang-commits] [flang] cf71571 - [flang] Allow compiler directives in more places

Tim Keith via flang-commits flang-commits at lists.llvm.org
Tue Aug 11 08:37:43 PDT 2020


Author: Tim Keith
Date: 2020-08-11T08:37:27-07:00
New Revision: cf715717aa8cb17d98177af3ce63c7e20e8d25a3

URL: https://github.com/llvm/llvm-project/commit/cf715717aa8cb17d98177af3ce63c7e20e8d25a3
DIFF: https://github.com/llvm/llvm-project/commit/cf715717aa8cb17d98177af3ce63c7e20e8d25a3.diff

LOG: [flang] Allow compiler directives in more places

Allow compiler directives in the implicit-part and before USE statements
in the specification-part.

Differential Revision: https://reviews.llvm.org/D85693

Added: 
    flang/test/Parser/compiler-directives.f90

Modified: 
    flang/include/flang/Parser/parse-tree.h
    flang/lib/Parser/Fortran-parsers.cpp
    flang/lib/Parser/program-parsers.cpp
    flang/lib/Semantics/resolve-names.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index c6d5f68c1376..2fecac5118d8 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -403,7 +403,8 @@ struct ImplicitPartStmt {
       Statement<common::Indirection<ParameterStmt>>,
       Statement<common::Indirection<OldParameterStmt>>,
       Statement<common::Indirection<FormatStmt>>,
-      Statement<common::Indirection<EntryStmt>>>
+      Statement<common::Indirection<EntryStmt>>,
+      common::Indirection<CompilerDirective>>
       u;
 };
 
@@ -430,6 +431,7 @@ struct SpecificationPart {
   TUPLE_CLASS_BOILERPLATE(SpecificationPart);
   std::tuple<std::list<OpenACCDeclarativeConstruct>,
       std::list<OpenMPDeclarativeConstruct>,
+      std::list<common::Indirection<CompilerDirective>>,
       std::list<Statement<common::Indirection<UseStmt>>>,
       std::list<Statement<common::Indirection<ImportStmt>>>, ImplicitPart,
       std::list<DeclarationConstruct>>

diff  --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index f46186323ada..19b1893065fa 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -116,7 +116,8 @@ TYPE_PARSER(first(
     construct<ImplicitPartStmt>(statement(indirect(parameterStmt))),
     construct<ImplicitPartStmt>(statement(indirect(oldParameterStmt))),
     construct<ImplicitPartStmt>(statement(indirect(formatStmt))),
-    construct<ImplicitPartStmt>(statement(indirect(entryStmt)))))
+    construct<ImplicitPartStmt>(statement(indirect(entryStmt))),
+    construct<ImplicitPartStmt>(indirect(compilerDirective))))
 
 // R512 internal-subprogram -> function-subprogram | subroutine-subprogram
 // Internal subprograms are not program units, so their END statements

diff  --git a/flang/lib/Parser/program-parsers.cpp b/flang/lib/Parser/program-parsers.cpp
index 9e18c458ea3c..1be1207c8626 100644
--- a/flang/lib/Parser/program-parsers.cpp
+++ b/flang/lib/Parser/program-parsers.cpp
@@ -61,7 +61,7 @@ TYPE_PARSER(construct<ProgramUnit>(indirect(Parser<Module>{})) ||
 //         [declaration-construct]...
 TYPE_CONTEXT_PARSER("specification part"_en_US,
     construct<SpecificationPart>(many(openaccDeclarativeConstruct),
-        many(openmpDeclarativeConstruct),
+        many(openmpDeclarativeConstruct), many(indirect(compilerDirective)),
         many(statement(indirect(Parser<UseStmt>{}))),
         many(unambiguousStatement(indirect(Parser<ImportStmt>{}))),
         implicitPart, many(declarationConstruct)))
@@ -128,7 +128,7 @@ constexpr auto limitedDeclarationConstruct{recovery(
 // statement.
 constexpr auto limitedSpecificationPart{inContext("specification part"_en_US,
     construct<SpecificationPart>(many(openaccDeclarativeConstruct),
-        many(openmpDeclarativeConstruct),
+        many(openmpDeclarativeConstruct), many(indirect(compilerDirective)),
         many(statement(indirect(Parser<UseStmt>{}))),
         many(unambiguousStatement(indirect(Parser<ImportStmt>{}))),
         implicitPart, many(limitedDeclarationConstruct)))};

diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index ad93d01b2a1a..48d0e9315d54 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5916,7 +5916,8 @@ bool ResolveNamesVisitor::Pre(const parser::SpecificationPart &x) {
   Walk(std::get<2>(x.t));
   Walk(std::get<3>(x.t));
   Walk(std::get<4>(x.t));
-  const std::list<parser::DeclarationConstruct> &decls{std::get<5>(x.t)};
+  Walk(std::get<5>(x.t));
+  const std::list<parser::DeclarationConstruct> &decls{std::get<6>(x.t)};
   for (const auto &decl : decls) {
     if (const auto *spec{
             std::get_if<parser::SpecificationConstruct>(&decl.u)}) {

diff  --git a/flang/test/Parser/compiler-directives.f90 b/flang/test/Parser/compiler-directives.f90
new file mode 100644
index 000000000000..5545d0486e56
--- /dev/null
+++ b/flang/test/Parser/compiler-directives.f90
@@ -0,0 +1,11 @@
+! RUN: %f18 -funparse %s 2>&1
+
+! Test that compiler directives can appear in various places.
+
+module m
+  !dir$ integer
+  use iso_fortran_env
+  !dir$ integer
+  implicit integer(a-z)
+  !dir$ integer
+end


        


More information about the flang-commits mailing list