Commit e3c70387 by Richard Guenther Committed by Richard Biener

re PR tree-optimization/42944 (errno misoptimization around malloc call)

2010-02-03  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/42944
	* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Handle
	calloc.
	(call_may_clobber_ref_p_1): Likewise.  Properly handle
	malloc and calloc clobbering errno.

	* gcc.dg/errno-1.c: New testcase.

From-SVN: r156467
parent 4cad6dba
2010-02-03 Richard Guenther <rguenther@suse.de>
PR tree-optimization/42944
* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Handle
calloc.
(call_may_clobber_ref_p_1): Likewise. Properly handle
malloc and calloc clobbering errno.
2010-02-03 Steven Bosscher <steven@gcc.gnu.org> 2010-02-03 Steven Bosscher <steven@gcc.gnu.org>
* doc/invoke.texi: Fix name of sched1 dump. * doc/invoke.texi: Fix name of sched1 dump.
......
2010-02-03 Richard Guenther <rguenther@suse.de> 2010-02-03 Richard Guenther <rguenther@suse.de>
PR tree-optimization/42944
* gcc.dg/errno-1.c: New testcase.
2010-02-03 Richard Guenther <rguenther@suse.de>
PR middle-end/42927 PR middle-end/42927
* gcc.c-torture/compile/pr42927.c: New testcase. * gcc.c-torture/compile/pr42927.c: New testcase.
......
/* { dg-do compile } */
/* { dg-options "-O2" } */
#include <errno.h>
#include <stdlib.h>
int main()
{
void *p;
errno = 0;
p = malloc (-1);
if (errno != 0)
do_not_optimize_away ();
return 0;
}
/* { dg-final { scan-assembler "do_not_optimize_away" } } */
...@@ -963,6 +963,7 @@ ref_maybe_used_by_call_p_1 (gimple call, ao_ref *ref) ...@@ -963,6 +963,7 @@ ref_maybe_used_by_call_p_1 (gimple call, ao_ref *ref)
/* The following builtins do not read from memory. */ /* The following builtins do not read from memory. */
case BUILT_IN_FREE: case BUILT_IN_FREE:
case BUILT_IN_MALLOC: case BUILT_IN_MALLOC:
case BUILT_IN_CALLOC:
case BUILT_IN_MEMSET: case BUILT_IN_MEMSET:
case BUILT_IN_FREXP: case BUILT_IN_FREXP:
case BUILT_IN_FREXPF: case BUILT_IN_FREXPF:
...@@ -1190,6 +1191,21 @@ call_may_clobber_ref_p_1 (gimple call, ao_ref *ref) ...@@ -1190,6 +1191,21 @@ call_may_clobber_ref_p_1 (gimple call, ao_ref *ref)
/* Allocating memory does not have any side-effects apart from /* Allocating memory does not have any side-effects apart from
being the definition point for the pointer. */ being the definition point for the pointer. */
case BUILT_IN_MALLOC: case BUILT_IN_MALLOC:
case BUILT_IN_CALLOC:
/* Unix98 specifies that errno is set on allocation failure.
Until we properly can track the errno location assume it
is not a plain decl but anonymous storage in a different
translation unit. */
if (flag_errno_math)
{
struct ptr_info_def *pi;
if (DECL_P (base))
return false;
if (INDIRECT_REF_P (base)
&& TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME
&& (pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0))))
return pi->pt.anything || pi->pt.nonlocal;
}
return false; return false;
/* Freeing memory kills the pointed-to memory. More importantly /* Freeing memory kills the pointed-to memory. More importantly
the call has to serve as a barrier for moving loads and stores the call has to serve as a barrier for moving loads and stores
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment