[flang] check C1002
authorpeter klausler <pklausler@nvidia.com>
Tue, 18 Sep 2018 18:59:25 +0000 (11:59 -0700)
committerpeter klausler <pklausler@nvidia.com>
Tue, 25 Sep 2018 22:24:02 +0000 (15:24 -0700)
Original-commit: flang-compiler/f18@6a2fd760b4e38fe126b70a84e2b2e7dde62708be
Reviewed-on: https://github.com/flang-compiler/f18/pull/195
Tree-same-pre-rewrite: false

flang/lib/semantics/expression.cc
flang/lib/semantics/symbol.h

index accc561..752c980 100644 (file)
@@ -245,10 +245,23 @@ MaybeExpr AnalyzeHelper(ExprAnalyzer &ea, const parser::Designator &d) {
     if (std::optional<DataRef> dataRef{ExtractDataRef(std::move(result))}) {
       if (Component * component{std::get_if<Component>(&dataRef->u)}) {
         ea.ComponentRankCheck(*component);
-      } else if (const Symbol **symbol{
+      } else if (const Symbol **symbolPointer{
                      std::get_if<const Symbol *>(&dataRef->u)}) {
-        // TODO: Whole array reference: append : subscripts, enforce C1002
-        // Possibly use EA::Subscripts() below.
+        const Symbol &symbol{**symbolPointer};
+        if (const auto *details{
+                symbol.detailsIf<semantics::ObjectEntityDetails>()}) {
+          if (details->isArray()) {
+            if (details->isAssumedSize()) {  // C1002
+              // TODO: it's okay to forward an assumed-size array as an argument
+              // to many functions and all subroutines, though
+              ea.context.messages.Say(
+                  "assumed-size array '%s' must have subscripts in expression"_err_en_US,
+                  symbol.name().ToString().data());
+            }
+            // TODO: Whole array reference: append : subscripts, enforce C1002
+            // Possibly use EA::Subscripts() below.
+          }
+        }
       }
     }
     return result;
@@ -642,7 +655,6 @@ MaybeExpr ExprAnalyzer::Subscripts(const Symbol &symbol, ArrayRef &&ref) {
         symbolRank, symbol.name().ToString().data(), subscripts);
   }
   // TODO: fill in bounds of triplets?
-  // TODO: subtract lowers bounds?
   // TODO: enforce constraints, like lack of uppermost bound on assumed-size
   if (Component * component{std::get_if<Component>(&ref.u)}) {
     int baseRank{component->Rank()};
index d27daf0..8ae7f24 100644 (file)
@@ -120,6 +120,10 @@ public:
   void set_shape(const ArraySpec &shape);
   bool isDummy() const { return isDummy_; }
   bool isArray() const { return !shape_.empty(); }
+  bool isAssumedSize() const {
+    return isDummy() && isArray() && shape_.back().ubound().isAssumed() &&
+        !shape_.back().lbound().isAssumed();
+  }
 
 private:
   bool isDummy_;