C++11 with GNU VLA extention results in ICE

Bug #1895372 reported by Andy Zheng
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-7 (Ubuntu)
New
Undecided
Unassigned

Bug Description

I have just encountered an "internal compiler error" while using gcc-7.

```cpp source code
#include <cstdio>

int main()
{
    int N = 100;
    int K = 100;
    int dp[N][2][K] = {0};
    printf("%d\n", dp[0][0][0]);
    return 0;
}
```

After executing
  g++ test.cc
Output is
  test.cc: In function ‘int main()’:
  test.cc:7:25: internal compiler error: in make_decl_rtl, at varasm.c:1310
       int dp[N][2][K] = {0};
                         ^
  Please submit a full bug report,
  with preprocessed source if appropriate.
  See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.

which is exectly same with these three options: "-std=c++11", "-std=c++14", "-std=c++17".

With executing
  g++ test.cc -std=c++98
the binary is produced normally.

With executing
  g++ test.cc -std=c++98 -ansi -pedantic -Wextra -Werror
Output is
  test.cc: In function ‘int main()’:
  test.cc:7:19: error: ISO C++ forbids variable length array ‘dp’ [-Werror=vla]
       int dp[N][2][K] = {0};
                   ^
  test.cc:7:19: error: ISO C++ forbids variable length array ‘dp’ [-Werror=vla]
  cc1plus: all warnings being treated as errors
which is expected.

According to my observation, this seems to be the issue related to the order of 'N','2','K',
if I write
  int dp[N][K][2] = {0};
then everything is fine.

Here is my gcc version (gcc -v):

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)

BTW, the preprocessed file 'test.ii' can be found in the 'Attachment' in case you need it.

Revision history for this message
Andy Zheng (smlight) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.