[clang] [clang] Fix strlen constant evaluation for wide string literals with an offset (PR #241354)

Michael Scartaccini via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 11 18:07:40 PST 2026


MScarta wrote:

I pushed a second commit. While comparing this with #241359 I tested more kinds of string literal and found my own type check was too strict. It compared types, so it rejected u8 literals, which have 1-byte characters and which LLVM 21 folds. I changed the check to compare character sizes instead, and added two test lines for it.

One side effect: `__builtin_wcslen` on a `u""` or `U""` literal cast to a `wchar_t` of the same size is folded. LLVM 21 did not fold this, but main already does, so it is not new here. I can restrict the fast path to matching types if you prefer.

I also replaced one of my test lines, because it gave the same result with and without the fix.

The description is updated to match.


https://github.com/llvm/llvm-project/pull/241354


More information about the cfe-commits mailing list