[flang] Fix bug handling function prefix type
authorTim Keith <tkeith@nvidia.com>
Thu, 28 Feb 2019 17:53:49 +0000 (09:53 -0800)
committerGitHub <noreply@github.com>
Thu, 28 Feb 2019 18:38:17 +0000 (10:38 -0800)
This showed up in procinterface01. A function can have more than one
PrefixSpec (e.g. `real elemental f()`). We need to ignore that ones
that aren't types.

Also, process the type after the ImplicitPart rather than after the
SpecificationPart. The type of the function result variable could
be accessed between those places.

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

flang/lib/semantics/resolve-names.cc

index 9e462ad..15b5ca3 100644 (file)
@@ -609,11 +609,11 @@ public:
   void Post(const parser::SeparateModuleSubprogram &);
   bool Pre(const parser::Suffix &);
   bool Pre(const parser::PrefixSpec &);
+  void Post(const parser::ImplicitPart &);
 
 protected:
   // Set when we see a stmt function that is really an array element assignment
   bool badStmtFuncFound_{false};
-  void HandleFunctionPrefixType();
 
 private:
   // Info about the current function: parse tree of the type in the PrefixSpec;
@@ -2196,12 +2196,17 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) {
 
 bool SubprogramVisitor::Pre(const parser::PrefixSpec &x) {
   // Save this to process after UseStmt and ImplicitPart
-  funcInfo_.parsedType = std::get_if<parser::DeclarationTypeSpec>(&x.u);
-  funcInfo_.source = currStmtSource();
-  return funcInfo_.parsedType == nullptr;
+  if (const auto *parsedType{std::get_if<parser::DeclarationTypeSpec>(&x.u)}) {
+    funcInfo_.parsedType = parsedType;
+    funcInfo_.source = currStmtSource();
+    return false;
+  } else {
+    return true;
+  }
 }
 
-void SubprogramVisitor::HandleFunctionPrefixType() {
+void SubprogramVisitor::Post(const parser::ImplicitPart &) {
+  // If the function has a type in the prefix, process it now
   if (funcInfo_.parsedType) {
     messageHandler().set_currStmtSource(funcInfo_.source);
     if (const auto *type{ProcessTypeSpec(*funcInfo_.parsedType)}) {
@@ -4485,7 +4490,6 @@ static bool NeedsExplicitType(const Symbol &symbol) {
 void ResolveNamesVisitor::Post(const parser::SpecificationPart &) {
   badStmtFuncFound_ = false;
   CheckImports();
-  HandleFunctionPrefixType();
   bool inModule{currScope().kind() == Scope::Kind::Module};
   for (auto &pair : currScope()) {
     auto &symbol{*pair.second};