https://gcc.gnu.org/g:1487310d2707203e0f9b5b1794daf1f381e3e622

commit r14-11217-g1487310d2707203e0f9b5b1794daf1f381e3e622
Author: Iain Buclaw <ibuc...@gdcproject.org>
Date:   Fri Jan 17 00:23:45 2025 +0100

    d: Fix record layout of compiler-generated TypeInfo_Class [PR115249]
    
    In r14-8766, the layout of TypeInfo_Class changed in the runtime
    library, but didn't get reflected in the compiler-generated data,
    causing a corruption of runtime type introspection on BigEndian targets.
    
    This adjusts the size of the `ClassFlags' field from uint to ushort, and
    adds a new ushort `depth' field in the space where ClassFlags used to
    occupy.
    
            PR d/115249
    
    gcc/d/ChangeLog:
    
            * typeinfo.cc (create_tinfo_types): Update internal Typenfo
            representation.
            (TypeInfoVisitor::visit (TypeInfoClassDeclaration *)): Likewise.
    
    (cherry picked from commit d740694ff89ab5c78652a1f66b058ca16634ddbc)

Diff:
---
 gcc/d/typeinfo.cc | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index cadcbe8164e9..aa702892c4d7 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -258,10 +258,10 @@ create_tinfo_types (Module *mod)
                          Identifier::idPool ("TypeInfo_Class"),
                          array_type_node, array_type_node, array_type_node,
                          array_type_node, ptr_type_node, ptr_type_node,
-                         ptr_type_node, d_uint_type, ptr_type_node,
-                         array_type_node, ptr_type_node, ptr_type_node,
-                         d_uint_type, d_uint_type, d_uint_type, d_uint_type,
-                         NULL);
+                         ptr_type_node, d_ushort_type, d_ushort_type,
+                         ptr_type_node, array_type_node, ptr_type_node,
+                         ptr_type_node, d_uint_type, d_uint_type, d_uint_type,
+                         d_uint_type, NULL);
 
   object_module = mod;
 }
@@ -813,6 +813,7 @@ public:
        void *destructor;
        void function(Object) classInvariant;
        ClassFlags m_flags;
+       ushort depth;
        void *deallocator;
        OffsetTypeInfo[] m_offTi;
        void function(Object) defaultConstructor;
@@ -918,7 +919,10 @@ public:
        flags |= ClassFlags::noPointers;
 
     Lhaspointers:
-       this->layout_field (build_integer_cst (flags, d_uint_type));
+       this->layout_field (build_integer_cst (flags, d_ushort_type));
+
+       /* ushort depth;  (not implemented)  */
+       this->layout_field (build_zero_cst (d_ushort_type));
 
        /* void *deallocator;  */
        this->layout_field (null_pointer_node);
@@ -979,7 +983,10 @@ public:
        if (cd->isCOMinterface ())
          flags |= ClassFlags::isCOMclass;
 
-       this->layout_field (build_integer_cst (flags, d_uint_type));
+       this->layout_field (build_integer_cst (flags, d_ushort_type));
+
+       /* ushort depth;  (not implemented)  */
+       this->layout_field (build_zero_cst (d_ushort_type));
 
        /* void *deallocator;
           OffsetTypeInfo[] m_offTi;  (not implemented)

Reply via email to