#include <stdio.h> #include <complex.h> int main(int argc, char *argv[]) { double data[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0},*d; double complex *c, s = 3.0 + 0.0I; int i; d=data; for (i = 0; i<6; i++) { printf("c(%p), d(%p)=%lf\n",c,d,*d); *c++ = *d++ * s; } return 0; } With gcc 4.4.5 (compiles without warnings with -Wall): c(0x7fff16e86a00), d(0x7fff16e868d0)=1.000000 c(0x7fff16e86a10), d(0x7fff16e868d8)=2.000000 c(0x7fff16e86a20), d(0x7fff16e868e0)=3.000000 c(0x7fff16e86a30), d(0x7fff16e868e8)=4.000000 c(0x7fff16e86a40), d(0x7fff16e868f0)=5.000000 c(0x7fff16e86a50), d(0x7fff16e868f8)=6.000000 With gcc 4.5.1 and 4.6.0: c(0x7fff5411f2f0), d(0x7fff5411f1c0)=1.000000 c(0x7fff5411f300), d(0x7fff5411f1d0)=3.000000 c(0x7fff5411f310), d(0x7fff5411f1e0)=5.000000 c(0x7fff5411f320), d(0x7fff5411f1f0)=0.000000 c(0x7fff5411f330), d(0x7fff5411f200)=0.000000 c(0x7fff5411f340), d(0x7fff5411f210)=0.000000 It appears that the right hand side pointer is being incremented at the rate of its promoted size. If you remove the " * s" from the increment line, the code works as expected. Same problem with 32-bit and 64-bit machines.
May only apply to complex variables. I can't reproduce with promotion of float to double.
The frontend generates *c++ = COMPLEX_EXPR <*d++ * REALPART_EXPR <SAVE_EXPR <s>>, *d++ * IMAGPART_EXPR <SAVE_EXPR <s>>>; and thus increments d twice.
The testcase looks wrong though, I don't see c being initialized anywhere.
Yeah, I screwed that up. But it doesn't make any difference to the problem. This should be correct though. #include <stdio.h> #include <complex.h> int main(int argc, char *argv[]) { double data[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0},*d; double complex ddata[6], *c, s = 3.0; int i; d=data; c=ddata; for (i = 0; i<6; i++) { printf("c(%p), d(%p)=%f\n",c,d,*d); *c++ = *d++ * s; } return 0; }
Created attachment 24704 [details] gcc47-pr49644.patch Untested fix.
I am on vacation and will be out of the office until Thursay, July 21st. Your message has been saved and I will respond if needed when I return. If this is an urgent CoRA computing issue, please send email to coracomputer@cora.nwra.com. Cheers, Orion -- Orion Poplawski Technical Manager 303-415-9701 x222 NWRA/CoRA Division FAX: 303-415-9702 3380 Mitchell Lane orion@cora.nwra.com Boulder, CO 80301 http://www.cora.nwra.com
Author: jakub Date: Thu Jul 7 19:11:27 2011 New Revision: 176004 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176004 Log: PR c/49644 * c-typeck.c (build_binary_op): For MULT_EXPR and TRUNC_DIV_EXPR with one non-complex and one complex argument, call c_save_expr on both operands. * gcc.c-torture/execute/pr49644.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr49644.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-typeck.c trunk/gcc/testsuite/ChangeLog
Author: jakub Date: Thu Jul 7 19:14:38 2011 New Revision: 176005 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176005 Log: PR c/49644 * c-typeck.c (build_binary_op): For MULT_EXPR and TRUNC_DIV_EXPR with one non-complex and one complex argument, call c_save_expr on both operands. * gcc.c-torture/execute/pr49644.c: New test. Added: branches/gcc-4_6-branch/gcc/testsuite/gcc.c-torture/execute/pr49644.c Modified: branches/gcc-4_6-branch/gcc/ChangeLog branches/gcc-4_6-branch/gcc/c-typeck.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Fixed for C in 4.6+ so far, C++ patch is waiting for review.
Author: jakub Date: Thu Jul 7 19:41:55 2011 New Revision: 176006 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176006 Log: 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. Added: trunk/gcc/testsuite/g++.dg/torture/pr49644.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/typeck.c trunk/gcc/testsuite/ChangeLog
Author: jakub Date: Thu Jul 7 19:42:58 2011 New Revision: 176007 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176007 Log: 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. Added: branches/gcc-4_6-branch/gcc/testsuite/g++.dg/torture/pr49644.C Modified: branches/gcc-4_6-branch/gcc/cp/ChangeLog branches/gcc-4_6-branch/gcc/cp/typeck.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Author: jakub Date: Tue Jul 19 13:07:23 2011 New Revision: 176456 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176456 Log: Backport from mainline 2011-07-07 Jakub Jelinek <jakub@redhat.com> PR c/49644 * c-typeck.c (build_binary_op): For MULT_EXPR and TRUNC_DIV_EXPR with one non-complex and one complex argument, call c_save_expr on both operands. * gcc.c-torture/execute/pr49644.c: New test. Added: branches/gcc-4_5-branch/gcc/testsuite/gcc.c-torture/execute/pr49644.c Modified: branches/gcc-4_5-branch/gcc/ChangeLog branches/gcc-4_5-branch/gcc/c-typeck.c branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
Author: jakub Date: Tue Jul 19 13:08:33 2011 New Revision: 176457 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176457 Log: 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. Added: branches/gcc-4_5-branch/gcc/testsuite/g++.dg/torture/pr49644.C Modified: branches/gcc-4_5-branch/gcc/cp/ChangeLog branches/gcc-4_5-branch/gcc/cp/typeck.c branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
Fixed.
*** Bug 49933 has been marked as a duplicate of this bug. ***