Hello, in file c-typeck.c, function build_binary_op, for mixed scalar-vector operations, there are 2 cases: stv_firstarg and stv_secondarg. The first one has: op0 = c_wrap_maybe_const (op0, true); while the second has: op0 = c_wrap_maybe_const (op1, true); I think the second one should read "op1 = ...", for symmetry. I haven't managed to come up with a testcase that runs this line of code :-(
Have you tried setting a breakpoint there when running: * gcc.c-torture/execute/scal-to-vec1.c: New test. * gcc.c-torture/execute/scal-to-vec2.c: New test. * gcc.c-torture/execute/scal-to-vec3.c: New test. * gcc.dg/scal-to-vec1.c: New test. * gcc.dg/scal-to-vec2.c: New test. But it could also happen that the code is dead. It may be that build_binary_op or its callers rearrange the operators so VECTOR*SCALAR is always handled as SCALAR*VECTOR?
(In reply to comment #1) > * gcc.dg/scal-to-vec2.c: New test. This one runs the problematic code, but since this is a compile-only test, it can't detect a problem. A variant that does fail: extern void abort (void); int f(void) { return 2; } unsigned int g(void) { return 5; } unsigned int h = 1; typedef unsigned int vec __attribute__((vector_size(16))); vec i = { 1, 2, 3, 4}; vec fv1(void) { return i + (h ? f() : g()); } vec fv2(void) { return (h ? f() : g()) + i; } int main(){ vec j = fv1(); if (j[0] != 3) abort(); } (it works ok with fv2)
Mine.
Author: rguenth Date: Mon Apr 23 10:20:05 2012 New Revision: 186696 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186696 Log: 2012-04-23 Richard Guenther <rguenther@suse.de> PR c/53060 * c-typeck.c (build_binary_op): Fix typo. * gcc.dg/pr53060.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/pr53060.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-typeck.c trunk/gcc/testsuite/ChangeLog
Author: rguenth Date: Mon Apr 23 10:24:14 2012 New Revision: 186698 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186698 Log: 2012-04-23 Richard Guenther <rguenther@suse.de> PR c/53060 * c-typeck.c (build_binary_op): Fix typo. * gcc.dg/pr53060.c: New testcase. Added: branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/pr53060.c Modified: branches/gcc-4_7-branch/gcc/ChangeLog branches/gcc-4_7-branch/gcc/c-typeck.c branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Fixed. Thanks for spotting.