[flang] [OpenMP] miscellaneous parse tree fix (flang-compiler/f18#669)
authorJinxin (Brian) Yang <jinxiny@nvidia.com>
Tue, 20 Aug 2019 17:30:29 +0000 (10:30 -0700)
committerGitHub <noreply@github.com>
Tue, 20 Aug 2019 17:30:29 +0000 (10:30 -0700)
Fix `aligned(argument-list[ : alignment])` for `declare simd`

(original implementation will throw parser error if `: alignment` is present.

Original-commit: flang-compiler/f18@f3f50f9ad3b77174d0054011a17c8e4d3af50d98
Reviewed-on: https://github.com/flang-compiler/f18/pull/669

flang/lib/parser/openmp-grammar.h
flang/lib/semantics/check-omp-structure.cc
flang/test/semantics/omp-declarative-directive.f90

index 1be7b85..c3f84b8 100644 (file)
@@ -156,7 +156,7 @@ TYPE_CONTEXT_PARSER("Omp LINEAR clause"_en_US,
 
 // ALIGNED(list: alignment)
 TYPE_PARSER(construct<OmpAlignedClause>(
-    nonemptyList(name), maybe(":"_tok) >> scalarIntConstantExpr))
+    nonemptyList(name), maybe(":" >> scalarIntConstantExpr)))
 
 TYPE_PARSER(construct<OmpObject>(pure(OmpObject::Kind::Object), designator) ||
     construct<OmpObject>(
index 19e0f05..b382d2c 100644 (file)
@@ -276,6 +276,16 @@ void OmpStructureChecker::Enter(const parser::OmpEndSectionsDirective &x) {
 void OmpStructureChecker::Enter(const parser::OpenMPDeclareSimdConstruct &x) {
   const auto &dir{std::get<parser::Verbatim>(x.t)};
   PushContext(dir.source, OmpDirective::DECLARE_SIMD);
+  // 2.8.2 declare-simd-clause -> simdlen-clause |
+  //                              linear-clause |
+  //                              aligned-clause |
+  //                              uniform-clause |
+  //                              inbranch-clause |
+  //                              notinbranch-clause
+  OmpClauseSet allowed{OmpClause::LINEAR, OmpClause::ALIGNED,
+      OmpClause::UNIFORM, OmpClause::INBRANCH, OmpClause::NOTINBRANCH};
+  SetContextAllowed(allowed);
+  SetContextAllowedOnce({OmpClause::SIMDLEN});
 }
 
 void OmpStructureChecker::Leave(const parser::OpenMPDeclareSimdConstruct &) {
index 01739f5..a8cf5ea 100644 (file)
@@ -24,7 +24,8 @@
 subroutine declare_simd_1(a, b)
   real(8), intent(inout) :: a, b
   !ERROR: Internal: no symbol found for 'declare_simd_1'
-  !$omp declare simd(declare_simd_1)
+  !ERROR: Internal: no symbol found for 'a'
+  !$omp declare simd(declare_simd_1) aligned(a)
   a = 3.14 + b
 end subroutine declare_simd_1