[libc-commits] [libc] [libc] Export the RPC interface from `libc` (PR #71432)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Fri Mar 15 08:46:32 PDT 2024
jhuber6 wrote:
> The reinterpret_casts I cautioned against in November are still here, this time with clear cut undefined behaviour.
>
> ```
> rpc::Client::Port *port = reinterpret_cast<rpc::Client::Port *>(handle);
> port-> bang
> ```
>
> Handle is 32 bytes. It's not an instance of port. Totally invalid C++, you need to handle aliasing with far more paranoia than this to be correct. Even if you're going with "UB is fine, clang isn't currently breaking me", that's a misaligned load and I doubt GPUs support that gracefully.
Could you explain a bit further into what's undefined here? Basically we are doing this
```
struct Port { ... }
struct port_t { uint8_t data[sizeof(Port)]; }
port_t p = bit_cast<port_t>(Port());
void *ptr = &p
Port &original = *reinterpret_cast<Port>(ptr);
```
The sketchy part may be the original bitcast, because the base type is not trivially constructable. But because we already created it, shouldn't it be valid to do an in-memory bitcast? After that it's pretty much just typical type erasure since it's referring to the same memory.
https://github.com/llvm/llvm-project/pull/71432
More information about the libc-commits
mailing list