<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - constexpr fibonacci is not computed at compile time"
   href="https://bugs.llvm.org/show_bug.cgi?id=39109">39109</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>constexpr fibonacci is not computed at compile time
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>constexpr uint32_t fib(const uint32_t n) {
  if (n <= 1) return 1;
  return fib(n - 1) + fib(n - 2);
}

int main() {
  return fib(7);
}

int main2() {
  const uint32_t res = fib(7);
  return res;
}

Clang is unable to compute fib in main (but it can in main2) at compile time,
GCC can do it in both functions.

main:                                   # @main
        mov     edi, 7
        jmp     fib(unsigned int)    


While main2 is interesting.. Clang computes it as 21 but then it still calls
fib uselessly.

main2():                              # @main2()
        push    rax
        mov     edi, 7
        call    fib(unsigned int)
        mov     eax, 21
        pop     rcx
        ret


Latest GCC:
main:
        mov     eax, 21
        ret
main2():
        mov     eax, 21
        ret</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>