From c0edcec630eb26e12d66dae2f0e1fbf5258cb6ac Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Tue, 8 Jun 2021 18:28:39 +0000 Subject: [PATCH] Add a static assertions for custom Op<> to not defined data members (NFC) A common mistake for newcomers to MLIR is to try to store extra member on the Op class. However these are intended to be thing wrapper around an Operation*, all the storage is meant to be encoded in attribute on the underlying Operation. This can be confusing to debug, so better catch it at build time. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D103869 --- mlir/include/mlir/IR/OpDefinition.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index dadf028..bb6ff8d 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -1780,6 +1780,8 @@ private: return &verifyInvariants; } static LogicalResult verifyInvariants(Operation *op) { + static_assert(sizeof(ConcreteType) == sizeof(OpState), + "Op class aren't allowed to have data members"); return failure( failed(op_definition_impl::verifyTraits(op)) || failed(cast(op).verify())); -- 2.7.4