public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/107639] New: GCC unable to reason about range of idx/len
@ 2022-11-11 15:44 jmuizelaar at mozilla dot com
  2022-11-11 15:46 ` [Bug tree-optimization/107639] " jmuizelaar at mozilla dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jmuizelaar at mozilla dot com @ 2022-11-11 15:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107639
           Summary: GCC unable to reason about range of idx/len
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jmuizelaar at mozilla dot com
  Target Milestone: ---

Clang 14 is able to optimize this function to just 'ret'. GCC 12.2 is not.

#include <cstddef>

void do_checks(const int* begin, const size_t len){
    size_t idx = 0;
    const auto end = begin + len;
    for (const int* it = begin; it!=end; ++it, ++idx){
        if (idx <= len){
            // Do something useful
        }
        else
        {
            throw 5;
        }
    }
}

https://godbolt.org/z/f7PjjqG9T

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-14 14:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-11 15:44 [Bug tree-optimization/107639] New: GCC unable to reason about range of idx/len jmuizelaar at mozilla dot com
2022-11-11 15:46 ` [Bug tree-optimization/107639] " jmuizelaar at mozilla dot com
2022-11-14 11:32 ` rguenth at gcc dot gnu.org
2022-11-14 14:24 ` amacleod at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).