[Bug c/71538] New: Obvious optimization related to arrays aren't performed.
sasho648 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Jun 14 21:07:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71538
Bug ID: 71538
Summary: Obvious optimization related to arrays aren't
performed.
Product: gcc
Version: 6.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: sasho648 at gmail dot com
Target Milestone: ---
Consider this code:
#include <stdio.h>
extern void f(int *p)
{
p = *((int (*)[6])p);
if(p == NULL)
printf("NULL");
}
It's obvious (at least for me) that p can't be possibly NULL because it's
assigned the value of pointer to the first element of array with 6 elements.
However the assembly output of this code for my native machine compiled on
linux (x86-64 - dumped using ida pro with general assembler for intel) is:
;f function
test rdi, rdi
jz short loc_400550
rep retn
; ---------------------------------------------------------------------------
align 10h
loc_400550:
mov edi, (offset format+4) ; "NULL"
xor eax, eax
jmp _printf
;f function end
As you see the branch where printf is called with "NULL" is still present in
the code although on theory it should never be reached.
I don't think there is requirement by the standard to disallow evaluation of
this expression (as opposed to for example *&p).
More information about the Gcc-bugs
mailing list