From 9ae71a0357b9ccdb49e709cd513aeaa190bce027 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Mon, 7 Jan 2019 11:28:20 -0800 Subject: [PATCH] [flang] Fix crash evaluating kind expression 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index de83b8d..46ac6b9 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -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 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); -- 2.7.4