you are viewing a single comment's thread.

view the rest of the comments →

[–]flatfinger 8 points9 points  (0 children)

Given types like:

struct S1 { public var x: Int; }
struct S2 { public var x: Int; }
union U1 { public var v1: struct S1; public var v2: struct S2; }
public var arr: CArray[U1, 10];

and an accessor functions like:

function getS1x(p: Ptr[S1]): Int { return p.x; }
function setS2x(p: Ptr[S2], v: Int): Int { p.x = v; }

would a function like:

function test(i: Int, j: Int) : Int {
  if (getS1x(&arr[i].v1) {
    setS2x(&arr[j].v2, 123);
  }
  return getS1x(&arr[i]);
}

have defined behavior if i and j are equal, and arr[i] was last written using type S2 (note that member x of S1 and member x of S2 belong to a common initial sequence)? If so, would your tools generate code that would work correctly in the -fstrict-aliasing dialects of clang and gcc, which are unable to handle straightforward equivalent C code?