summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/errno-1.c17
-rw-r--r--gcc/tree-ssa-alias.c16
4 files changed, 46 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 62f96ffc251..34437bd5a50 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+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>
* doc/invoke.texi: Fix name of sched1 dump.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ccfdb6b88b2..27979358961 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
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
* gcc.c-torture/compile/pr42927.c: New testcase.
diff --git a/gcc/testsuite/gcc.dg/errno-1.c b/gcc/testsuite/gcc.dg/errno-1.c
new file mode 100644
index 00000000000..d0365bed45b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/errno-1.c
@@ -0,0 +1,17 @@
+/* { 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" } } */
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