It is a gdb bug. I have filed on gcc (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117647), and they asked me to move to sourceware.org. Meanwhile they mentioned two related issues https://sourceware.org/PR28999 and https://sourceware.org/PR26325, but as of today 2024/11/18 gdb 15.2 still hasn't fixed the issue.