Open llvmbot opened 5 years ago
Here is a reduced example: https://wandbox.org/permlink/etMQoctaLhXPIoFl It prints "this should be zero: -1" with Clang 8.0.0.
void funcA(int g) { int grp[3] = {-1}; int i, k = 0; for (i = 0; i < 1; ++i) { if (grp[g] > 0) { ((long long)&grp[0]) = 0; } grp[k++] = 0; } printf("this should be zero: %d\n", grp[0]); }
int main(void) { funcA(1); }
1) argument "ptr" has type "char *"
But you're not accessing the variable via a char , but instead, you're casting to a long long .
2) condition "cond" is always zero
This seems more concerning.
Extended Description
Lets consider example r.c from attachment
$ clang-7.0 -O0 r.c -o r0.out $ clang-7.0 -O1 r.c -fno-strict-aliasing -o r1.nsa.out $ clang-7.0 -O1 r.c -o r1.sa.out
$ ./r0.out this should be zero: 0
$ ./r1.nsa.out this should be zero: 0
$ ./r1.sa.out this should be zero: -1
static inline void attribute((always_inline)) longLongAssign( int cond, char ptr) { if ( cond ) { ((long long *)ptr) = 0; } }
I suppose test doesn't violate strict-aliasing rule, because 1) argument "ptr" has type "char *" 2) condition "cond" is always zero
Why I got different results?
P.S. I am new therefore apologize for my mistakes.