[llvm-bugs] [Bug 34254] New: Clang misses an opportunity to evaluate a call to std::accumulate at compile time

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 21 03:31:06 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34254

            Bug ID: 34254
           Summary: Clang misses an opportunity to evaluate a call to
                    std::accumulate at compile time
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jbcoe at me.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The following code:

#include <iterator>
#include <numeric>

using std::begin;
using std::end;

int f()
{
  int xs[32];

  std::iota(begin(xs), 
            end(xs), 1);

  return std::accumulate(begin(xs), 
                         end(xs), 0);
}

Is compiled with gcc-trunk -O3 to:

f():
  mov eax, 528
  ret

whereas Clang evaluates the call to accumulate at compile time.

example at: https://godbolt.org/g/dd831y

This is not impeding my work in any way and was discovered by accident.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170821/cf551bd9/attachment.html>


More information about the llvm-bugs mailing list