[Bug 1895372] [NEW] C++11 with GNU VLA extention results in ICE

Andy Zheng 1895372 at bugs.launchpad.net
Sat Sep 12 05:34:26 UTC 2020


Public bug reported:

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.

** Affects: gcc-7 (Ubuntu)
     Importance: Undecided
         Status: New

** Attachment added: "test.ii"
   https://bugs.launchpad.net/bugs/1895372/+attachment/5410020/+files/test.ii

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-7 in Ubuntu.
https://bugs.launchpad.net/bugs/1895372

Title:
  C++11 with GNU VLA extention results in ICE

Status in gcc-7 package in Ubuntu:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-7/+bug/1895372/+subscriptions



More information about the foundations-bugs mailing list