Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#253 closed defect (fixed)

Plan-9 with dynamic layout gives wrong field offsets

Reported by: mlbrooks Owned by: Michael Brooks <mlbrooks@…>
Priority: minor Component: cfa-cc
Version: 1.0 Keywords:
Cc:

Description

Subsequent plan9-inlined fields (which make the owning struct have multiple inheritance) are unusable when the owning struct has dynamic layout (a layout that varies according to the size of a sized-T parameter), because uses of such fields get the wrong offset.

forall( T )
struct thing {
    T q;            // variable-sized padding
    inline double;
    inline float;
};

#define SHOW_OFFSETS \
    double & x_inner_double = x; \
    float  & x_inner_float  = x; \
    printf("  offset of inner double: %ld\n", ((char *) & x_inner_double) - ((char *) & x) ); \
    printf("  offset of inner float:  %ld\n", ((char *) & x_inner_float ) - ((char *) & x) );

void showStatic( thing(int) & x ) {
    printf("static:\n");
    SHOW_OFFSETS
}

forall( T )
void showDynamic( thing(T) & x ) {
    printf("dynamic:\n");
    SHOW_OFFSETS
}

int main() {
    thing(int) x;
    showStatic(x);
    showDynamic(x);
}

Actual: Runs with output showing inconsitent offset of second inlined field (float)

static:
  offset of inner double: 8
  offset of inner float:  16
dynamic:
  offset of inner double: 8
  offset of inner float:  8

Expected: Runs with output showing consitent offset of second inlined field (float)

static:
  offset of inner double: 8
  offset of inner float:  16
dynamic:
  offset of inner double: 8
  offset of inner float:  16

Change History (2)

comment:1 Changed 3 years ago by Michael Brooks <mlbrooks@…>

Owner: set to Michael Brooks <mlbrooks@…>
Resolution: fixed
Status: newclosed

In 801978b:

GenPoly? field-number selection for dynamic layouts uses uniqueId to match anonymous fields, rather than accepting first name match. fixed #253?

comment:2 Changed 3 years ago by Michael Brooks <mlbrooks@…>

In 801978b:

GenPoly? field-number selection for dynamic layouts uses uniqueId to match anonymous fields, rather than accepting first name match. fixed #253?

Note: See TracTickets for help on using tickets.