-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Open
Description
Clang has builtins for a lot of the <cwchar> functions and can constant evaluate them when using the __builtin_ variants, but the backend can't constant fold them. There doesn't seem to be much of a technical reason, since their <cstring> counterparts can often be constant folded, and some even have passes dedicated to them.
For example,
#include <cstddef>
auto test(wchar_t *ptr, size_t count) {
wchar_t buffer[] = L"Banane";
return __builtin_wmemchr(buffer, L'a', __builtin_wcslen(buffer)) != nullptr;
}
static_assert([] {
wchar_t buffer[] = L"Banane";
return __builtin_wmemchr(buffer, L'a', __builtin_wcslen(buffer)) != nullptr;
}());compiles just fine, but test generates horrible code compared to what should be possible: https://godbolt.org/z/xP3vM9jPn