]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/49644 (post-increment of promoted operand is incorrect.)
authorJakub Jelinek <jakub@redhat.com>
Tue, 19 Jul 2011 13:08:33 +0000 (15:08 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 19 Jul 2011 13:08:33 +0000 (15:08 +0200)
Backport from mainline
2011-07-07  Jakub Jelinek  <jakub@redhat.com>

PR c/49644
* typeck.c (cp_build_binary_op): For MULT_EXPR and TRUNC_DIV_EXPR with
one non-complex and one complex argument, call save_expr on both
operands.

* g++.dg/torture/pr49644.C: New test.

From-SVN: r176457

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr49644.C [new file with mode: 0644]

index 69dcf301052f0dd4e254de1af716217fea48b6e8..cbe8bc3b16cb18f778b9c90b81c1049089a41d8d 100644 (file)
@@ -1,3 +1,13 @@
+2011-07-19  Jakub Jelinek  <jakub@redhat.com>
+
+       Backport from mainline
+       2011-07-07  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/49644
+       * typeck.c (cp_build_binary_op): For MULT_EXPR and TRUNC_DIV_EXPR with
+       one non-complex and one complex argument, call save_expr on both
+       operands.
+
 2011-06-23  Jason Merrill  <jason@redhat.com>
 
        PR c++/49440
index 8ccb32d93c510da329e6976c90da7f5505f8b91f..7cdcee939fe418558f24c32a076ecd0e5dbccdc5 100644 (file)
@@ -4297,6 +4297,7 @@ cp_build_binary_op (location_t location,
                {
                case MULT_EXPR:
                case TRUNC_DIV_EXPR:
+                 op1 = save_expr (op1);
                  imag = build2 (resultcode, real_type, imag, op1);
                  /* Fall through.  */
                case PLUS_EXPR:
@@ -4315,6 +4316,7 @@ cp_build_binary_op (location_t location,
              switch (code)
                {
                case MULT_EXPR:
+                 op0 = save_expr (op0);
                  imag = build2 (resultcode, real_type, op0, imag);
                  /* Fall through.  */
                case PLUS_EXPR:
index d758a7612e64085b6a8cf3726cea55721bdd138c..aa95f8a2fed0d1ed3fe97d29c8fd8090f09ae11e 100644 (file)
@@ -3,6 +3,9 @@
        Backport from mainline
        2011-07-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/49644
+       * g++.dg/torture/pr49644.C: New test.
+
        PR c/49644
        * gcc.c-torture/execute/pr49644.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/torture/pr49644.C b/gcc/testsuite/g++.dg/torture/pr49644.C
new file mode 100644 (file)
index 0000000..5fb82e0
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c/49644
+// { dg-do run }
+
+extern "C" void abort ();
+
+int
+main ()
+{
+  _Complex double a[12], *c = a, s = 3.0 + 1.0i;
+  double b[12] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, *d = b;
+  int i;
+  for (i = 0; i < 6; i++)
+    *c++ = *d++ * s;
+  if (c != a + 6 || d != b + 6)
+    abort ();
+  return 0;
+}