clangupc / upc2c

Clang based UPC to C Translator
https://clangupc.github.io/clang-upc2c
Other
4 stars 3 forks source link

Incorrect initializers for definite shared arrays #99

Open PHHargrove opened 10 years ago

PHHargrove commented 10 years ago

FIRST: note that initialization of shared variables is NOT required by the UPC 1.3 spec. So, this issue can be resolved either by correcting the translated code, or by removing this optional support.

The following code fails the validation assertions for any number of threads other than 1:

#include <upc.h>
#include <assert.h>
#include <stdio.h>

#if __UPC_DYNAMIC_THREADS__
#error This test is only valid for static threads
#endif

shared [0] int Indef[4] = {0,1,2,3};
shared [1] int Cyclic[4] = {4,5,6,7};
shared [2] int Block2[4] = {8,9,10,11};

int main(void) {
   for (int i = 0; i < 4; ++i) {
     assert(Indef[i] == i);
     assert(Cyclic[i] == 4+i);
     assert(Block2[i] == 8+i);
   }
   return 0;
}

The generated code for the initializers:

extern void UPCRI_INIT_tt_3512010450() {
    UPCR_BEGIN_FUNCTION();
    int _bupc_Indef_val[4] = { 0, 1, 2, 3 };
    int _bupc_Cyclic_val[4] = { 4, 5, 6, 7 };
    int _bupc_Block2_val[4] = { 8, 9, 10, 11 };
    if (upcr_mythread() == 0) {
        upcr_put_pshared(Indef, 0, &_bupc_Indef_val, 16);
        upcr_put_pshared(Cyclic, 0, &_bupc_Cyclic_val, 16);
        upcr_put_shared(Block2, 0, &_bupc_Block2_val, 16);
    }
}

While the Cyclic and Block2 are distributed arrays, the initialization code is performing a Put of a contiguous (single thread) block of 16 bytes.

For reference, the BUPC translator generates the following code (post-processed using indent) which performs the correct initiailzations:

void
UPCRI_INIT_tt_6385737540(void)
{
        UPCR_BEGIN_FUNCTION();
        int32_t         _bupc_Indef_val[4] = {0, 1, 2, 3,};
        upcr_startup_arrayinit_diminfo_t _bupc_Indef_diminfos[] = {
                {4, 4, 0},
        };
        int32_t         _bupc_Cyclic_val[4] = {4, 5, 6, 7,};
        upcr_startup_arrayinit_diminfo_t _bupc_Cyclic_diminfos[] = {
                {4, 4, 0},
        };
        int32_t         _bupc_Block2_val[4] = {8, 9, 10, 11,};
        upcr_startup_arrayinit_diminfo_t _bupc_Block2_diminfos[] = {
                {4, 4, 0},
        };
        UPCR_SET_SRCPOS("_tt_6385737540_INIT", 0);
        upcr_startup_initparray(Indef, _bupc_Indef_val, _bupc_Indef_diminfos, 1, 4, 0);
        upcr_startup_initparray(Cyclic, _bupc_Cyclic_val, _bupc_Cyclic_diminfos, 1, 4, 1);
        upcr_startup_initarray(Block2, _bupc_Block2_val, _bupc_Block2_diminfos, 1, 4, 2);
}
nenadv commented 9 years ago

I also noticed that we get the following warning on some other test:

upcr_startup_arrayinit_diminfo_t _bupc_t_diminfo[] = { 1UL, 1UL, 0 };
                                                           ^~~~~~~~~~~
                                                           {          }
/home/nenad/t.c:28:60: warning: suggest braces around initialization of subobject [-Wmissing-braces]