[llvm] [flang-rt] Fix REAL(10)/COMPLEX(10) component sizes in runtime type info (PR #192049)

Eugene Epshteyn via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 16:57:42 PDT 2026


================
@@ -280,3 +282,128 @@ TEST(Descriptor, Dump) {
   fclose(tmpf);
 }
 #endif // defined(__linux__) && !defined(__ANDROID__)
+
+// Verify that Descriptor::BytesFor returns the correct storage size
+// for Real and Complex types, especially for kind=10 where the x87
+// 80-bit extended precision value is stored in a 16-byte container.
+TEST(Descriptor, BytesForRealAndComplex) {
+  using TC = TypeCategory;
+  // Real kinds: storage size should account for container padding
+  EXPECT_EQ(Descriptor::BytesFor(TC::Real, 2), 2u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Real, 3), 2u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Real, 4), 4u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Real, 8), 8u);
+#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
+    defined(_M_IX86)
+  EXPECT_EQ(Descriptor::BytesFor(TC::Real, 10),
+      16u); // x87: 80-bit in 128-bit container
+#endif
+  EXPECT_EQ(Descriptor::BytesFor(TC::Real, 16), 16u);
+  // Complex kinds: should be twice the Real storage size
+  EXPECT_EQ(Descriptor::BytesFor(TC::Complex, 2), 4u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Complex, 3), 4u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Complex, 4), 8u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Complex, 8), 16u);
+#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
+    defined(_M_IX86)
+  EXPECT_EQ(Descriptor::BytesFor(TC::Complex, 10), 32u); // x87: 2 * 16 bytes
+#endif
+  EXPECT_EQ(Descriptor::BytesFor(TC::Complex, 16), 32u);
+  // Integer and Logical kinds: storage size equals the kind value
+  EXPECT_EQ(Descriptor::BytesFor(TC::Integer, 1), 1u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Integer, 4), 4u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Integer, 8), 8u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Logical, 1), 1u);
+  EXPECT_EQ(Descriptor::BytesFor(TC::Logical, 4), 4u);
+}
+
+// Test that Component::GetElementByteSize() returns the correct storage size.
+// This is the function modified by the fix; it delegates to
+// Descriptor::BytesFor() for Real and Complex types.
+TEST(Descriptor, ComponentGetElementByteSize) {
+  using TC = TypeCategory;
+  using typeInfo::Component;
+  using typeInfo::Value;
+
+  // Component has all-private members and no setters.  Mirror its layout
+  // with public fields so we can populate category_ and kind_ for testing.
+  struct TestableComponent {
----------------
eugeneepshteyn wrote:

Thank you for adding the test.

Could you please look into a way to create an actual descriptor with the right kind? Having this subset here feels very brittle: we change something in the real descriptor, we forget to modify it here, and then we'll have random buildbots fail for no apparent reason at random times on some platforms but not the others...

https://github.com/llvm/llvm-project/pull/192049


More information about the llvm-commits mailing list