[Mlir-commits] [mlir] c0edcec - Add a static assertions for custom Op<> to not defined data members (NFC)

Mehdi Amini llvmlistbot at llvm.org
Tue Jun 8 11:38:32 PDT 2021


Author: Mehdi Amini
Date: 2021-06-08T18:38:18Z
New Revision: c0edcec630eb26e12d66dae2f0e1fbf5258cb6ac

URL: https://github.com/llvm/llvm-project/commit/c0edcec630eb26e12d66dae2f0e1fbf5258cb6ac
DIFF: https://github.com/llvm/llvm-project/commit/c0edcec630eb26e12d66dae2f0e1fbf5258cb6ac.diff

LOG: 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

Added: 
    

Modified: 
    mlir/include/mlir/IR/OpDefinition.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index dadf028d281f..bb6ff8d4f74e 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -1780,6 +1780,8 @@ class Op : public OpState, public Traits<ConcreteType>... {
     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<VerifiableTraitsTupleT>(op)) ||
         failed(cast<ConcreteType>(op).verify()));


        


More information about the Mlir-commits mailing list