[Bug c/71538] Obvious optimization related to arrays aren't performed.

2016-06-15 Thread sasho648 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71538

--- Comment #4 from sasho648 at gmail dot com ---
More *shocking* example will be:

struct tx { int a[6], b[6]; } *f();

void (main)() 
{
int *p = f()->b;

if(p == NULL)
printf("What?"); 
}


Compiling with "gcc -Ofast -c test.c -o a.out" will result in this assembly
output:

;main function

sub rsp, 8
xor eax, eax
callf
cmp rax, 0FFE8h
jz  short loc_26

loc_21: 
add rsp, 8
retn
; ---

loc_26: 
pop rdx
mov edi, offset format ; "What?"
xor eax, eax

loc_2E: 
jmp printf

;main function end

Keeping the printf branch which at least for me is amazing.

[Bug c/71538] Obvious optimization related to arrays aren't performed.

2016-06-15 Thread sasho648 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71538

--- Comment #3 from sasho648 at gmail dot com ---
But if it's NULL for the cast it'll invoke UB I believe. Shouldn't the
optimizer assume that UB never occur?

[Bug c/71538] Obvious optimization related to arrays aren't performed.

2016-06-15 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71538

--- Comment #2 from Richard Biener  ---
I don't think the C standard says that p cannot be a NULL pointer for this
cast.

[Bug c/71538] Obvious optimization related to arrays aren't performed.

2016-06-14 Thread sasho648 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71538

--- Comment #1 from sasho648 at gmail dot com ---
The exact command used to compile this code was "gcc -O3 test.c" (as test.c
containing the snippet above).