[Bug debug/81042] New: Too many constexpr interations on unreachable loop.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug debug/81042] New: Too many constexpr interations on unreachable loop.

danglin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81042

            Bug ID: 81042
           Summary: Too many constexpr interations on unreachable loop.
           Product: gcc
           Version: 7.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kevincox at kevincox dot ca
  Target Milestone: ---

Created attachment 41526
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41526&action=edit
Example code.

The following code causes an error for too many iterations in the unreachable
loop. Clang correctly creates a binary which returns 1 when run. It's worth
noting that the previous version of gcc I tried this on hung forever, however
7.1.1 gives the too many iterations error.

Example online: https://godbolt.org/g/QFRmwk

$ g++ -std=c++17 test.cc
/home/kevincox/test.cc: In function ‘int main()’:
/home/kevincox/test.cc:14:24:   in constexpr expansion of ‘foo()’
/home/kevincox/test.cc:7:3: error: constexpr loop iteration count exceeds limit
of 262144 (use -fconstexpr-loop-limit= to increase the limit)
   while (true) {} // Unreachable
   ^~~~~

// test.cc
constexpr static bool foo() {
        int i = 0;
        while (i < 1) {
                i++;
                continue;

                while (true) {} // Unreachable
        }

        return true;
}

int main() {
        constexpr bool f = foo();
        return f;
}
Reply | Threaded
Open this post in threaded view
|

[Bug c++/81042] Too many constexpr interations on unreachable loop.

danglin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81042

--- Comment #1 from Kevin Cox <kevincox at kevincox dot ca> ---
Also it appears the loop condition isn't properly evaluated. For example the
following three examples (and any other number I tested also cause the error.

while (++i == 0) {} // Unreachable
while (++i == 1) {} // Unreachable
while (++i == 2) {} // Unreachable

However some simpler expressions don't cause the error.

while (false) {} // Unreachable
while (i != i) {} // Unreachable
Reply | Threaded
Open this post in threaded view
|

[Bug c++/81042] Too many constexpr interations on unreachable loop.

danglin at gcc dot gnu.org
In reply to this post by danglin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81042

Mateusz Nowotynski <maxmati4 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxmati4 at gmail dot com

--- Comment #2 from Mateusz Nowotynski <maxmati4 at gmail dot com> ---
I also experienced this bug on gcc (Gentoo 6.4.0 p1.0) 6.4.0 and gcc (GCC)
8.0.0 20170819 (experimental). On version 6.4 it results in never ending
compilation and on 8.0 it trigers same error as @KevinCox.

Whats more for me it looks like regrsion since my code compiles fine on gcc
(Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005 haven't tried @KevinCox version.

My program triggering this error:
struct Table
{
    constexpr Table() : primes()
    {
        for(int i = 1; i < 100; ++i){
            if(!primes[i]) continue;
            for(int j = 1; j < 100; ++j);
        }

    }
    bool primes[100];
};


int main(){
    constexpr auto primes = Table();
}
Reply | Threaded
Open this post in threaded view
|

[Bug c++/81042] Too many constexpr interations on unreachable loop.

danglin at gcc dot gnu.org
In reply to this post by danglin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81042

Valentine <v at vsamko dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |v at vsamko dot com

--- Comment #3 from Valentine <v at vsamko dot com> ---
I'm having the same problem with gcc 7.2. Clang handles this correctly.

constexpr int gcc_bug() {
    for (unsigned int i = 0; i != 1; ++i) {
        continue;
        int q = 0;
        while (q == -1) {}
    }
    return 0;
}

int main() {
    constexpr int x = gcc_bug();
}
Reply | Threaded
Open this post in threaded view
|

[Bug c++/81042] Too many constexpr iterations on unreachable loop.

danglin at gcc dot gnu.org
In reply to this post by danglin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81042

Ralph Tandetzky <ralph.tandetzky at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ralph.tandetzky at gmail dot com

--- Comment #4 from Ralph Tandetzky <ralph.tandetzky at gmail dot com> ---
The following code:

 1 constexpr int f()
 2 {
 3     for ( int i = 0; i < 1; ++i ) {
 4         const int digit = i/1;
 5         if( digit == 0 )
 6             continue;
 7         for ( int j = 0; j < 0; ++j ) {} // <-- loop iteration count
 8                                          //     exceeds limit
 9     }
10     return 0;
11 }
12
13 constexpr int i = f();

produces the following error with GCC 8.2:

    <source>:13:20:   in 'constexpr' expansion of 'f()'

    <source>:7:9: error: 'constexpr' loop iteration count exceeds
        limit of 262144 (use -fconstexpr-loop-limit= to increase the limit)

             for ( int j = 0; j < 0; ++j ) {}
             ^~~