[clang] [llvm] [DenseMap] Do not align pointer sentinel values (NFC) (PR #146595)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 2 01:06:17 PDT 2025


nikic wrote:

> Do you know if this runs into issues with undefined behavior? I don't know the exact rules, but remember reading something along the lines that some OOB pointers cannot even be compared without running into UB. Having pointers that don't respect type alignment sounds like walking on thin ice to me...

I think the relevant parts are https://eel.is/c++draft/expr.eq#3 (which does not specify UB for equality comparisons) and https://eel.is/c++draft/expr.reinterpret.cast#5 (which makes all non-roundtrip integer to pointer reinterpret_casts implementation-defined.) 

I think there are some more complexities here, but I think the gist is that as soon as we do a reinterpret_cast from an integer to a pointer we're in implementation-defined territory regardless of whether the resulting pointer is aligned or not.

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


More information about the cfe-commits mailing list