Bug 69516 - [5/6 regression] infinite recursion on a VLA with excess initializer elements in constexpr function
Summary: [5/6 regression] infinite recursion on a VLA with excess initializer elements...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 5.4
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks: C++VLA
  Show dependency treegraph
 
Reported: 2016-01-27 16:22 UTC by Martin Sebor
Modified: 2019-12-01 01:55 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-01-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2016-01-27 16:22:45 UTC
GCC gets itself into infinite recursion compiling the following test case derived derived from the one shown in the discussion of a patch for bug 69496 (https://gcc.gnu.org/ml/gcc-patches/2016-01/msg02098.html).  See also bug 69509 (which might be the same problem.)

The same problem exists in 5.x.  4.9.3 doesn't suffer from it because it doesn't implement the more relaxed C++ 14 constexpr rules and rejects constexpr functions that consist of more than just a return statement.

$ (cat t.c && ulimit -t 10 && /home/msebor/build/gcc-trunk-svn/gcc/xgcc -B/home/msebor/build/gcc-trunk-svn/gcc  -Wall -Wextra -Wpedantic -std=c++14 -xc++ t.c)
constexpr int foo (int n)
{
     int a[n] = { 1, 2, 3, 4, 5, 6 };
     int z = 0;
     for (unsigned i = 0; i < 3; ++i)
       z += a[i];
     return z;
}

int main ()
{
   constexpr int n = foo (3);
   __builtin_printf ("%d\n", n);
}
t.c: In function ‘constexpr int foo(int)’:
t.c:3:13: warning: ISO C++ forbids variable length array ‘a’ [-Wvla]
      int a[n] = { 1, 2, 3, 4, 5, 6 };
             ^
xgcc: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Marek Polacek 2016-01-27 16:30:18 UTC
Confirmed.
Comment 2 Marek Polacek 2016-01-28 13:14:49 UTC
Examining.
Comment 3 Marek Polacek 2016-01-29 09:25:47 UTC
Author: mpolacek
Date: Fri Jan 29 09:25:14 2016
New Revision: 232969

URL: https://gcc.gnu.org/viewcvs?rev=232969&root=gcc&view=rev
Log:
	PR c++/69509
	PR c++/69516
	* constexpr.c (cxx_eval_array_reference): Give the "array subscript
	out of bound" error earlier.
	* init.c (build_vec_init): Change NE_EXPR into GT_EXPR.  Update the
	commentary.

	* g++.dg/ext/constexpr-vla2.C: New test.
	* g++.dg/ext/constexpr-vla3.C: New test.
	* g++.dg/ubsan/vla-1.C: Remove dg-shouldfail.

Added:
    trunk/gcc/testsuite/g++.dg/ext/constexpr-vla2.C
    trunk/gcc/testsuite/g++.dg/ext/constexpr-vla3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/ubsan/vla-1.C
Comment 4 Marek Polacek 2016-01-29 09:37:35 UTC
Fixed for GCC 6.