From 55df4a7ad8c40c9d042e2bd317b1d5079ea17c55 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Fri, 12 Oct 2018 16:25:39 -0700 Subject: [PATCH] [flang] more unit testing, fix a bug Original-commit: flang-compiler/f18@70189119df6ae84f995d6dd1fbdb6d03c784c723 Reviewed-on: https://github.com/flang-compiler/f18/pull/212 Tree-same-pre-rewrite: false --- flang/lib/evaluate/intrinsics.cc | 9 ++++-- flang/test/evaluate/intrinsics.cc | 46 ++++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/flang/lib/evaluate/intrinsics.cc b/flang/lib/evaluate/intrinsics.cc index 0f6995f571e8..8385c4e49cd9 100644 --- a/flang/lib/evaluate/intrinsics.cc +++ b/flang/lib/evaluate/intrinsics.cc @@ -973,8 +973,13 @@ std::optional IntrinsicInterface::Match( break; case KindCode::same: CHECK(sameArg != nullptr); - resultType = *sameArg->GetType(); - CHECK(result.categorySet.test(resultType.category)); + if (std::optional aType{sameArg->GetType()}) { + if (result.categorySet.test(aType->category)) { + resultType = *aType; + } else { + resultType.kind = aType->kind; + } + } break; case KindCode::effectiveKind: CHECK(kindDummyArg != nullptr); diff --git a/flang/test/evaluate/intrinsics.cc b/flang/test/evaluate/intrinsics.cc index 615b27cbbef1..b9810b95827b 100644 --- a/flang/test/evaluate/intrinsics.cc +++ b/flang/test/evaluate/intrinsics.cc @@ -154,31 +154,57 @@ void TestIntrinsics() { IntrinsicProcTable table{IntrinsicProcTable::Configure(defaults)}; table.Dump(std::cout); + using Int1 = Type; using Int4 = Type; + using Int8 = Type; + using Real4 = Type; + using Real8 = Type; + using Complex4 = Type; + using Complex8 = Type; + using Char = Type; + using Log4 = Type; TestCall{table, "bad"} - .Push(Const(Scalar{1})) + .Push(Const(Scalar{})) .DoCall(); // bad intrinsic name TestCall{table, "abs"} - .Push(Named("a", Const(Scalar{1}))) + .Push(Named("a", Const(Scalar{}))) .DoCall(Int4::dynamicType); - TestCall{table, "abs"}.Push(Const(Scalar{1})).DoCall(Int4::dynamicType); + TestCall{table, "abs"}.Push(Const(Scalar{})).DoCall(Int4::dynamicType); TestCall{table, "abs"} - .Push(Named("bad", Const(Scalar{1}))) + .Push(Named("bad", Const(Scalar{}))) .DoCall(); // bad keyword TestCall{table, "abs"}.DoCall(); // insufficient args TestCall{table, "abs"} - .Push(Const(Scalar{1})) - .Push(Const(Scalar{2})) + .Push(Const(Scalar{})) + .Push(Const(Scalar{})) .DoCall(); // too many args TestCall{table, "abs"} - .Push(Const(Scalar{1})) - .Push(Named("a", Const(Scalar{2}))) + .Push(Const(Scalar{})) + .Push(Named("a", Const(Scalar{}))) .DoCall(); TestCall{table, "abs"} - .Push(Named("a", Const(Scalar{1}))) - .Push(Const(Scalar{2})) + .Push(Named("a", Const(Scalar{}))) + .Push(Const(Scalar{})) .DoCall(); + TestCall{table, "abs"}.Push(Const(Scalar{})).DoCall(Int1::dynamicType); + TestCall{table, "abs"}.Push(Const(Scalar{})).DoCall(Int4::dynamicType); + TestCall{table, "abs"}.Push(Const(Scalar{})).DoCall(Int8::dynamicType); + TestCall{table, "abs"} + .Push(Const(Scalar{})) + .DoCall(Real4::dynamicType); + TestCall{table, "abs"} + .Push(Const(Scalar{})) + .DoCall(Real8::dynamicType); + TestCall{table, "abs"} + .Push(Const(Scalar{})) + .DoCall(Real4::dynamicType); + TestCall{table, "abs"} + .Push(Const(Scalar{})) + .DoCall(Real8::dynamicType); + TestCall{table, "abs"}.Push(Const(Scalar{})).DoCall(); + TestCall{table, "abs"}.Push(Const(Scalar{})).DoCall(); + // TODO: test other intrinsics } } // namespace Fortran::evaluate