Bug 53060 - Typo in build_binary_op for scalar-vector ops
Summary: Typo in build_binary_op for scalar-vector ops
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-21 12:08 UTC by Marc Glisse
Modified: 2012-04-23 10:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-04-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Glisse 2012-04-21 12:08:20 UTC
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 :-(
Comment 1 Manuel López-Ibáñez 2012-04-21 13:42:32 UTC
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?
Comment 2 Marc Glisse 2012-04-21 14:59:54 UTC
(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)
Comment 3 Richard Biener 2012-04-23 10:00:52 UTC
Mine.
Comment 4 Richard Biener 2012-04-23 10:20:13 UTC
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
Comment 5 Richard Biener 2012-04-23 10:24:25 UTC
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
Comment 6 Richard Biener 2012-04-23 10:36:28 UTC
Fixed.  Thanks for spotting.