clangupc / upc2c

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

Bad translation of pointer-to-shared as logical #115

Closed PHHargrove closed 8 years ago

PHHargrove commented 8 years ago

Given the following UPC input:

     1  #include <upc.h>
     2  int main(void) {
     3     shared int *p;
     4     int i;
     5
     6     int a = p        ? 0 : 1;
     7     int b = (p && i) ? 0 : 1;
     8
     9     return 0;
    10  }

Clang-upc2c is translating lines 6 and 7 as

        int a = !upcr_isnull_pshared(p) ? 0 : 1;
        int b = (p && i) ? 0 : 1;

The translation of line 6 (initialization of a) correctly uses upcr_isnull_pshared(). However, no such conversion is being applied in the translation of line 7.

This mistranslation goes unnoticed with a packed representation of the pointer-to-shared, but is still incorrect because there are NULL pointers-to-shared that are not zero (non-zero phase in particular).

In the case of a struct representation of the pointer-to-shared, the mistranslation leads to a compilation error from the backend, since struct && int is not a valid expression.

PHHargrove commented 8 years ago

Commit db5f95f resolved this for issue for me. Thanks.