Bug 69509 - [5/6 regression] infinite loop compiling a VLA in a recursive constexpr function
Summary: [5/6 regression] infinite loop compiling a VLA in a recursive constexpr function
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: ice-on-valid-code
Depends on:
Blocks: C++VLA
  Show dependency treegraph
 
Reported: 2016-01-27 03:26 UTC by Martin Sebor
Modified: 2019-12-01 01:55 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 5.3.0, 6.0
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 03:26:03 UTC
Current GCC trunk (6.0) as well as 5.1.0 loops indefinitely compiling the following quasi-legal C++ 11 code (loosely based on bug 69496).  Clang rejects the code because it doesn't accept initialized VLAs.

The same code compiles successfully with -Dconstexpr=''.

$ (cat t.c && ulimit -t 10 && /home/msebor/build/gcc-trunk-svn/gcc/xgcc -B/home/msebor/build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic -std=c++14 -xc++ t.c)
constexpr int foo (int n)
{
    int a [n] = { 0 };

    int z = a [0] + (n ? foo (n - 1) : 0);

    return z;
}

constexpr int i = foo (3);
t.c: In function ‘constexpr int foo(int)’:
t.c:3:13: warning: ISO C++ forbids variable length array ‘a’ [-Wvla]
     int a [n] = { 0 };
             ^
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:08 UTC
Confirmed.
Comment 2 Martin Sebor 2016-01-27 17:06:22 UTC
Marking this a 5/6 regression since ICE 4.9.3 rejects the code with the error below because it doesn't allow contexpr functions to have more than one (return) statement.

t.c: In function ‘constexpr int foo(int)’:
t.c:8:1: error: body of constexpr function ‘constexpr int foo(int)’ not a return-statement
 }
 ^
t.c: At global scope:
t.c:10:25: error: ‘constexpr int foo(int)’ called in a constant expression
 constexpr int i = foo (3);
                         ^
Comment 3 Marek Polacek 2016-01-28 14:34:05 UTC
I see the problem here too.
Comment 4 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 5 Marek Polacek 2016-01-29 09:37:24 UTC
Fixed for GCC 6.