Opened 9 months ago

#215 new defect

Cannot declare object whose size takes multiple steps of dynamic calculation

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


CFA-CPP generates bad C code when declaring generic-of-generic objects like vec(vec(T)), where both the size of the generic wrappers depend on the size of the element, and where the original size unit is kept abstract (like T, not like float). That is, multi-step dynamic size calculations do not work.

Two specific symptoms are noted, which are cases 1 and 2 below.

forall( otype X )
struct wrap_in { X x; };

forall( otype Y )
struct wrap_out { Y y; };

forall( dtype X )
struct ref_in { X * x; };

forall( dtype Y )
struct ref_out { Y * y; };

#if SHOW_ERR == 1
    forall( otype Z )
    void f() {
        wrap_out( wrap_in( Z ) ) obj;  // GCC: '____sizeof_S7wrap_in_Y1Z_' undeclared
#elif SHOW_ERR == 2
    forall( otype Z )
    void f() {
        wrap_in( Z ) obj_0;
        wrap_out( wrap_in( Z ) ) obj;  // GCC: dereferencing 'void *' pointer AND invalid use of void expression

// related declarations that work

void f2() {
    wrap_out( wrap_in( float ) ) obj;

forall( otype Z )
void f3() {
     ref_out(  ref_in( Z ) ) obj;
     ref_out( wrap_in( Z ) ) obj;
    wrap_out(  ref_in( Z ) ) obj;

In all cases, we expect compiler success. In the SHOW_ERR cases, the actual error is commented.

Note that case 2 adds an extra valid declaration before the line that is broken in case 1, which acts as a workaround for the case-1 error, meaning that only the case-2 error remains. The case-2 error also occurs in the case-1 program.

The error of case 1 has a similar symptom to #214. In #214, the required sizeof variable (and calculation to fill it) is emitted by default, but when the bug's problematic declaration is in scope, that variable is no longer emitted. Here, the sizeof variable for wrap_in is not emitted by default (case 1), but adding a workaround declaration forces it to be emitted (case 2).

The error of case 2 has no known workaround.

Change History (0)

Note: See TracTickets for help on using tickets.