clangupc / clang-upc

Clang UPC Front-End
https://clangupc.github.io/
Other
17 stars 5 forks source link

Bad shared allocation - shared declared inside the function context #48

Closed nenadv closed 10 years ago

nenadv commented 10 years ago

Intrepid's test18 test fails on PPC platform with bad vaddr. Here is a small example that duplicates this problem:

#include <upc.h>

static shared int int1 = 5;
void x ()
{
  static shared int int2 = 10;
}
int
main ()
{
  x ();
  int1 = 1;
}

After looking into the generated code I noticed that 'int2' is not being declared from the shared section. Instead, '.comm' is used.

        .type   x.int2,@object
        .local  x.int2
        .comm   x.int2,4,4
        .type   int1,@object
        .section        upc_shared,"",@nobits
        .align  2
int1:
        .long   0
        .size   int1, 4

GUPC allocates this variable from the upc_shared section.

While this bug was exhibited on PPC, the same issues exists on x86-64, but it is not visible as vaddr is small enough to fit inside the thread's sahred space (we just write at the random shared space). On PPC all VMAs start at 0x10000000 that puts our vaddr high enough to be detected.