[PATCH] D110586: Update `DynTypedNode` to support the conversion of `TypeLoc`s.

James King via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 30 15:44:02 PDT 2021


jcking1034 marked an inline comment as done.
jcking1034 added inline comments.


================
Comment at: clang/include/clang/AST/ASTTypeTraits.h:472
+      assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind));
+      return *static_cast<const T *>(reinterpret_cast<const BaseT *>(Storage));
+    }
----------------
sbenza wrote:
> The create/get don't seem to match.
> We are constructing a `BaseT` object in `create()`, so this `static_cast` to a derived type is UB?
> That memory does not contain a `T`.
> 
> If we instead construct a `T` in `create()`, we should be able to read it as a `BaseT*` (assuming `is_pointer_interconvertible_base_of<BaseT, T>` is true)
Done, constructing a `T` instead of a `BaseT` seems to work!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110586/new/

https://reviews.llvm.org/D110586



More information about the cfe-commits mailing list