Bug 21294 - Missed removal of null pointer check
Summary: Missed removal of null pointer check
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 enhancement
Target Milestone: 4.1.0
Assignee: Kazu Hirata
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: missed-optimization, patch
Depends on:
Blocks:
 
Reported: 2005-04-30 01:39 UTC by Andrew Pinski
Modified: 2005-07-23 22:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-04-30 05:17:01


Attachments
patch (1.83 KB, text/plain)
2005-05-01 23:16 UTC, Kazu Hirata
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-04-30 01:39:58 UTC
struct f
{
  int i;
};
void link_error ();
void g(struct f *i)
{
  i->i = 1;
  if (&i->i == 0)
    link_error ();
}
int main()
{
  struct f n;
  g(&n);
}

There should be no references to link_error.
The following is optimized:
void link_error ();
void g(int *i)
{
  *i = 1;
  if (i == 0)
    link_error ();
}
int main()
{
  int n;
  g(&n);
}
Comment 1 Andrew Pinski 2005-04-30 01:46:08 UTC
For VRP to catch this, extract_range_from_unary_expr has to be enhanced to deal with ADDR_EXPR.
Comment 2 Kazu Hirata 2005-04-30 03:34:40 UTC
I've got a patch in testing.
Comment 3 Kazu Hirata 2005-05-01 23:16:13 UTC
Created attachment 8788 [details]
patch
Comment 4 Andrew Pinski 2005-05-02 13:54:28 UTC
Patch posted here: <http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00076.html>.
Comment 5 CVS Commits 2005-05-02 18:06:38 UTC
Subject: Bug 21294

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	kazu@gcc.gnu.org	2005-05-02 18:06:28

Modified files:
	gcc            : ChangeLog tree-vrp.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg/tree-ssa: pr21294.c 

Log message:
	gcc/
	PR tree-optimization/21294
	* tree-vrp.c (vrp_expr_computes_nonzero): New.
	(extract_range_from_expr): Call vrp_expr_computes_nonzero.
	
	testsuite/
	PR tree-optimization/21294
	* gcc.dg/tree-ssa/pr21294.c: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8562&r2=2.8563
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-vrp.c.diff?cvsroot=gcc&r1=2.14&r2=2.15
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5427&r2=1.5428
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/pr21294.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Kazu Hirata 2005-05-02 18:07:11 UTC
Just checked in a patch.