[PATCH] D124571: Avoid strict aliasing violation on type punning inside llvm::PointerIntPair
Argyrios Kyrtzidis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 28 09:17:13 PDT 2022
akyrtzi added inline comments.
================
Comment at: llvm/include/llvm/ADT/PointerIntPair.h:48
+ }
+
+ alignas(Ptr) char Data[sizeof(Ptr)];
----------------
there should be a `private:` line to make `Data` inaccessible from outside.
================
Comment at: llvm/include/llvm/ADT/PointerIntPair.h:49
+
+ alignas(Ptr) char Data[sizeof(Ptr)];
+};
----------------
I believe this can just be `Ptr Data;`, it doesn't need to be a `char` buffer, the `memcpy`s should keep this in "defined behavior land" even if you are copying from a pointer type.
Then `getPointerAddress()` becomes
```
Ptr *getPointerAddress() { return &Data; }
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124571/new/
https://reviews.llvm.org/D124571
More information about the llvm-commits
mailing list