Cleanup the Linalg trait ViewRanks.
authorRiver Riddle <riverriddle@google.com>
Mon, 3 Jun 2019 14:03:54 +0000 (07:03 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Tue, 4 Jun 2019 02:26:04 +0000 (19:26 -0700)
* Fix a miscompile on older clang versions when initializing an ArrayRef with an unsigned variadic template argument.
* Update the errors to use the streaming interface instead of Twine.

PiperOrigin-RevId: 251223929

mlir/include/mlir/Linalg/IR/LinalgTraits.h

index 7d99dc7..5fafe91 100644 (file)
@@ -100,18 +100,18 @@ public:
       : public OpTrait::TraitBase<ConcreteType, ViewRanks<Ranks...>::Impl> {
   public:
     static LogicalResult verifyTrait(Operation *op) {
-      ArrayRef<unsigned> ranks{Ranks...};
-      if (op->getNumOperands() != ranks.size())
-        return op->emitError("expected " + Twine(ranks.size()) + " operands");
+      if (op->getNumOperands() != sizeof...(Ranks))
+        return op->emitError("expected ") << sizeof...(Ranks) << " operands";
+
+      unsigned ranks[]{Ranks...};
       for (unsigned i = 0, e = op->getNumOperands(); i < e; ++i) {
         auto viewType =
             op->getOperand(i)->getType().dyn_cast<mlir::linalg::ViewType>();
         if (!viewType)
-          return op->emitOpError("operand " + Twine(i) +
-                                 " must have view type ");
+          return op->emitOpError("operand ") << i << " must have view type ";
         if (ranks[i] != viewType.getRank())
-          return op->emitOpError("operand " + Twine(i) + " must have rank " +
-                                 Twine(ranks[i]));
+          return op->emitOpError("operand ")
+                 << i << " must have rank " << ranks[i];
       }
       return success();
     }