[Mlir-commits] [mlir] 8847d9a - Reland "[mlir][test] Fix IR/AttributeTest.cpp compilation on Solaris"

Rainer Orth llvmlistbot at llvm.org
Fri Aug 19 13:00:33 PDT 2022


Author: Rainer Orth
Date: 2022-08-19T21:59:57+02:00
New Revision: 8847d9a2424caebf7340367a1ba203cb1569525d

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

LOG: Reland "[mlir][test] Fix IR/AttributeTest.cpp compilation on Solaris"

The `IR/AttributeTest.cpp` test fails to compile on Solaris:
```
/vol/llvm/src/llvm-project/local/mlir/unittests/IR/AttributeTest.cpp:223:36: error: no matching function for call to 'allocate'
      AttrT::get(type, "resource", UnmanagedAsmResourceBlob::allocate(data));
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/vol/llvm/src/llvm-project/local/mlir/unittests/IR/AttributeTest.cpp:237:3: note: in instantiation of function template specialization 'checkNativeAccess<mlir::detail::DenseResourceElementsAttrBase<int8_t>, char>' requested here
  checkNativeAccess<AttrT, T>(builder.getContext(), llvm::makeArrayRef(data),
  ^
/vol/llvm/src/llvm-project/local/mlir/unittests/IR/AttributeTest.cpp:258:3: note: in instantiation of function template specialization 'checkNativeIntAccess<mlir::detail::DenseResourceElementsAttrBase<int8_t>, char>' requested here
  checkNativeIntAccess<DenseI8ResourceElementsAttr, int8_t>(builder, 8);
  ^
/vol/llvm/src/llvm-project/local/mlir/include/mlir/IR/AsmState.h:221:3: note: candidate template ignored: requirement '!std::is_same<char, char>::value' was not satisfied [with T = char]
  allocate(ArrayRef<T> data, bool dataIsMutable = false) {
  ^
/vol/llvm/src/llvm-project/local/mlir/include/mlir/IR/AsmState.h:214:26: note: candidate function not viable: requires at least 2 arguments, but 1 was provided
  static AsmResourceBlob allocate(ArrayRef<char> data, size_t align,
                         ^
```
Because `char` is `signed` by default on Solaris and `int8_t` is
`char`. `std::is_same<int8_t, char>` is `true` unlike elsewhere, rejecting
the one-arg `allocate` overload.

Fixed by renaming the two overloads to avoid the ambiguity.

Tested on `amd64-pc-solaris2.11` ,`sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D131148

Added: 
    

Modified: 
    mlir/include/mlir/IR/AsmState.h
    mlir/unittests/IR/AttributeTest.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/AsmState.h b/mlir/include/mlir/IR/AsmState.h
index b54bf176ce2a..51a66310b25d 100644
--- a/mlir/include/mlir/IR/AsmState.h
+++ b/mlir/include/mlir/IR/AsmState.h
@@ -211,15 +211,15 @@ class UnmanagedAsmResourceBlob {
   /// Create a new unmanaged resource directly referencing the provided data.
   /// `dataIsMutable` indicates if the allocated data can be mutated. By
   /// default, we treat unmanaged blobs as immutable.
-  static AsmResourceBlob allocate(ArrayRef<char> data, size_t align,
-                                  bool dataIsMutable = false) {
+  static AsmResourceBlob allocateWithAlign(ArrayRef<char> data, size_t align,
+                                           bool dataIsMutable = false) {
     return AsmResourceBlob(data, align, /*deleter=*/{},
                            /*dataIsMutable=*/false);
   }
   template <typename T>
-  static std::enable_if_t<!std::is_same<T, char>::value, AsmResourceBlob>
-  allocate(ArrayRef<T> data, bool dataIsMutable = false) {
-    return allocate(
+  static AsmResourceBlob allocateInferAlign(ArrayRef<T> data,
+                                            bool dataIsMutable = false) {
+    return allocateWithAlign(
         ArrayRef<char>((const char *)data.data(), data.size() * sizeof(T)),
         alignof(T));
   }

diff  --git a/mlir/unittests/IR/AttributeTest.cpp b/mlir/unittests/IR/AttributeTest.cpp
index 1a3342b1c6dc..e393b83df78d 100644
--- a/mlir/unittests/IR/AttributeTest.cpp
+++ b/mlir/unittests/IR/AttributeTest.cpp
@@ -219,8 +219,8 @@ template <typename AttrT, typename T>
 static void checkNativeAccess(MLIRContext *ctx, ArrayRef<T> data,
                               Type elementType) {
   auto type = RankedTensorType::get(data.size(), elementType);
-  auto attr =
-      AttrT::get(type, "resource", UnmanagedAsmResourceBlob::allocate(data));
+  auto attr = AttrT::get(type, "resource",
+                         UnmanagedAsmResourceBlob::allocateInferAlign(data));
 
   // Check that we can access and iterate the data properly.
   Optional<ArrayRef<T>> attrData = attr.tryGetAsArrayRef();
@@ -279,7 +279,7 @@ TEST(DenseResourceElementsAttrTest, CheckNoCast) {
   ArrayRef<uint32_t> data;
   auto type = RankedTensorType::get(data.size(), builder.getI32Type());
   Attribute i32ResourceAttr = DenseI32ResourceElementsAttr::get(
-      type, "resource", UnmanagedAsmResourceBlob::allocate(data));
+      type, "resource", UnmanagedAsmResourceBlob::allocateInferAlign(data));
 
   EXPECT_TRUE(i32ResourceAttr.isa<DenseI32ResourceElementsAttr>());
   EXPECT_FALSE(i32ResourceAttr.isa<DenseF32ResourceElementsAttr>());
@@ -296,7 +296,8 @@ TEST(DenseResourceElementsAttrTest, CheckInvalidData) {
   EXPECT_DEBUG_DEATH(
       {
         DenseBoolResourceElementsAttr::get(
-            type, "resource", UnmanagedAsmResourceBlob::allocate(data));
+            type, "resource",
+            UnmanagedAsmResourceBlob::allocateInferAlign(data));
       },
       "alignment mismatch between expected alignment and blob alignment");
 }
@@ -311,7 +312,8 @@ TEST(DenseResourceElementsAttrTest, CheckInvalidType) {
   EXPECT_DEBUG_DEATH(
       {
         DenseBoolResourceElementsAttr::get(
-            type, "resource", UnmanagedAsmResourceBlob::allocate(data));
+            type, "resource",
+            UnmanagedAsmResourceBlob::allocateInferAlign(data));
       },
       "invalid shape element type for provided type `T`");
 }


        


More information about the Mlir-commits mailing list