conda-forge / ctng-compilers-feedstock

A conda-smithy repository for ctng-compilers.
BSD 3-Clause "New" or "Revised" License
12 stars 28 forks source link

gcc triggers internal compiler error when using -std=c++14 or -std=c++17 #6

Open pearu opened 4 years ago

pearu commented 4 years ago

Issue: g++ fails with internal compiler error.

Consider a C++ program:

/* File test.cpp */
int rand();

template<typename T>
struct s
{
    int count() { return rand(); }
};

template<typename v>
int f(s<v> a)
{
    int const x = a.count();
    int r = 0;
    auto l = [&](int& r)
    {
        for(int y = 0, yend = (x); y < yend; ++y)
        {
            r += y;
        }
    };
    l(r);
}

template int f(s<float>);

int main()
{
}

Which triggers the gcc bug:

$ g++ -c test.cpp
test.cpp: In instantiation of 'f(s<v>)::<lambda(int&)> [with v = float]':
test.cpp:14:16:   required from 'struct f(s<v>) [with v = float]::<lambda(int&)>'
test.cpp:14:10:   required from 'int f(s<v>) [with v = float]'
test.cpp:24:24:   required from here
test.cpp:16:24: internal compiler error: in maybe_undo_parenthesized_ref, at cp/semantics.c:1705
         for(int y = 0, yend = (x); y < yend; ++y)
                        ^~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

Notice that the same compilation error happens with the following commands

g++ -c -std=c++14 test.cpp
g++ -c -std=c++17 test.cpp

but not with

g++ -c -std=c++11 test.cpp

Also note that g++ from Debian has a fix to the above bug, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=882855 .


Environment (conda list):

``` $ conda list # packages in environment at /home/pearu/miniconda3/envs/test-gcc-bug: # # Name Version Build Channel _libgcc_mutex 0.1 main conda-forge binutils-meta 1.0.4 0 conda-forge binutils_impl_linux-64 2.33.1 he1b5a44_7 conda-forge binutils_linux-64 2.33.1 h9595d00_15 conda-forge c-compiler 1.0.4 h516909a_0 conda-forge compilers 1.0.4 0 conda-forge cxx-compiler 1.0.4 hc9558a2_0 conda-forge fortran-compiler 1.0.4 he991be0_0 conda-forge gcc_impl_linux-64 7.3.0 habb00fd_2 conda-forge gcc_linux-64 7.3.0 h553295d_15 conda-forge gfortran_impl_linux-64 7.3.0 hdf63c60_2 conda-forge gfortran_linux-64 7.3.0 h553295d_15 conda-forge gxx_impl_linux-64 7.3.0 hdf63c60_2 conda-forge gxx_linux-64 7.3.0 h553295d_15 conda-forge ld_impl_linux-64 2.33.1 h53a641e_7 conda-forge libgcc-ng 9.2.0 hdf63c60_0 conda-forge libgfortran-ng 7.3.0 hdf63c60_2 conda-forge libstdcxx-ng 9.2.0 hdf63c60_0 conda-forge ```


Details about conda and system ( conda info ):

``` $ conda info active environment : test-gcc-bug active env location : /home/pearu/miniconda3/envs/test-gcc-bug shell level : 2 user config file : /home/pearu/.condarc populated config files : /home/pearu/.condarc conda version : 4.7.12 conda-build version : 3.18.11 python version : 3.7.3.final.0 virtual packages : __cuda=10.1 base environment : /home/pearu/miniconda3 (writable) channel URLs : file:///home/pearu/miniconda3/conda-bld/linux-64 file:///home/pearu/miniconda3/conda-bld/noarch https://conda.anaconda.org/conda-forge/linux-64 https://conda.anaconda.org/conda-forge/noarch https://repo.anaconda.com/pkgs/main/linux-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/linux-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /home/pearu/miniconda3/pkgs /home/pearu/.conda/pkgs envs directories : /home/pearu/miniconda3/envs /home/pearu/.conda/envs platform : linux-64 user-agent : conda/4.7.12 requests/2.22.0 CPython/3.7.3 Linux/4.15.0-70-generic ubuntu/18.04.3 glibc/2.27 UID:GID : 1000:1000 netrc file : None offline mode : False ```
mattip commented 4 years ago

PR gh-22 updated the compilers to gcc 7.5 (from the 7.3 used here in this issue), but that still hits this bug.

xhochy commented 2 years ago

https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-7-debian/debian/patches/pr83204.diff should fix it.