Opened 5 years ago

Last modified 3 months ago

#176 new defect

Assignment fails for union structure field

Reported by: pabuhr Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords:
Cc:

Description (last modified by pabuhr)

forall( dtype T )
union Link {
	struct {
		T * top;
		uintptr_t count;
	};
	__int128 atom; // both fields
};

int fred() {
	Link(int) l;
	int i = l.count, * ip = l.top;
	__int128 I = l.atom;
	i = l.count;
	ip = l.top;
	I = l.atom;
}
CFA Version 1.0.0 (debug)
test1.cfa:15:1 error: No reasonable alternatives for expression Applying untyped:
  Name: ?=?
...to:
  Name: ip
  Untyped Member Expression, with field: 
    Name: top  ... from aggregate:
    Name: l

The assignment fails because top is of type T. Assignment to non-polymorphic types works.

Change History (2)

comment:1 Changed 5 years ago by pabuhr

Description: modified (diff)

comment:2 Changed 3 months ago by ajbeach

I believe I stumbled on the same error. Or at least it is so close that whoever investigates the error should be aware of both because I think it came from the same part of the library but involves the work-around.

In the following case:

forall( T & )
union InnerUnion {
    T * top;
    uintptr_t atom;
};

forall( T & )
struct OuterStruct {
    InnerUnion(T) data;
};

forall( T & )
void ?{}( OuterStruct(T) & this ) { this.data.atom = 0; }

We get the following error from C:

repro-sized.cfa:13:174: error: ‘_dtype_static_member_10’ is a pointer; did you mean to use ‘->’?
   13 | void ?{}( OuterStruct(T) & this ) { this.data.atom = 0; }
      |

This just seems to be an error in the Cforall to C lowering. Particularly in the GenPoly? section because if you switch the T & on the OuterStruct and constructor to T it works correctly (which is what the standard library does to avoid the problem).

Note: See TracTickets for help on using tickets.