Skip to content

Commit b1172d1

Browse files
ceseoaadeshps-mcw
authored andcommitted
[flang-rt] Fix TypeCategory for quad-precision COMPLEX (llvm#168090)
Modify the TypeCategory for quad-precision COMPLEX to CFI_type_float128_Complex so it matches the TypeCode returned by SELECT TYPE lowering. Fixes llvm#134565
1 parent 005d56d commit b1172d1

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

flang-rt/lib/runtime/type-code.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ RT_API_ATTRS TypeCode::TypeCode(TypeCategory f, int kind) {
9292
raw_ = CFI_type_extended_double_Complex;
9393
break;
9494
case 16:
95-
raw_ = CFI_type_long_double_Complex;
95+
raw_ = CFI_type_float128_Complex;
9696
break;
9797
}
9898
break;

flang-rt/unittests/Runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ add_flangrt_unittest(RuntimeTests
4040
Time.cpp
4141
TemporaryStack.cpp
4242
Transformational.cpp
43+
TypeCode.cpp
4344

4445
LINK_LIBS
4546
flang_rt.runtime.unittest
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===-- unittests/Runtime/TypeCode.cpp --------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "gtest/gtest.h"
10+
#include "flang-rt/runtime/type-code.h"
11+
12+
using namespace Fortran::runtime;
13+
using namespace Fortran::common;
14+
15+
TEST(TypeCode, ComplexTypes) {
16+
// Test all Complex type kinds to ensure they map correctly
17+
struct ComplexTypeMapping {
18+
int kind;
19+
Fortran::ISO::CFI_type_t expectedType;
20+
};
21+
22+
ComplexTypeMapping mappings[] = {
23+
{2, CFI_type_half_float_Complex},
24+
{3, CFI_type_bfloat_Complex},
25+
{4, CFI_type_float_Complex},
26+
{8, CFI_type_double_Complex},
27+
{10, CFI_type_extended_double_Complex},
28+
{16, CFI_type_float128_Complex},
29+
};
30+
31+
for (const auto &mapping : mappings) {
32+
TypeCode tc(TypeCategory::Complex, mapping.kind);
33+
EXPECT_EQ(tc.raw(), mapping.expectedType)
34+
<< "Complex kind " << mapping.kind << " should map to CFI type "
35+
<< mapping.expectedType;
36+
EXPECT_TRUE(tc.IsComplex());
37+
38+
auto categoryAndKind = tc.GetCategoryAndKind();
39+
ASSERT_TRUE(categoryAndKind.has_value());
40+
EXPECT_EQ(categoryAndKind->first, TypeCategory::Complex);
41+
EXPECT_EQ(categoryAndKind->second, mapping.kind);
42+
}
43+
}

0 commit comments

Comments
 (0)