[flang] Fix crash evaluating kind expression
authorTim Keith <tkeith@nvidia.com>
Mon, 7 Jan 2019 19:28:20 +0000 (11:28 -0800)
committerTim Keith <tkeith@nvidia.com>
Tue, 8 Jan 2019 20:14:35 +0000 (12:14 -0800)
If we fail to evaluate the kind expression we were getting an invalid
optional reference. Instead, fail with an assert. This can happen if an
intrinsic function is not folded, but that will be implemented
eventually.

Original-commit: flang-compiler/f18@3bdbfc34bb75e6585eea57aa3240c3c825fff704
Reviewed-on: https://github.com/flang-compiler/f18/pull/256
Tree-same-pre-rewrite: false

flang/lib/semantics/resolve-names.cc

index de83b8d..46ac6b9 100644 (file)
@@ -2487,7 +2487,11 @@ void DeclarationVisitor::Post(const parser::IntrinsicTypeSpec::Character &x) {
 }
 void DeclarationVisitor::Post(const parser::CharSelector::LengthAndKind &x) {
   if (auto maybeExpr{EvaluateExpr(x.kind)}) {
-    charInfo_.kind = evaluate::ToInt64(*maybeExpr).value();
+    if (std::optional<std::int64_t> kind{evaluate::ToInt64(*maybeExpr)}) {
+      charInfo_.kind = *kind;
+    } else {
+      common::die("TODO: kind did not evaluate to a constant integer");
+    }
   }
   if (x.length) {
     charInfo_.length = GetParamValue(*x.length);