Opened 9 months ago

Last modified 9 months ago

#280 new defect

Compound Literal Hoisted Out of Function/typeof

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

Description

A simple example of the problem:

forall( T & )
struct proxy {};

forall( T & )
void action( typeof( (proxy(T)){} ) & p ) {
    (void)p;
}
// Becomes (trimmed and cleaned):
proxy(T) _compLit0 = {};
forall(T &)
void action(typeof(_compLit0) &p){
    ((void)p);
}

Because T is a data type and the proxy constructor has no assertions, this actually compiles, it seems adding anything else to it will cause errors. However, it is non-sense and we should not be generating it.

To avoid cases like this, there should not be hoisting out of typeof, sizeof or other non-evaluated contexts. Since they are not evaluated anyways we don't actually need the memory.

If there are other cases where the storage would have to be hoisted out of a function and are evaluated, they may have to forbidden if the constructed type is polymorphic. Or handled specially depending on the case.

Change History (1)

comment:1 Changed 9 months ago by ajbeach

The generated code is invalid (just not in a way that is currently causing any problems) and is (or would be) caught by the new invariant checking code.

I programmed in an exception (in my working code, a merge with it should come soon) so they are not triggered if this happens at a the global level. If this occurs in a nested function, a different pattern is created an a different exception would be needed. Because this happens exactly once across the libraries and tests (array-container/dimexpr-match-cfa), I decided to just remove that case for now.

The fix that allows for the removal of the exception should handle both cases.

Note: See TracTickets for help on using tickets.