From 898b18dca637a93159e3e73c2f5a02ec0760937e Mon Sep 17 00:00:00 2001 From: tnowicki Date: Fri, 28 Mar 2025 18:13:45 -0400 Subject: [PATCH] SWDEV-303548 - Macro for declaring VisitorPayloadOffsetProjection with useOffsetof = false --- include/llvm-dialects/Dialect/Visitor.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/llvm-dialects/Dialect/Visitor.h b/include/llvm-dialects/Dialect/Visitor.h index fd6e731..4606f51 100644 --- a/include/llvm-dialects/Dialect/Visitor.h +++ b/include/llvm-dialects/Dialect/Visitor.h @@ -91,6 +91,20 @@ struct VisitorPayloadProjection { static constexpr std::size_t offset = offsetof(PayloadT, field); \ }; +/// Identical to the previous macro except this one handles complex data types +/// +/// offsetof() should not be used with complex types that have a non-standard +/// layout, such as classes. Here we set useOffsetof = false to avoid using +/// offsetof() on the field. +#define LLVM_DIALECTS_VISITOR_PAYLOAD_PROJECT_COMPLEX_FIELD(PayloadT, field) \ + template <> \ + struct llvm_dialects::detail::VisitorPayloadOffsetProjection< \ + PayloadT, \ + std::remove_reference_t().field)>> { \ + static constexpr bool useOffsetof = false; \ + static constexpr std::size_t offset = 0; \ + }; + /// @brief Possible result states of visitor callbacks /// /// A visitor may have multiple callbacks registered that match on the same