[clang] Reland "[clang] Add nuw attribute to GEPs (#105496)" (PR #107257)

Arseny Kapoulkine via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 12 10:21:38 PDT 2024


zeux wrote:

This change leads to a miscompilation; I've extracted a somewhat minimal repro case from the referenced issue above, in the comment: https://github.com/zeux/pugixml/issues/629#issuecomment-2346839855

The code, when compiled with `-O2 -g` by latest clang on Linux/X64, generates the following assembly after the call to `printf` in `get_valid_length`:

```
->  0x555555561270 <+192>: movzx  eax, byte ptr [-0x1]
```

... which, as you can imagine, results in a sigsegv :) This seems to be architecture independent as it initially reproduced in Wasm and also confirmed on Arm.

I *believe* that all accesses in this code are in-bounds and no overflow/underflow happens. The code is silent with `-fsanitize=integer,undefined` when using clang 18.

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


More information about the cfe-commits mailing list