[LLVMbugs] [Bug 14771] New: c++11: Fibonacci numbers calculations cause infinite loop

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jan 1 04:51:06 PST 2013


             Bug #: 14771
           Summary: c++11: Fibonacci numbers calculations cause infinite
           Product: clang
           Version: 3.2
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: dushistov at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I play with c++11. And such code cause 100% cpu usage during 1 hour,
after that I just press ctrl+c.

#include <cstdio>

constexpr unsigned int fib(unsigned int N)
    return N <= 1 ? 1 : (fib(N - 1) + fib(N - 2));

template <unsigned int N>
struct Fib {
    enum { value = fib(N) };

int main()
    printf("%u\n", Fib<1000>::value);

I run clang in such way:
clang++ -fconstexpr-depth=10000 -Wall -std=c++0x test8.cpp

time g++ -fconstexpr-depth=10000 -Wall -std=c++0x test8.cpp

real    0m0.108s
user    0m0.080s
sys     0m0.010s

So > 1 hour of work seems strange.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list