Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang-rt/lib/runtime/type-code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ RT_API_ATTRS TypeCode::TypeCode(TypeCategory f, int kind) {
raw_ = CFI_type_extended_double_Complex;
break;
case 16:
raw_ = CFI_type_long_double_Complex;
raw_ = CFI_type_float128_Complex;
break;
}
break;
Expand Down
1 change: 1 addition & 0 deletions flang-rt/unittests/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ add_flangrt_unittest(RuntimeTests
Time.cpp
TemporaryStack.cpp
Transformational.cpp
TypeCode.cpp

LINK_LIBS
flang_rt.runtime.unittest
Expand Down
43 changes: 43 additions & 0 deletions flang-rt/unittests/Runtime/TypeCode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===-- unittests/Runtime/TypeCode.cpp --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "gtest/gtest.h"
#include "flang-rt/runtime/type-code.h"

using namespace Fortran::runtime;
using namespace Fortran::common;

TEST(TypeCode, ComplexTypes) {
// Test all Complex type kinds to ensure they map correctly
struct ComplexTypeMapping {
int kind;
Fortran::ISO::CFI_type_t expectedType;
};

ComplexTypeMapping mappings[] = {
{2, CFI_type_half_float_Complex},
{3, CFI_type_bfloat_Complex},
{4, CFI_type_float_Complex},
{8, CFI_type_double_Complex},
{10, CFI_type_extended_double_Complex},
{16, CFI_type_float128_Complex},
};

for (const auto &mapping : mappings) {
TypeCode tc(TypeCategory::Complex, mapping.kind);
EXPECT_EQ(tc.raw(), mapping.expectedType)
<< "Complex kind " << mapping.kind << " should map to CFI type "
<< mapping.expectedType;
EXPECT_TRUE(tc.IsComplex());

auto categoryAndKind = tc.GetCategoryAndKind();
ASSERT_TRUE(categoryAndKind.has_value());
EXPECT_EQ(categoryAndKind->first, TypeCategory::Complex);
EXPECT_EQ(categoryAndKind->second, mapping.kind);
}
}
Loading