Bug 29091 - [4.0 Regression] vector constant not fully outputed
Summary: [4.0 Regression] vector constant not fully outputed
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.1.2
Assignee: Jakub Jelinek
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2006-09-14 22:58 UTC by Andrew Pinski
Modified: 2007-02-03 20:16 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.2.3 4.1.2 4.2.0
Known to fail: 3.3.3 3.4.0 4.0.0 4.1.0 4.1.1
Last reconfirmed: 2006-10-04 16:28:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2006-09-14 22:58:12 UTC
Testcase:
#include <stdlib.h>
__attribute__((vector_size(16))) int a = {1, 2};

int main(void)
{
  int *b = (int*)&a;
  if (b[0] != 1)
    abort ();
  if (b[1] != 2)
    abort ();
  if (b[2] != 0)
    abort ();
  if (b[3] != 0)
    abort ();
  return 0;
}

----
The VECTOR_CST has only two elements.
Comment 1 Andrew Pinski 2006-09-14 23:07:17 UTC
The C++ front-end produces:
a:
        .long   1
        .long   2
        .zero   8
While the C front-end does not have .zero there.
Comment 2 Andrew Pinski 2006-09-15 05:35:46 UTC
3.2.3 on x86 with -msse (since we did not have generic vectors until 3.3) works.
And 3.3.3 fails (even with -msse).
Note a better testcase is something like:
#include <stdlib.h>
__attribute__((vector_size(16))) int a = {1, 2};
int c = 1;
__attribute__((vector_size(16))) int b = {1, 2};

int main(void)
{
  int *b = (int*)&a;
  if (b[0] != 1)
    abort ();
  if (b[1] != 2)
    abort ();
  if (b[2] != 0)
    abort ();
  if (b[3] != 0)
    abort ();
  return 0;
}
Comment 3 Andrew Pinski 2006-09-17 01:23:24 UTC
This was caused by:
2003-04-01  Aldy Hernandez  <aldyh@redhat.com>

        * testsuite/gcc.c-torture/execute/simd-3.c: New.

        * expr.c (expand_expr): Handle VECTOR_CST.
        (const_vector_from_tree): New.

        * varasm.c (output_constant): Handle VECTOR_CST.

        * c-typeck.c (digest_init): Build a vector constant from a
        VECTOR_TYPE.


Specificly the digest_init change, though output_constant does not check make sure we have the right number of elements either.  build_vector does not either.
Comment 4 Jakub Jelinek 2006-10-06 07:16:00 UTC
Subject: Bug 29091

Author: jakub
Date: Fri Oct  6 07:15:48 2006
New Revision: 117481

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117481
Log:
	PR c/29091
	* varasm.c (output_constant): If TREE_VECTOR_CST_ELTS chain is shorter than
	the number of vector elements fill the rest with zeros.

	* gcc.dg/pr29091.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr29091.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/varasm.c

Comment 5 Jakub Jelinek 2006-10-06 07:42:56 UTC
Fixed on the trunk so far.
Comment 6 Jakub Jelinek 2006-10-16 09:58:59 UTC
Subject: Bug 29091

Author: jakub
Date: Mon Oct 16 09:58:48 2006
New Revision: 117779

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117779
Log:
	PR c/29091
	* varasm.c (output_constant): If TREE_VECTOR_CST_ELTS chain is shorter than
	the number of vector elements fill the rest with zeros.

	* gcc.dg/pr29091.c: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/pr29091.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/varasm.c

Comment 7 Gabriel Dos Reis 2007-02-03 20:16:03 UTC
Fixed in GCC-4.1.2.