[flang] Fix crash in name resolution
authorPeter Klausler <pklausler@nvidia.com>
Sat, 17 Dec 2022 23:25:45 +0000 (15:25 -0800)
committerPeter Klausler <pklausler@nvidia.com>
Sun, 18 Dec 2022 01:23:52 +0000 (17:23 -0800)
In an error recovery situation, the name resolution code for a
SELECT TYPE statement must check the presence of an optional
expression before calling GetType() upon it.

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

flang/lib/Semantics/resolve-names.cpp

index 29a7c2f..fdc3b3e 100644 (file)
@@ -6359,14 +6359,16 @@ void ConstructVisitor::Post(const parser::SelectTypeStmt &x) {
     // This isn't a name in the current scope, it is in each TypeGuardStmt
     MakePlaceholder(*name, MiscDetails::Kind::SelectTypeAssociateName);
     association.name = &*name;
-    auto exprType{association.selector.expr->GetType()};
     if (ExtractCoarrayRef(association.selector.expr)) { // C1103
       Say("Selector must not be a coindexed object"_err_en_US);
     }
-    if (exprType && !exprType->IsPolymorphic()) { // C1159
-      Say(association.selector.source,
-          "Selector '%s' in SELECT TYPE statement must be "
-          "polymorphic"_err_en_US);
+    if (association.selector.expr) {
+      auto exprType{association.selector.expr->GetType()};
+      if (exprType && !exprType->IsPolymorphic()) { // C1159
+        Say(association.selector.source,
+            "Selector '%s' in SELECT TYPE statement must be "
+            "polymorphic"_err_en_US);
+      }
     }
   } else {
     if (const Symbol *