aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/gimplify.c9
-rw-r--r--gcc/testsuite/ChangeLog10
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr48814-1.c18
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr48814-2.c18
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/assign-1.c12
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/assign-2.c13
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/assign-3.c24
8 files changed, 108 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c827218..e18d220 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,4 +1,12 @@
2012-03-16 Richard Guenther <rguenther@suse.de>
+ Kai Tietz <ktietz@redhat.com>
+
+ PR middle-end/48814
+ * gimplify.c (gimplify_self_mod_expr): Evaluate postfix
+ side-effects completely in the pre-queue and use a temporary
+ for the result.
+
+2012-03-16 Richard Guenther <rguenther@suse.de>
* stor-layout.c (finish_bitfield_representative): Fall back
to the conservative maximum size if we cannot compute the
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 07eb8fd..3c41294 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -2265,17 +2265,18 @@ gimplify_self_mod_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
arith_code = POINTER_PLUS_EXPR;
}
- t1 = build2 (arith_code, TREE_TYPE (*expr_p), lhs, rhs);
-
if (postfix)
{
- gimplify_assign (lvalue, t1, orig_post_p);
+ tree t2 = get_initialized_tmp_var (lhs, pre_p, NULL);
+ t1 = build2 (arith_code, TREE_TYPE (*expr_p), t2, rhs);
+ gimplify_assign (lvalue, t1, pre_p);
gimplify_seq_add_seq (orig_post_p, post);
- *expr_p = lhs;
+ *expr_p = t2;
return GS_ALL_DONE;
}
else
{
+ t1 = build2 (arith_code, TREE_TYPE (*expr_p), lhs, rhs);
*expr_p = build2 (MODIFY_EXPR, TREE_TYPE (lvalue), lvalue, t1);
return GS_OK;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index eddbfac..ba1e455 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,4 +1,14 @@
2012-03-16 Richard Guenther <rguenther@suse.de>
+ Kai Tietz <ktietz@redhat.com>
+
+ PR middle-end/48814
+ * gcc.c-torture/execute/pr48814-1.c: New test.
+ * gcc.c-torture/execute/pr48814-2.c: New test.
+ * gcc.dg/tree-ssa/assign-1.c: New test.
+ * gcc.dg/tree-ssa/assign-2.c: New test.
+ * gcc.dg/tree-ssa/assign-3.c: New test.
+
+2012-03-16 Richard Guenther <rguenther@suse.de>
* gnat.dg/specs/pack7.ads: New testcase.
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr48814-1.c b/gcc/testsuite/gcc.c-torture/execute/pr48814-1.c
new file mode 100644
index 0000000..452aaab
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr48814-1.c
@@ -0,0 +1,18 @@
+extern void abort (void);
+
+int arr[] = {1,2,3,4};
+int count = 0;
+
+int __attribute__((noinline))
+incr (void)
+{
+ return ++count;
+}
+
+int main()
+{
+ arr[count++] = incr ();
+ if (count != 2 || arr[count] != 3)
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr48814-2.c b/gcc/testsuite/gcc.c-torture/execute/pr48814-2.c
new file mode 100644
index 0000000..9eea328
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr48814-2.c
@@ -0,0 +1,18 @@
+extern void abort (void);
+
+int arr[] = {1,2,3,4};
+int count = 0;
+
+int
+incr (void)
+{
+ return ++count;
+}
+
+int main()
+{
+ arr[count++] = incr ();
+ if (count != 2 || arr[count] != 3)
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/assign-1.c b/gcc/testsuite/gcc.dg/tree-ssa/assign-1.c
new file mode 100644
index 0000000..f95f03f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/assign-1.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+volatile int count;
+void bar(int);
+void foo()
+{
+ bar(count++);
+}
+
+/* { dg-final { scan-tree-dump-times "count =" 1 "optimized"} } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/assign-2.c b/gcc/testsuite/gcc.dg/tree-ssa/assign-2.c
new file mode 100644
index 0000000..47c3822
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/assign-2.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+volatile int count;
+int arr[4];
+void foo()
+{
+ arr[count++] = 0;
+}
+
+/* { dg-final { scan-tree-dump-times "count =" 1 "optimized"} } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/assign-3.c b/gcc/testsuite/gcc.dg/tree-ssa/assign-3.c
new file mode 100644
index 0000000..e5426d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/assign-3.c
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fdump-tree-gimple" } */
+
+extern void abort (void);
+struct S { int i; };
+struct S arr[32];
+volatile int count = 0;
+
+struct S __attribute__((noinline))
+incr ()
+{
+ ++count;
+}
+
+int main()
+{
+ arr[count++] = incr ();
+ if (count != 2)
+ abort ();
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump-times " = count;" 3 "gimple" } } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */