[clang] [libcxx] [clang & libcxx] constexpr pointer tagging (DO NOT MERGE) (PR #111861)

Hana Dusíková via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 10 10:53:04 PDT 2024


hanickadot wrote:

> Is there some explanation of the set of builtins you chose somewhere? How is "masking" a pointer different from the existing __builtin_align_down/__builtin_align_up?

Intention is to allow to use any bits in pointer for tagging and give freedom. To do so. I'm not proposing these now for LLVM, this is just prototype, so I can get some review of library design, but also I wanted to give here version which somehow works, but it doesn't need to be perfect.

> I'm pretty sure your implementation of comparison operators doesn't actually work correctly; what happens if you compare a tagged pointer to a struct to pointer to a member of the struct?

(If we are talking libcxx). 
Not sure what you mean. They should have incompatible types for comparison and it won't match the operator.  If they are of compatible types this tagged_ptr is doing untagging first with function `.pointer()` so you should get original untagged pointer.  If you try to tag pointer in a way which would make original value irrecoverable you are breaking semantic requirement inside constructor of tagged_ptr.



In ExprConstant.cpp the comparison of tags is happening at the end of comparing pointers, where they were compared based on offsets (calculated out of LValue's path) so they should be same, but they can differ in tag.


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


More information about the cfe-commits mailing list