summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-alias.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2010-02-03 13:03:39 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2010-02-03 13:03:39 +0000
commite3c70387dc0fdf85f15dab9b1499148a039841ea (patch)
treecc0411dbf0232937e66a437fe07b60b01e85621a /gcc/tree-ssa-alias.c
parent4cad6dba074f9325e3bc0c4fa80e7646cb50088a (diff)
downloadgcc-e3c70387dc0fdf85f15dab9b1499148a039841ea.tar.gz
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
Diffstat (limited to 'gcc/tree-ssa-alias.c')
-rw-r--r--gcc/tree-ssa-alias.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index 6ace7e32680..16abb4c5222 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -963,6 +963,7 @@ ref_maybe_used_by_call_p_1 (gimple call, ao_ref *ref)
/* The following builtins do not read from memory. */
case BUILT_IN_FREE:
case BUILT_IN_MALLOC:
+ case BUILT_IN_CALLOC:
case BUILT_IN_MEMSET:
case BUILT_IN_FREXP:
case BUILT_IN_FREXPF:
@@ -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
being the definition point for the pointer. */
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;
/* Freeing memory kills the pointed-to memory. More importantly
the call has to serve as a barrier for moving loads and stores