Skip to content

Commit 898b18d

Browse files
committed
SWDEV-303548 - Macro for declaring VisitorPayloadOffsetProjection with useOffsetof = false
1 parent a52cb73 commit 898b18d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

include/llvm-dialects/Dialect/Visitor.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ struct VisitorPayloadProjection {
9191
static constexpr std::size_t offset = offsetof(PayloadT, field); \
9292
};
9393

94+
/// Identical to the previous macro except this one handles complex data types
95+
///
96+
/// offsetof() should not be used with complex types that have a non-standard
97+
/// layout, such as classes. Here we set useOffsetof = false to avoid using
98+
/// offsetof() on the field.
99+
#define LLVM_DIALECTS_VISITOR_PAYLOAD_PROJECT_COMPLEX_FIELD(PayloadT, field) \
100+
template <> \
101+
struct llvm_dialects::detail::VisitorPayloadOffsetProjection< \
102+
PayloadT, \
103+
std::remove_reference_t<decltype(std::declval<PayloadT>().field)>> { \
104+
static constexpr bool useOffsetof = false; \
105+
static constexpr std::size_t offset = 0; \
106+
};
107+
94108
/// @brief Possible result states of visitor callbacks
95109
///
96110
/// A visitor may have multiple callbacks registered that match on the same

0 commit comments

Comments
 (0)