On Tue, 19 Mar 2019 at 13:07, Robin Dapp <rd...@linux.ibm.com> wrote:
>
> Hi,
>
> > Alignment is written to TypeInfo, I don't think it should ever be
> > zero.  That would mean that it isn't being generated by the compiler,
> > or read by the library correctly, so something else is amiss.
>
> it took me a while to see that in libphobos/libdruntime/object.d
>
>  override @property size_t talign() nothrow pure const {return m_align;}
>
> returns a size_t but m_align is a uint.  The type info seems to be
> stored in memory by the compiler and writes a GCC "sizetype".  When
> using it, we only emit a 4-byte read which loads the first half of the
> stored 8 bytes.  This will work on a little-endian machine but fail on
> big endian.
>
> I'd hope it is safe to change m_align's type to size_t since, as far as
> I can tell, the compiler will always write 8 bytes and the memory layout
> will not be changed by that.
>

So, when the initializer value type is larger than the field, it
truncates rather than rounds?

This would mean that StructFlags and ClassFlags will also both have a
wrong value as well.

> Does this [1] look reasonable?
>

If there's a compiler/library discrepancy, the compiler should be
adjusted to write out the value at the correct size.

I think the following below should do it.

-- 
Iain

--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -830,7 +830,7 @@ public:
        flags |= ClassFlags::noPointers;

     Lhaspointers:
-       this->layout_field (size_int (flags));
+       this->layout_field (build_integer_cst (flags, d_uint_type));

        /* void *deallocator;  */
        tree ddtor = (cd->aggDelete)
@@ -886,7 +886,7 @@ public:
        if (cd->isCOMinterface ())
          flags |= ClassFlags::isCOMclass;

-       this->layout_field (size_int (flags));
+       this->layout_field (build_integer_cst (flags, d_uint_type));

        /* void *deallocator;
           OffsetTypeInfo[] m_offTi;  (not implemented)
@@ -1019,7 +1019,7 @@ public:
     StructFlags::Type m_flags = 0;
     if (ti->hasPointers ())
       m_flags |= StructFlags::hasPointers;
-    this->layout_field (size_int (m_flags));
+    this->layout_field (build_integer_cst (m_flags, d_uint_type));

     /* void function(void*) xdtor;  */
     tree dtor = (sd->dtor) ? build_address (get_symbol_decl (sd->dtor))
@@ -1033,7 +1033,7 @@ public:
       this->layout_field (null_pointer_node);

     /* uint m_align;  */
-    this->layout_field (size_int (ti->alignsize ()));
+    this->layout_field (build_integer_cst (ti->alignsize (), d_uint_type));

     if (global.params.is64bit)
       {
@@ -1488,9 +1488,8 @@ create_typeinfo (Type *type, Module *mod)
              make_internal_typeinfo (tk, ident,
                                      array_type_node, array_type_node,
                                      ptr_type_node, ptr_type_node,
-                                     ptr_type_node, ptr_type_node,
-                                     size_type_node, ptr_type_node,
-                                     ptr_type_node, size_type_node,
+                                     ptr_type_node, ptr_type_node, d_uint_type,
+                                     ptr_type_node, ptr_type_node, d_uint_type,
                                      ptr_type_node, argtype, argtype, NULL);
            }
          t->vtinfo = TypeInfoStructDeclaration::create (t);

Reply via email to