This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix PR 17252
- From: Diego Novillo <dnovillo at redhat dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 14 Sep 2004 23:02:41 -0400
- Subject: fix PR 17252
- Organization: Red Hat Canada
Adds an additional check to not assuming that a pointer can't take its
own address, when relaxed aliasing.
I am not completely certain whether the test case is portable. Could
someone take a look?
Bootstrapped and tested x86, x86-64 and ppc.
Diego.
PR tree-optimization/17252
* tree-ssa-alias.c (may_alias_p): Don't assume that a
pointer may not point to itself when using relaxed
aliasing rules.
testsuite/ChangeLog:
PR tree-optimization/17252
* gcc.c-torture/execute/pr17252.c: New test.
Index: tree-ssa-alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-alias.c,v
retrieving revision 2.34
diff -d -c -p -u -r2.34 tree-ssa-alias.c
--- tree-ssa-alias.c 14 Sep 2004 22:45:53 -0000 2.34
+++ tree-ssa-alias.c 15 Sep 2004 01:27:36 -0000
@@ -1558,7 +1558,8 @@ may_alias_p (tree ptr, HOST_WIDE_INT mem
for PTR's alias set here, not its pointed-to type. We also can't
do this check with relaxed aliasing enabled. */
if (POINTER_TYPE_P (TREE_TYPE (var))
- && var_alias_set != 0)
+ && var_alias_set != 0
+ && mem_alias_set != 0)
{
HOST_WIDE_INT ptr_alias_set = get_alias_set (ptr);
if (ptr_alias_set == var_alias_set)
Index: testsuite/gcc.c-torture/execute/pr17252.c
===================================================================
RCS file: testsuite/gcc.c-torture/execute/pr17252.c
diff -N testsuite/gcc.c-torture/execute/pr17252.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/execute/pr17252.c 15 Sep 2004 01:27:38 -0000
@@ -0,0 +1,24 @@
+/* PR 17252. When a char * pointer P takes its own address, storing
+ into *P changes P itself. */
+
+char *a;
+
+main ()
+{
+ int i;
+
+ /* Make 'a' point to itself. */
+ a = (char *)&a;
+
+ /* Assign NULL to 'a' byte by byte. */
+ for (i = 0; i < sizeof(char *); i++)
+ a[i] = 0;
+
+ /* If a's memory tag does not contain 'a' in its alias set, we will
+ think that this predicate is superfluous and change it to
+ 'if (1)'. */
+ if (a == (char *)&a)
+ abort ();
+
+ return 0;
+}