4 ms·
Out of curiosity, does this idiom work in fil-c? https://github.com/protocolbuffers/protobuf/blob/cb873c8987dd33282125ecbbae378b74be5f4707/upb/wire/eps_copy_in
by charleslmunger 1y ago
Out of curiosity, does this idiom work in fil-c?
https://github.com/protocolbuffers/protobuf/blob/cb873c8987dd33282125ecbbae378b74be5f4707/upb/wire/eps_copy_input_stream.h#L286 https://github.com/protocolbuffers/protobuf/blob/cb873c8987d...
// This somewhat silly looking add-and-subtract behavior provides provenance
// from the original input buffer's pointer. After optimization it produces
// the same assembly as just casting `(uintptr_t)ptr+input_delta`
// https://godbolt.org/z/zosG88oPn
size_t position =
(uintptr_t)ptr + e->input_delta - (uintptr_t)e->buffer_start;
return e->buffer_start + position;
It does use the implementation defined behavior that a char pointer + 1 casted to uintptr is the same as casting to uintptr then adding 1.
- pizlonator 1y agoYeah that should just work Code that strives to preserve provenance works in Fil-C
- charleslmunger 1y agoVery cool. Hardware asan did not catch the pointer provenance bug in the previous implementation of that code because it relies on tag bits, and the produced pointer was bit-identical to the intended one. It sounds like fil-c would have caught it because the pointer capabilities are stored elsewhere.