Changes between Initial Version and Version 2 of Ticket #214


Ignore:
Timestamp:
Sep 9, 2020, 4:34:10 PM (4 years ago)
Author:
mlbrooks
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #214

    • Property Summary changed from C Errors in dtype/ttype combination with Generic struct/union to Assertion with sized generic parameter breaks the declaring function's body
  • Ticket #214 – Description

    initial v2  
    1 The following code gives C-style errors about sizeof T in generic struct/union on compiling with CFA.
     1A sized generic struct cannot be instantiated in a function with an assertion that takes this struct as a parameter.
    22
    3 forall( dtype T | sized(T) ) { // Removing sized assertion gives CFA error "T declared void"
     3{{{
     4forall( otype X )
     5struct wrapper { X item; };
     6
     7forall( otype Y
     8                #ifndef HIDE_ERROR
     9                                    | { void unusedHelper( wrapper(Y) ); }
     10                #endif
     11      )
     12void f() {
     13    wrapper(Y) myvar;
     14}
     15}}}
     16
     17Actual (plain): GCC error: '_sizeof_S7wrapper_Y1Y_' undeclared
     18Actual (-DHIDE_ERROR), Expected (both):  Compiler success
     19
     20Desired for the following case in the memory allocator.  Here, the affected function is `balloc`, whose assertion for `$balloc_internal` takes a parameter of type `SS_fill(T)`.  In the affected function's body, the object declaration where the failure happens is the `(SS_fill(T)){...}` argument initializer.
     21{{{
     22forall( dtype T | sized(T) ) {
    423        union  U_fill   { char c; T * a; T t; };
    524        struct SS_fill  { char tag; U_fill(T) fill; };
     
    2342        return 0;
    2443}
     44}}}
     45Actual:  GCC error: '_sizeof_S7SS_fill_Y1T_' undeclared
     46Expected:  Compiler success
     47
     48This revision shows the assertion is at fault (but it does not provide a workaround).  The assumption of a TT-fitting `$balloc_internal` is changed from an assertion to a declaration.
     49{{{
     50forall( dtype T | sized(T) ) {
     51        union  U_fill   { char c; T * a; T t; };
     52        struct SS_fill  { char tag; U_fill(T) fill; };
     53}
     54
     55static inline forall( dtype T | sized(T) ) {
     56        T * $balloc_internal( void * Resize, void * Realloc, size_t Align, size_t Dim, SS_fill(T) Fill) {
     57                return (T*)0p;
     58        } // $balloc_internal
     59
     60        forall( ttype TT ) {
     61            T * $balloc_internal( void *, void *, size_t, size_t, SS_fill(T), TT );
     62            T * balloc( TT all ) {
     63                return $balloc_internal( (void*)0p, (void*)0p, 16, 1, (SS_fill(T)){'0', (U_fill(T)){'0'}}, all);
     64            } // balloc
     65        } // distribution TT
     66} // distribution T
     67
     68int main() {
     69        int * abc = balloc();
     70        free(abc);
     71        return 0;
     72}
     73}}}
     74Actual and expected: Compiler success, linker failure to find `$balloc_internal( ..., TT )`.