[flang] more unit testing, fix a bug

Original-commit: flang-compiler/f18@70189119df
Reviewed-on: https://github.com/flang-compiler/f18/pull/212
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2018-10-12 16:25:39 -07:00
parent 7bda1b3243
commit 55df4a7ad8
2 changed files with 43 additions and 12 deletions

View File

@ -973,8 +973,13 @@ std::optional<SpecificIntrinsic> IntrinsicInterface::Match(
break; break;
case KindCode::same: case KindCode::same:
CHECK(sameArg != nullptr); CHECK(sameArg != nullptr);
resultType = *sameArg->GetType(); if (std::optional<DynamicType> aType{sameArg->GetType()}) {
CHECK(result.categorySet.test(resultType.category)); if (result.categorySet.test(aType->category)) {
resultType = *aType;
} else {
resultType.kind = aType->kind;
}
}
break; break;
case KindCode::effectiveKind: case KindCode::effectiveKind:
CHECK(kindDummyArg != nullptr); CHECK(kindDummyArg != nullptr);

View File

@ -154,31 +154,57 @@ void TestIntrinsics() {
IntrinsicProcTable table{IntrinsicProcTable::Configure(defaults)}; IntrinsicProcTable table{IntrinsicProcTable::Configure(defaults)};
table.Dump(std::cout); table.Dump(std::cout);
using Int1 = Type<TypeCategory::Integer, 1>;
using Int4 = Type<TypeCategory::Integer, 4>; using Int4 = Type<TypeCategory::Integer, 4>;
using Int8 = Type<TypeCategory::Integer, 8>;
using Real4 = Type<TypeCategory::Real, 4>;
using Real8 = Type<TypeCategory::Real, 8>;
using Complex4 = Type<TypeCategory::Complex, 4>;
using Complex8 = Type<TypeCategory::Complex, 8>;
using Char = Type<TypeCategory::Character, 1>;
using Log4 = Type<TypeCategory::Logical, 4>;
TestCall{table, "bad"} TestCall{table, "bad"}
.Push(Const(Scalar<Int4>{1})) .Push(Const(Scalar<Int4>{}))
.DoCall(); // bad intrinsic name .DoCall(); // bad intrinsic name
TestCall{table, "abs"} TestCall{table, "abs"}
.Push(Named("a", Const(Scalar<Int4>{1}))) .Push(Named("a", Const(Scalar<Int4>{})))
.DoCall(Int4::dynamicType); .DoCall(Int4::dynamicType);
TestCall{table, "abs"}.Push(Const(Scalar<Int4>{1})).DoCall(Int4::dynamicType); TestCall{table, "abs"}.Push(Const(Scalar<Int4>{})).DoCall(Int4::dynamicType);
TestCall{table, "abs"} TestCall{table, "abs"}
.Push(Named("bad", Const(Scalar<Int4>{1}))) .Push(Named("bad", Const(Scalar<Int4>{})))
.DoCall(); // bad keyword .DoCall(); // bad keyword
TestCall{table, "abs"}.DoCall(); // insufficient args TestCall{table, "abs"}.DoCall(); // insufficient args
TestCall{table, "abs"} TestCall{table, "abs"}
.Push(Const(Scalar<Int4>{1})) .Push(Const(Scalar<Int4>{}))
.Push(Const(Scalar<Int4>{2})) .Push(Const(Scalar<Int4>{}))
.DoCall(); // too many args .DoCall(); // too many args
TestCall{table, "abs"} TestCall{table, "abs"}
.Push(Const(Scalar<Int4>{1})) .Push(Const(Scalar<Int4>{}))
.Push(Named("a", Const(Scalar<Int4>{2}))) .Push(Named("a", Const(Scalar<Int4>{})))
.DoCall(); .DoCall();
TestCall{table, "abs"} TestCall{table, "abs"}
.Push(Named("a", Const(Scalar<Int4>{1}))) .Push(Named("a", Const(Scalar<Int4>{})))
.Push(Const(Scalar<Int4>{2})) .Push(Const(Scalar<Int4>{}))
.DoCall(); .DoCall();
TestCall{table, "abs"}.Push(Const(Scalar<Int1>{})).DoCall(Int1::dynamicType);
TestCall{table, "abs"}.Push(Const(Scalar<Int4>{})).DoCall(Int4::dynamicType);
TestCall{table, "abs"}.Push(Const(Scalar<Int8>{})).DoCall(Int8::dynamicType);
TestCall{table, "abs"}
.Push(Const(Scalar<Real4>{}))
.DoCall(Real4::dynamicType);
TestCall{table, "abs"}
.Push(Const(Scalar<Real8>{}))
.DoCall(Real8::dynamicType);
TestCall{table, "abs"}
.Push(Const(Scalar<Complex4>{}))
.DoCall(Real4::dynamicType);
TestCall{table, "abs"}
.Push(Const(Scalar<Complex8>{}))
.DoCall(Real8::dynamicType);
TestCall{table, "abs"}.Push(Const(Scalar<Char>{})).DoCall();
TestCall{table, "abs"}.Push(Const(Scalar<Log4>{})).DoCall();
// TODO: test other intrinsics
} }
} // namespace Fortran::evaluate } // namespace Fortran::evaluate