This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PR 20933: prevent mixing read-only/writeable types when creating tags
- From: Diego Novillo <dnovillo at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 11 Apr 2005 18:12:31 -0400
- Subject: PR 20933: prevent mixing read-only/writeable types when creating tags
- Organization: Red Hat Canada
The alias analyzer was associating a type tag T of a read-only
type to a pointer P whose pointed-to type was not read-only.
By chance, the symbols in T's alias set were *all* of a read-only
type, so when we found an assignment:
*P = 47;
instead of creating V_MAY_DEFs for each of the symbols, we were
creating all VUSES. This is because the operand scanner
determined that since the symbols were read-only, they couldn't
be really modified by the store.
The operand scanner reasoning is correct, but the aliaser was
messing things up by associating a writeable tag to read-only
symbols.
Fixed with this patch. Also added checks in verify_ssa that
check for V_MAY_DEFs in store operations.
Bootstrapped and tested on ppc, x86, x86_64 and ia64.
Diego.
PR tree-optimization/20933
* tree-ssa-alias.c (compute_flow_insensitive_aliasing): Move
logic to reject aliases between read-only and writable
variables ...
(may_alias_p): ... here.
(get_tmt_for): Do not associate read-only tags to pointers
whose pointed-to type is not read-only.
* tree-ssa.c (verify_ssa): Check that memory stores have at
least one V_MAY_DEF or V_MUST_DEF.
testsuite/ChangeLog
PR tree-optimization/20933
* gcc.dg/tree-ssa/pr20933.c: New test.
Index: tree-ssa-alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-alias.c,v
retrieving revision 2.84
diff -d -u -p -r2.84 tree-ssa-alias.c
--- tree-ssa-alias.c 11 Apr 2005 20:15:33 -0000 2.84
+++ tree-ssa-alias.c 11 Apr 2005 22:03:43 -0000
@@ -1001,10 +1001,6 @@ compute_flow_insensitive_aliasing (struc
if (!tag_stored_p && !var_stored_p)
continue;
- if ((unmodifiable_var_p (tag) && !unmodifiable_var_p (var))
- || (unmodifiable_var_p (var) && !unmodifiable_var_p (tag)))
- continue;
-
if (may_alias_p (p_map->var, p_map->set, var, v_map->set))
{
subvar_t svars;
@@ -1719,6 +1715,16 @@ may_alias_p (tree ptr, HOST_WIDE_INT mem
return false;
}
+ /* If either MEM or VAR is a read-only global and the other one
+ isn't, then PTR cannot point to VAR. */
+ if ((unmodifiable_var_p (mem) && !unmodifiable_var_p (var))
+ || (unmodifiable_var_p (var) && !unmodifiable_var_p (mem)))
+ {
+ alias_stats.alias_noalias++;
+ alias_stats.simple_resolved++;
+ return false;
+ }
+
m_ann = var_ann (mem);
gcc_assert (m_ann->mem_tag_kind == TYPE_TAG);
@@ -2319,9 +2325,11 @@ get_tmt_for (tree ptr, struct alias_info
for (i = 0, tag = NULL_TREE; i < ai->num_pointers; i++)
{
struct alias_map_d *curr = ai->pointers[i];
- if (tag_set == curr->set)
+ tree curr_tag = var_ann (curr->var)->type_mem_tag;
+ if (tag_set == curr->set
+ && TYPE_READONLY (tag_type) == TYPE_READONLY (TREE_TYPE (curr_tag)))
{
- tag = var_ann (curr->var)->type_mem_tag;
+ tag = curr_tag;
break;
}
}
@@ -2356,6 +2364,10 @@ get_tmt_for (tree ptr, struct alias_info
pointed-to type. */
gcc_assert (tag_set == get_alias_set (tag));
+ /* If PTR's pointed-to type is read-only, then TAG's type must also
+ be read-only. */
+ gcc_assert (TYPE_READONLY (tag_type) == TYPE_READONLY (TREE_TYPE (tag)));
+
return tag;
}
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa.c,v
retrieving revision 2.87
diff -d -u -p -r2.87 tree-ssa.c
--- tree-ssa.c 9 Apr 2005 16:43:30 -0000 2.87
+++ tree-ssa.c 11 Apr 2005 22:03:43 -0000
@@ -707,16 +707,37 @@ verify_ssa (bool check_modified_stmt)
goto err;
}
+ if (TREE_CODE (stmt) == MODIFY_EXPR
+ && TREE_CODE (TREE_OPERAND (stmt, 0)) != SSA_NAME)
+ {
+ tree lhs, base_address;
- if (stmt_ann (stmt)->makes_aliased_stores
- && NUM_V_MAY_DEFS (STMT_V_MAY_DEF_OPS (stmt)) == 0)
+ lhs = TREE_OPERAND (stmt, 0);
+ base_address = get_base_address (lhs);
+
+ if (base_address
+ && SSA_VAR_P (base_address)
+ && NUM_V_MAY_DEFS (STMT_V_MAY_DEF_OPS (stmt)) == 0
+ && NUM_V_MUST_DEFS (STMT_V_MUST_DEF_OPS (stmt)) == 0)
{
- error ("Statement makes aliased stores, but has no V_MAY_DEFS");
+ error ("Statement makes a memory store, but has no "
+ "V_MAY_DEFS nor V_MUST_DEFS");
print_generic_stmt (stderr, stmt, TDF_VOPS);
goto err;
}
+ }
- FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES | SSA_OP_ALL_KILLS)
+
+ if (stmt_ann (stmt)->makes_aliased_stores
+ && NUM_V_MAY_DEFS (STMT_V_MAY_DEF_OPS (stmt)) == 0)
+ {
+ error ("Statement makes aliased stores, but has no V_MAY_DEFS");
+ print_generic_stmt (stderr, stmt, TDF_VOPS);
+ goto err;
+ }
+
+ FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
+ SSA_OP_ALL_USES | SSA_OP_ALL_KILLS)
{
op = USE_FROM_PTR (use_p);
if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)],
Index: testsuite/gcc.dg/tree-ssa/pr20933.c
===================================================================
RCS file: testsuite/gcc.dg/tree-ssa/pr20933.c
diff -N testsuite/gcc.dg/tree-ssa/pr20933.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/tree-ssa/pr20933.c 11 Apr 2005 22:03:49 -0000
@@ -0,0 +1,70 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern __SIZE_TYPE__ strlen (__const char *__s)
+ __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
+extern char *strcpy (char *__restrict __dest, __const char *__restrict __src)
+ __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
+extern char *getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
+extern int access (__const char *__name, int __type) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
+extern void * xmalloc (__SIZE_TYPE__) __attribute__ ((__malloc__));
+
+static __inline__ const char *
+try (const char *dir, const char *base)
+{
+ if (base != 0)
+ return base;
+ if (dir != 0
+ && access (dir, 4 | 2 | 1) == 0)
+ return dir;
+ return 0;
+}
+
+static const char tmp[] = { '/', 't', 'm', 'p', 0 };
+static const char usrtmp[] =
+{ '/', 'u', 's', 'r', '/', 't', 'm', 'p', 0 };
+static const char vartmp[] =
+{ '/', 'v', 'a', 'r', '/', 't', 'm', 'p', 0 };
+
+static char *memoized_tmpdir;
+char *
+choose_tmpdir (void)
+{
+ const char *base = 0;
+ char *tmpdir;
+ unsigned int len;
+
+ if (memoized_tmpdir)
+ return memoized_tmpdir;
+
+ base = try (getenv ("TMPDIR"), base);
+ base = try (getenv ("TMP"), base);
+ base = try (getenv ("TEMP"), base);
+
+
+ base = try ("/tmp", base);
+
+
+
+ base = try (vartmp, base);
+ base = try (usrtmp, base);
+ base = try (tmp, base);
+
+
+ if (base == 0)
+ base = ".";
+
+
+
+ len = strlen (base);
+ tmpdir = xmalloc (len + 2);
+ strcpy (tmpdir, base);
+ /* Alias analysis was associating read-only memory tags to pointers
+ that are not read-only. We would then not issue any V_MAY_DEF in
+ this store. */
+ tmpdir[len] = '/';
+ tmpdir[len+1] = '\0';
+
+ memoized_tmpdir = tmpdir;
+ return tmpdir;
+}