Skip to content

[Clang 20.1.0] Missed strlen when cmp to NUL forwards with increments #132578

@BreadTom

Description

@BreadTom

https://godbolt.org/z/adf71b63Y
f1() should optimized to f0(). f0() should call strlen just like GCC 14.2.
C code

#include <stddef.h>

size_t f0(char *str){
    size_t i = 0;
    for(; str[i] != '\0'; ++i){

    }
    return i;
}

size_t f1(char *str, size_t inc){
    if(inc < 2)
        __builtin_unreachable();
    if(str[0] == '\0')
        return 0;
    size_t i = 0;
    for(;; i += inc){
        for(size_t n = 0; n < inc; ++n){
            if(str[i+n] == '\0'){
                return i+n;
            }
        }
    }
    return i;
}

Bug also reported at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119431

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions