[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 Bernd Edlinger changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #13 from Bernd Edlinger --- Fixed.
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 --- Comment #12 from Bernd Edlinger --- Author: edlinger Date: Mon Jan 7 17:08:51 2019 New Revision: 267653 URL: https://gcc.gnu.org/viewcvs?rev=267653=gcc=rev Log: PR c++/88261 PR c++/69338 PR c++/69696 PR c++/69697 * cp-tree.h (LOOKUP_ALLOW_FLEXARRAY_INIT): New flag value. * typeck2.c (digest_init_r): Raise an error for non-static initialization of a flexible array member. (process_init_constructor, massage_init_elt, process_init_constructor_array, process_init_constructor_record, process_init_constructor_union, process_init_constructor): Add the flags parameter and pass it thru. (store_init_value): Pass LOOKUP_ALLOW_FLEXARRAY_INIT parameter to digest_init_flags for static decls. gcc/testsuite: 2019-01-07 Bernd Edlinger PR c++/88261 PR c++/69338 PR c++/69696 PR c++/69697 * gcc.dg/array-6.c: Move from here ... * c-c++-common/array-6.c: ... to here and add some more test coverage. * g++.dg/pr69338.C: New test. * g++.dg/pr69697.C: Likewise. * g++.dg/ext/flexary32.C: Likewise. * g++.dg/ext/flexary3.C: Adjust test. * g++.dg/ext/flexary12.C: Likewise. * g++.dg/ext/flexary13.C: Likewise. * g++.dg/ext/flexary15.C: Likewise. * g++.dg/warn/Wplacement-new-size-1.C: Likewise. * g++.dg/warn/Wplacement-new-size-2.C: Likewise. * g++.dg/warn/Wplacement-new-size-6.C: Likewise. Added: trunk/gcc/testsuite/c-c++-common/array-6.c - copied, changed from r267652, trunk/gcc/testsuite/gcc.dg/array-6.c trunk/gcc/testsuite/g++.dg/ext/flexary32.C trunk/gcc/testsuite/g++.dg/pr69338.C trunk/gcc/testsuite/g++.dg/pr69697.C Removed: trunk/gcc/testsuite/gcc.dg/array-6.c Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cp-tree.h trunk/gcc/cp/typeck2.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/ext/flexary12.C trunk/gcc/testsuite/g++.dg/ext/flexary13.C trunk/gcc/testsuite/g++.dg/ext/flexary15.C trunk/gcc/testsuite/g++.dg/ext/flexary3.C trunk/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C trunk/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C trunk/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 Richard Biener changed: What|Removed |Added Keywords||ice-checking Priority|P3 |P1
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 Martin Sebor changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=69696 --- Comment #11 from Martin Sebor --- This looks related to pr69696.
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 --- Comment #10 from Bernd Edlinger --- Hmm, there are a few loose ends, where there is simply no decl. For instance in this example: /* PR c/5597 */ /* { dg-do compile } */ /* { dg-options "" } */ /* Verify that GCC forbids non-static initialization of flexible array members. */ struct str { int len; char s[]; }; struct str a = { 2, "a" }; void foo() { static struct str d = (struct str) { 2, "d" }; /* { dg-error "(non-static)|(near initialization)" } */ static struct str e = (struct str) { d.len, "e" }; /* { dg-error "(non-static)|(initialization)" } */ } $ g++ -S array-6.c array-6.c:14:47: error: non-static initialization of a flexible array member 14 | static struct str d = (struct str) { 2, "d" }; /* { dg-error "(non-static)|(near initialization)" } */ | ^ array-6.c:15:51: error: non-static initialization of a flexible array member 15 | static struct str e = (struct str) { d.len, "e" }; /* { dg-error "(non-static)|(initialization)" } */ | ^ the patch prints an error, but digest_init_r is called from finish_compound_literal: 2830 compound_literal = digest_init_flags (type, compound_literal, LOOKUP_NORMAL, 2831complain, NULL_TREE); So here it is impossible to tell which decl is going to be initialized, because this is called drectly from the parser (cp_parser_postfix_expression). However the C-FE does also not have a decl here, and I think I cannot do much about that: $ gcc -S array-6.c array-6.c: In function 'foo': array-6.c:14:43: error: non-static initialization of a flexible array member 14 | static struct str d = (struct str) { 2, "d" }; /* { dg-error "(non-static)|(near initialization)" } */ | ^~~ array-6.c:14:43: note: (near initialization for '(anonymous)') array-6.c:15:47: error: non-static initialization of a flexible array member 15 | static struct str e = (struct str) { d.len, "e" }; /* { dg-error "(non-static)|(initialization)" } */ | ^~~ array-6.c:15:47: note: (near initialization for '(anonymous)') array-6.c:15:25: error: initializer element is not constant 15 | static struct str e = (struct str) { d.len, "e" }; /* { dg-error "(non-static)|(initialization)" } */ | ^
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 --- Comment #9 from Jeffrey A. Law --- Thanks for running with this Bernd. My brain was too mushy last night to get anywhere. I agree that digest_init_r seems like the right place to try and address this problem. ISTM we could either add the DECL as a parameter or pass in some kind of state to indicate if it's automatic or static. I've got no strong opinion on which of those two approaches is best -- but Jason will have the final call here.
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 Bernd Edlinger changed: What|Removed |Added CC||bernd.edlinger at hotmail dot de --- Comment #8 from Bernd Edlinger --- Interesting: above patch adds an error in gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C where this is no ICE but only wrong code (I modified the test case a bit to demonstrate the Problem): $ cat Wplacement-new-size-1.C // PR c++/69662 - -Wplacement-new on allocated one element array members // Exercising the more permissive -Wplacement-new=1. The difference // between -Wplacement-new=1 is denoted by "no warning at level 1" in // the comments below. // { dg-do compile } // { dg-options "-Wno-pedantic -Wplacement-new=1" } typedef __typeof__ (sizeof 0) size_t; void* operator new (size_t, void *p) { return p; } void* operator new[] (size_t, void *p) { return p; } struct Ax { char n, a []; }; typedef __INT16_TYPE__ Int16; char xx[3]; void fAx2 () { Ax ax2 = { 1, { 2, 3 } }; new (ax2.a) Int16(123); __builtin_memcpy(xx, , 3); } int main() { fAx2 (); } $ g++ -O2 Wplacement-new-size-1.C $ ./a.out Segmentation fault (core dumped) $ g++ -S -O2 Wplacement-new-size-1.C $ cat Wplacement-new-size-1.s .file "Wplacement-new-size-1.C" .text .p2align 4 .globl _ZnwmPv .type _ZnwmPv, @function _ZnwmPv: .LFB0: .cfi_startproc movq%rsi, %rax ret .cfi_endproc .LFE0: .size _ZnwmPv, .-_ZnwmPv .p2align 4 .globl _ZnamPv .type _ZnamPv, @function _ZnamPv: .LFB5: .cfi_startproc movq%rsi, %rax ret .cfi_endproc .LFE5: .size _ZnamPv, .-_ZnamPv .section.rodata .LC0: .byte 1 .byte 2 .byte 3 .text .p2align 4 .globl _Z4fAx2v .type _Z4fAx2v, @function _Z4fAx2v: .LFB2: .cfi_startproc movzbl .LC0(%rip), %eax movb%al, -1(%rsp) movl$123, %eax movw%ax, (%rsp) movzwl -1(%rsp), %eax movw%ax, xx(%rip) movzbl 1(%rsp), %eax movb%al, xx+2(%rip) ret .cfi_endproc .LFE2: .size _Z4fAx2v, .-_Z4fAx2v .section.text.startup,"ax",@progbits .p2align 4 .globl main .type main, @function main: .LFB3: .cfi_startproc movzbl .LC0(%rip), %eax movb%al, -1(%rsp) movl$123, %eax movw%ax, (%rsp) movzwl -1(%rsp), %eax movw%ax, xx(%rip) movzbl 1(%rsp), %eax movb%al, xx+2(%rip) xorl%eax, %eax ret .cfi_endproc .LFE3: .size main, .-main .globl xx .bss .type xx, @object .size xx, 3 xx: .zero 3 .ident "GCC: (GNU) 9.0.0 20181209 (experimental)" .section.note.GNU-stack,"",@progbits So Ax2 has actually only 1 Byte space on the stack, and "new (ax2.a) Int16(123);" overwrites the return stack
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 --- Comment #7 from Bernd Edlinger --- Created attachment 45238 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45238=edit untested patch
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 --- Comment #6 from Bernd Edlinger --- (In reply to Jeffrey A. Law from comment #5) > Right, but we're not supposed to ICE, even on invalid code. Yes, ideed. I think what would be needed is adding this C-error to the C++FE: array-6.c: In function 'foo': array-6.c:12:23: error: non-static initialization of a flexible array member 12 | struct str b = { 2, "b" }; | ^~~ array-6.c:12:23: note: (near initialization for 'b') the error depends on TREE_STATIC (decl); the data flow in the C-FE is just weird, see "require_constant_value", a global value holds that bit... I believe the right place to add in the C++ FE is probably at where this C++ -Wpedantic warning is emitted, array-6.c:12:27: warning: initialization of a flexible array member [-Wpedantic] 12 | struct str b = { 2, "b" }; | ^ unfortunately that is in digest_init_r and that does not have access to TREE_STATIC (decl); In case the object is static, that should be a warning, but in case of an automatic object it should be a error, that would prevent the ICE. Either one need to a static variable like the C-FE or pass the decl from store_init_value and probably other places too into the digest_init and digest_init_flags. Well, it will probably be better to add an additional decl parameter. Thoughts?
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 Jeffrey A. Law changed: What|Removed |Added CC||law at redhat dot com --- Comment #5 from Jeffrey A. Law --- Right, but we're not supposed to ICE, even on invalid code.
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 --- Comment #4 from Bernd Edlinger --- For G++ versions, where this was accepted with -fpermissive, the code was wrong: struct str { int len; char s[]; }; int foo() { struct str b = { 2, "b" }; return sizeof(b); } => movl$4, %eax ret
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 --- Comment #3 from Martin Sebor --- The ICE only affects C++. G++ 8 and prior accept the code with just a pedantic warning: $ cat pr88261.C && gcc -O2 -S -Wall -Wextra -Wpedantic pr88261.C struct str { int len; char s[]; }; void foo() { struct str c = { 2, "c" }; } pr88261.C:1:30: warning: ISO C++ forbids flexible array member ‘s’ [-Wpedantic] struct str { int len; char s[]; }; ^ pr88261.C: In function ‘void foo()’: pr88261.C:5:27: warning: initialization of a flexible array member [-Wpedantic] struct str c = { 2, "c" }; ^ pr88261.C:5:14: warning: unused variable ‘c’ [-Wunused-variable] struct str c = { 2, "c" }; ^ But G++ rejects the code if it's changed like below so the C++ front-end should probably reject it regardless of whether or not the struct is used. int foo() { struct str c = { 2, "c" }; return c.s[0]; } pr88261.C:1:30: warning: ISO C++ forbids flexible array member ‘s’ [-Wpedantic] struct str { int len; char s[]; }; ^ pr88261.C: In function ‘int foo()’: pr88261.C:5:27: warning: initialization of a flexible array member [-Wpedantic] struct str c = { 2, "c" }; ^ pr88261.C:5:14: error: invalid use of array with unspecified bounds struct str c = { 2, "c" }; ^ pr88261.C:5:14: error: invalid use of array with unspecified bounds The again, G++ 5 accepts the modified example above with -fpermissive: pr88261.C:5:27: warning: initializer-string for array of chars is too long [-fpermissive] struct str c = { 2, "c" }; ^
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 --- Comment #2 from Jakub Jelinek --- Started with r264147.
[Bug c++/88261] [9 Regression] ICE: verify_gimple failed (error: non-trivial conversion at assignment)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88261 Richard Biener changed: What|Removed |Added Keywords||accepts-invalid Status|UNCONFIRMED |NEW Last reconfirmed||2018-11-29 Target Milestone|--- |9.0 Ever confirmed|0 |1 --- Comment #1 from Richard Biener --- Confirmed. GCC 8 diagnoses it as array-6.c: In function ‘void foo()’: array-6.c:15:14: error: invalid use of array with unspecified bounds struct str c = { 2, "c" }; /* { dg-error "(non-static)|(near initialization)" } */ ^ array-6.c:15:14: error: invalid use of array with unspecified bounds array-6.c:16:14: error: invalid use of array with unspecified bounds struct str d = (struct str) { 2, "d" }; /* { dg-error "(non-static)|(near initialization)" } */ ^ array-6.c:16:14: error: invalid use of array with unspecified bounds array-6.c:17:14: error: invalid use of array with unspecified bounds struct str e = (struct str) { d.len, "e" }; /* { dg-error "(non-static)|(initialization)" } */ ^ array-6.c:17:14: error: invalid use of array with unspecified bounds