diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-03-25 09:21:05 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-03-25 09:21:05 +0100 |
commit | 5f18995e23edc944af3a401d9d9d3320a9362652 (patch) | |
tree | ce7ae8f102f656e0a9d85013a496be79ba6ebb43 /gcc/testsuite/g++.dg | |
parent | 158cccea0d097d9f181bf4e35fdeb97865c960f7 (diff) | |
download | gcc-5f18995e23edc944af3a401d9d9d3320a9362652.zip gcc-5f18995e23edc944af3a401d9d9d3320a9362652.tar.gz gcc-5f18995e23edc944af3a401d9d9d3320a9362652.tar.bz2 |
varasm: Fix output_constructor where a RANGE_EXPR index needs to skip some elts [PR94303]
The following testcase is miscompiled, because output_constructor doesn't
output the initializer correctly. The FE creates {[1...2] = 9} in this
case, and we emit .long 9; long 9; .zero 8 instead of the expected
.zero 8; .long 9; .long 9. If the CONSTRUCTOR is {[1] = 9, [2] = 9},
output_constructor_regular_field has code to notice that the current
location (local->total_bytes) is smaller than the location we want to write
to (1*sizeof(elt)) and will call assemble_zeros to skip those. But
RANGE_EXPRs are handled by a different function which didn't do this,
so for RANGE_EXPRs we emitted them properly only if local->total_bytes
was always equal to the location where the RANGE_EXPR needs to start.
2020-03-25 Jakub Jelinek <jakub@redhat.com>
PR middle-end/94303
* varasm.c (output_constructor_array_range): If local->index
RANGE_EXPR doesn't start at the current location in the constructor,
skip needed number of bytes using assemble_zeros or assert we don't
go backwards.
PR middle-end/94303
* g++.dg/torture/pr94303.C: New test.
Diffstat (limited to 'gcc/testsuite/g++.dg')
-rw-r--r-- | gcc/testsuite/g++.dg/torture/pr94303.C | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/torture/pr94303.C b/gcc/testsuite/g++.dg/torture/pr94303.C new file mode 100644 index 0000000..45b90a2 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr94303.C @@ -0,0 +1,17 @@ +// PR middle-end/94303 +// { dg-do run } + +struct A { + int d = 9; + A () = default; + A (int x) : d(x) {} + void foo () { if (d < 1) __builtin_abort (); } +}; + +A a[3] = { 1 }; + +int +main () +{ + a[2].foo (); +} |