Hi, All

Can gatekeeper help review this fix?

Bug link: http://bugs.open64.net/show_bug.cgi?id=580



small case to reproduce:



typedef struct stru1

{

} Stru1;

typedef struct stru2

{

  unsigned int count;

  const char *table[];

}Stru2;

static Stru2 ins1 = {

  .count = 1,.table = {"base"}

};

static Stru2 ins2 = {

  .count = 4,.table = {"t", "IPMB-A only", "sgdsg","dsdg"}

};

static Stru1 ins3[] = {

};



Here the problem is no matter how many elements in the initialization of
ins2.table, the org offset of ins3 is always 0x20. In this case it should be
0x40.


        .section .data

        .org 0x0

        .align  0

        .type   ins1, @object

        .size   ins1, 16

ins1:   # 0x0

        # offset 0

        .4byte  1

        .skip 4

        .quad   .rodata +0

        # end of initialization for ins1

        .org 0x10

        .align  0

        .type   ins2, @object

        .size   ins2, 16

ins2:   # 0x10

        # offset 16

        .4byte  4

        .skip 4

        .quad   .rodata +16

        .quad   .rodata +32

        .quad   .rodata +48

        .quad   .rodata +64

        # end of initialization for ins2

        .org 0x20

        .align  0

        .type   ins3, @object

ins3:   # 0x20

        # end of initialization for ins3





The fix is when st's type is variable length struct, the size of st should
be replaced by its inito size when been initialized.

Patch:

Index: osprey/be/com/data_layout.cxx
===================================================================
--- osprey/be/com/data_layout.cxx       (revision 3404)
+++ osprey/be/com/data_layout.cxx       (working copy)
@@ -649,8 +649,16 @@
 {
   UINT align = Adjusted_Alignment(blk);
   INT64 old_offset;
-  INT64 size = ST_size(blk);
-
+  INT64 size;
+  INITO_IDX ino_idx;
+  // if blk is variable length struct, its size should be inito size.
+  if (TY_kind(ST_type(blk)) == KIND_STRUCT && (ino_idx =
Find_INITO_For_Symbol(blk)) != 0)
+  {
+    size = Get_INITO_Size(ino_idx);
+    Is_True(size >= ST_size(blk),("%s's inito size smaller than
ST_size",ST_name(blk)));
+  }
+  else
+    size = ST_size(blk);
 #if defined(TARG_PPC32)
   if ( ST_sclass(blk) == SCLASS_FORMAL &&
MTYPE_is_m(TY_mtype(ST_type(blk))) ) {
     size = MTYPE_RegisterSize(Spill_Int_Mtype);;


------

Best wishes

zhuqing
------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to