https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99966

            Bug ID: 99966
           Summary: Bounds check not eliminated by assert
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jmuizelaar at mozilla dot com
  Target Milestone: ---

#include <cassert>
#include <cstdint>
#include <cstddef>
#include <vector>

uint64_t f(std::vector<uint64_t>& data, size_t start, size_t end){
    assert(start < end && start < data.size() && end <= data.size());


    uint64_t total = 0;
    for (size_t i = start; i < end; i++) {
        total += data.at(i);
    }
    return total;
}

https://godbolt.org/z/Ksecrec11

Clang is able to eliminate the the check when using -mllvm
-enable-constraint-elimination
https://godbolt.org/z/K67b8PTM9
  • [Bug tree-optimization/99966] N... jmuizelaar at mozilla dot com via Gcc-bugs

Reply via email to