dimitriv / Ziria

A domain-specific-language and compiler for low-level bitstream processing.
92 stars 18 forks source link

Bug in passing array by reference #48

Open bradunov opened 9 years ago

bradunov commented 9 years ago

Although the array passing semantics is not entirely clear, it is sort of assumed to be by reference. And here is a related bug:

arr_shift(params.channelCoeffs, -agc_shift);

where

let arr_shift(a : arr complex16, agc_shift : int) = if (agc_shift > 0) then { v_shift_left_complex16(a,a,agc_shift); } else { v_shift_right_complex16(a,a,-agc_shift); } in

It uses the implicit assumption that the arrays are passed by reference. But here it is not the case. Probably because params is a struct. So we get:

        blink_copy(aln60__rx245, __bnd_fst_ln186__rx107params.channelCoeffs,
                   64 * sizeof( complex16));

        if (-agc_shiftln119__rx159 > 0L) {
            __if_rx246 = __ext_v_shift_left_complex16(aln60__rx245, 64,
                                                      aln60__rx245, 64,
                                                      -agc_shiftln119__rx159);
        } else {
            __if_rx246 = __ext_v_shift_right_complex16(aln60__rx245, 64,
                                                       aln60__rx245, 64,
                                                       --agc_shiftln119__rx159);
        }

And clearly the original memory location does not get changed.

More interestingly, if the arr_shift function is manually inlined, the projection is recognized as an array and passed directly by reference.