[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-08 Thread nathan at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

Nathan Sidwell  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #15 from Nathan Sidwell  ---
Fixed on 5, 6 & HEAD

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-08 Thread nathan at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

--- Comment #14 from Nathan Sidwell  ---
Author: nathan
Date: Thu Dec  8 19:27:32 2016
New Revision: 243457

URL: https://gcc.gnu.org/viewcvs?rev=243457&root=gcc&view=rev
Log:
PR c++/78551
* constexpr.c (extract_string_elt): New.  Broken out of ...
(cxx_eval_array_reference): ... here.  Call it.
(cxx_eval_store_expression): Convert init by STRING_CST into
CONSTRUCTOR, if needed.

PR c++/78551
* g++.dg/cpp1y/pr78551.C: New.

Added:
branches/gcc-5-branch/gcc/testsuite/g++.dg/cpp1y/pr78551.C
Modified:
branches/gcc-5-branch/gcc/cp/ChangeLog
branches/gcc-5-branch/gcc/cp/constexpr.c
branches/gcc-5-branch/gcc/testsuite/ChangeLog

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-08 Thread nathan at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

--- Comment #13 from Nathan Sidwell  ---
Author: nathan
Date: Thu Dec  8 18:37:03 2016
New Revision: 243451

URL: https://gcc.gnu.org/viewcvs?rev=243451&root=gcc&view=rev
Log:
PR c++/78551
* constexpr.c (extract_string_elt): New.  Broken out of ...
(cxx_eval_array_reference): ... here.  Call it.
(cxx_eval_store_expression): Convert init by STRING_CST into
CONSTRUCTOR, if needed.

PR c++/78551
* g++.dg/cpp1y/pr78551.C: New.

Added:
branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp1y/pr78551.C
Modified:
branches/gcc-6-branch/gcc/cp/ChangeLog
branches/gcc-6-branch/gcc/cp/constexpr.c
branches/gcc-6-branch/gcc/testsuite/ChangeLog

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-08 Thread nathan at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

--- Comment #12 from Nathan Sidwell  ---
Author: nathan
Date: Thu Dec  8 18:34:04 2016
New Revision: 243448

URL: https://gcc.gnu.org/viewcvs?rev=243448&root=gcc&view=rev
Log:
PR c++/78551
* constexpr.c (extract_string_elt): New.  Broken out of ...
(cxx_eval_array_reference): ... here.  Call it.
(cxx_eval_store_expression): Convert init by STRING_CST into
CONSTRUCTOR, if needed.

PR c++/78551
* g++.dg/cpp1y/pr78551.C: New.

Added:
trunk/gcc/testsuite/g++.dg/cpp1y/pr78551.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/constexpr.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-07 Thread nathan at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

Nathan Sidwell  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-07 Thread nathan at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

--- Comment #11 from Nathan Sidwell  ---
Created attachment 40276
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40276&action=edit
non-union crash

Union is not necessary to trigger the ICE.  All we need is to initialize a char
array with a string constant, and then try and write an element of the array.

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-06 Thread vlad at petric dot cc
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

--- Comment #10 from Vlad Petric  ---
Could someone boost its priority? Given that gcc segfaults with valid code (see
newest example/attachment), I believe it's worth a P1.

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-02 Thread vlad at petric dot cc
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

--- Comment #9 from Vlad Petric  ---
Created attachment 40235
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40235&action=edit
Compliant code that segfaults the compiler

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-02 Thread vlad at petric dot cc
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

--- Comment #8 from Vlad Petric  ---
(In reply to Vlad Petric from comment #7)
> Ok, so the example that I started this bug with is not standard compliant
> because it initialized different elements in a union with the constexpr
> constructor.
> 
> The following does just one. I believe that the following is
> standard-compliant code (though obviously I could be wrong)
> 
> And it generates a segfault.
> 
> struct A {
>   union {
> long s;
> char d[4];
>   };
>   constexpr A (char x) : d("") { d[0] = x; }
> };
> 
> A a{'a'};

clang 3.8/4.0 have no problem with the above code.

Personally I think that we should change the main attachment and the tag - to
segfault on valid code (worse than ICE ...).

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-01 Thread vlad at petric dot cc
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

--- Comment #7 from Vlad Petric  ---
Ok, so the example that I started this bug with is not standard compliant
because it initialized different elements in a union with the constexpr
constructor.

The following does just one. I believe that the following is standard-compliant
code (though obviously I could be wrong)

And it generates a segfault.

struct A {
  union {
long s;
char d[4];
  };
  constexpr A (char x) : d("") { d[0] = x; }
};

A a{'a'};

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-12-01 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P2

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-11-28 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org

--- Comment #6 from Jakub Jelinek  ---
Actually, no array is needed,
struct A { union { short s; char d[2]; }; constexpr A (char x) : s(0x2020) {
d[0] = x; } };
A c { 'a' };
ICEs as well.  The C++ FE creates a CONSTRUCTOR that contains both initializer
for s as well for d[0], that obviously can't be emitted properly.
Before Nathan's fix, GCC just emitted garbage:
.type   c, @object
.size   c, 2
c:
.value  8224
.byte   97
.zero   1
i.e. c actually didn't have size 2, but 4.
struct A { union { short s; char d[2]; }; constexpr A (const char x) :
s(0x2020) { d[0] = x; } };
constexpr A c { 'a' };
const A *p = &c;
is rejected by clang++, because of:
assignment to member 'd' of union with active member 's' is not allowed in a
constant expression
g++ still ICEs.
Finally:
struct A { union { short s; char d[2]; }; constexpr A (const char x) : d{0,0} {
d[0] = x; d[1] = x; } };
constexpr A c { 'a' };
const A *p = &c;
is accepted by both compilers and looks good.

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-11-28 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek  ---
Reduced testcase:
struct A { union { long s; char d[1]; }; constexpr A (char x) : s(0) { d[0] =
x; } };
struct B { A b[2]; };
B c { 'a', 'b' };

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-11-28 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

Martin Liška  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-11-28
 CC||marxin at gcc dot gnu.org,
   ||nathan at gcc dot gnu.org
  Known to work||5.3.0
 Ever confirmed|0   |1

--- Comment #4 from Martin Liška  ---
Confirmed, started on trunk with r234636. It was also backported to GCC 5.4.0.

[Bug c++/78551] [5/6/7 Regression] Internal compiler error with constexpr initialization of union

2016-11-28 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78551

Richard Biener  changed:

   What|Removed |Added

   Keywords||ice-on-invalid-code
  Known to work||4.9.4
   Target Milestone|--- |5.5
Summary|Internal compiler error |[5/6/7 Regression] Internal
   |with constexpr  |compiler error with
   |initialization of union |constexpr initialization of
   ||union
  Known to fail||5.4.0, 6.2.0, 7.0

--- Comment #3 from Richard Biener  ---
ICEs in

t.C:20:53: internal compiler error: in output_constructor_regular_field, at
varasm.c:4968
 constexpr std::array array({"long", "longer"});
 ^

GCC 4.9 rejects it, so does clang++:

> clang++ t.C -S -std=gnu++14
t.C:20:28: error: constexpr variable 'array' must be initialized by a constant
  expression
constexpr std::array array({"long", "longer"});
   ^
t.C:14:22: note: assignment to member 'buff' of union with active member 's' is
  not allowed in a constant expression
  buff[i] = str[i];
  ^
t.C:20:35: note: in call to 'A(&"long"[0])'
constexpr std::array array({"long", "longer"});
  ^
1 error generated.


Backtrace from GCC 6 branch head:

> /space/rguenther/install/gcc-6.2/bin/g++ t.ii -B /abuild/rguenther/gcc6-g/gcc
t.C:20:53: internal compiler error: in output_constructor_regular_field, at
varasm.c:4968
 constexpr std::array array({"long", "longer"});
 ^
0x14386b5 output_constructor_regular_field
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:4968
0x14394c1 output_constructor
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:5276
0x1437f16 output_constant
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:4803
0x143897b output_constructor_regular_field
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:5006
0x14394c1 output_constructor
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:5276
0x1437f16 output_constant
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:4803
0x143897b output_constructor_regular_field
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:5006
0x14394c1 output_constructor
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:5276
0x1437bd8 output_constant
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:4773
0x143897b output_constructor_regular_field
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:5006
0x14394c1 output_constructor
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:5276
0x1437f16 output_constant
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:4803
0x142f4d9 assemble_variable_contents
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:2062
0x142fe82 assemble_variable(tree_node*, int, int, int)
/space/rguenther/src/svn/gcc-6-branch/gcc/varasm.c:2238
0x1447096 varpool_node::assemble_decl()
/space/rguenther/src/svn/gcc-6-branch/gcc/varpool.c:582
0xbb40d9 output_in_order
/space/rguenther/src/svn/gcc-6-branch/gcc/cgraphunit.c:2231
0xbb4784 symbol_table::compile()
/space/rguenther/src/svn/gcc-6-branch/gcc/cgraphunit.c:2468
0xbb49c3 symbol_table::finalize_compilation_unit()
/space/rguenther/src/svn/gcc-6-branch/gcc/cgraphunit.c:2564
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.