| Issue |
76406
|
| Summary |
clang 18 has forgotten how to compute `strnlen` of a stack buffer
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
ecatmur
|
```c++
#include <string.h>
int f() {
char const s[] = "abcdefg";
return strnlen(s, 8);
}
int g() { return strnlen("abcdefg", 8); }
```
clang 15 through 17 (at -O) optimize both `f` and `g` to `mov eax, 7; ret`.
clang 18 trunk 68f832f56da1af0e5fc77003f640648ec7d901ad continues to optimize `g` but has forgotten how to optimize `f`:
```
f: # @f
push rax
movabs rax, 29104508263162465
mov qword ptr [rsp], rax
mov rdi, rsp
mov esi, 8
call strnlen@PLT
pop rcx
ret
```
However, if the buffer is expanded to > 64 bytes, it remembers again:
```
int f() {
char const s[65] = "abcdefg"; // this is fine
return strnlen(s, 8); // mov eax, 7; ret
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs