You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- example output is:
i: 0x7fff6adf3dac p(i): 0x7fff6adf3dad: ERROR
basically the conditional operator is evaluated with the opposite arguments according to its boolean operand expression in this case.
I tried some other simple cases and it was OK - no clue why this is happening, but in my case it's a big bug (I store values in the low bits of some pointers using this trick in some cases to optimize memory usage).
Note that compiling without optimizations results in correct code generation. Maybe there's something awry with the optimizer with this case.
The text was updated successfully, but these errors were encountered:
Extended Description
the following code when built with clang 3.5.0 with -O1 or above is compiled incorrectly:
#include <stdio.h>
union u {
size_t _refptr;
void setPtr(int* refptr, bool readonly = false) {
_refptr = (size_t)refptr;
if (readonly)
_refptr |= 1;
}
int* getPtr() const {
// the line below is compiled incorrectly with clang++ 3.5.0 -O1 or above
return (int*)((_refptr & 1L) ? (_refptr ^ 1L) : _refptr);
}
};
int main(int argc, char *argv[]) {
u u;
int i = 100;
u.setPtr(&i);
printf("i: %p p(i): %p: %s\n", &i, u.getPtr(), &i == u.getPtr() ? "OK" : "ERROR");
return 0;
}
-- example output is:
i: 0x7fff6adf3dac p(i): 0x7fff6adf3dad: ERROR
basically the conditional operator is evaluated with the opposite arguments according to its boolean operand expression in this case.
I tried some other simple cases and it was OK - no clue why this is happening, but in my case it's a big bug (I store values in the low bits of some pointers using this trick in some cases to optimize memory usage).
Note that compiling without optimizations results in correct code generation. Maybe there's something awry with the optimizer with this case.
The text was updated successfully, but these errors were encountered: