[PATCH] D13946: Shrink DynTypedNode by one pointer from 40 to 32 bytes (on x86_64).

Samuel Benzaquen via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 21 08:45:19 PDT 2015

sbenza added inline comments.

Comment at: include/clang/AST/ASTTypeTraits.h:250
@@ +249,3 @@
+    return NodeKind.hasPointerIdentity()
+               ? *reinterpret_cast<void *const *>(Storage.buffer)
+               : nullptr;
I'm not sure about this reinterpret_cast.
We are not storing void*. We are storing 'const Node*'.
I think this way is UB.

Maybe we should modify the union and the create/getUnchecked methods to use 'const void*' as storage instead.
Instead of:

new (Result.Storage.buffer) const BaseT * (&Node);
return *cast<T>(*reinterpret_cast<BaseT *const *>(Storage));
we should do

new (Result.Storage.buffer) const void * (static_cast<const BaseT*>(&Node));
return *cast<T>(static_cast<const BaseT*>(*reinterpret_cast<const void *const *>(Storage)));


More information about the cfe-commits mailing list