This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/21474] New: missed optimizations when comparing address to NULL
- From: "trt at acm dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 9 May 2005 17:22:22 -0000
- Subject: [Bug c/21474] New: missed optimizations when comparing address to NULL
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The program below gives some expressions which gcc could, but does not, evaluate
to true. E.g. gcc considers &p->a true, even when a is the first element
of the struct (is this a bug?), but does not consider &p->b[3] to be true.
struct foo {int a, b[10];};
int subr(int i, struct foo *p)
{
int x[10];
#if 0
// gcc folds this
if (&p->a) return 1;
#else
// but not these
if (&p->b[3]) return 1;
if (&x[3] != 0) return 1;
if (&x[i] != 0) return 1; // not sure if this one is safe to fold
#endif
return 0;
}
--
Summary: missed optimizations when comparing address to NULL
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: trt at acm dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21474