[llvm-dev] [RFC] Introducing a byte type to LLVM
John McCall via llvm-dev
llvm-dev at lists.llvm.org
Tue Jun 15 00:06:46 PDT 2021
On 15 Jun 2021, at 1:49, Juneyoung Lee wrote:
> On Tue, Jun 15, 2021 at 1:08 AM John McCall via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>> The semantics you seem to want are that LLVM’s integer types cannot
>> information from pointers. But I can cast a pointer to an integer in
>> C and
>> vice-versa, and compilers have de facto defined the behavior of
>> operations like breaking the integer up (and then putting it back
>> together), adding numbers to it, and so on. So no, as a C compiler
>> I do not have a choice; I will have to use a type that can validly
>> pointer information for integers in C.
> int->ptr cast can reconstruct the pointer information, so making
> types not carry pointer information does not necessarily mean that
> dereferencing a pointer casted from integer is UB.
What exactly is the claimed formal property of byte types, then,
that integer types will lack? Because it seems to me that converting
from an integer gives us valid provenance in strictly more situations
than converting from bytes, since it reconstructs provenance if
any object at that address (under still-debated restrictions),
while converting from bytes always preserves the original provenance
(if any). I don’t understand how that can possibly give us *more*
flexibility to optimize integers.
>> Since you seem to find this sort of thing compelling, please note
>> even a simple assignment like char c2 = c1 technically promotes
>> int in C, and so int must be able to carry pointer information if
> IIUC integer promotion is done when it is used as an operand of
> ops or switch's condition, so I think assignment operation is okay.
Hmm, I was misremembering the rule, you’re right.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev