[Mlir-commits] [mlir] [mlir][emitc] Add EmitC index types (PR #93155)

Corentin Ferry llvmlistbot at llvm.org
Tue May 28 00:05:26 PDT 2024


================
@@ -1570,6 +1570,10 @@ LogicalResult CppEmitter::emitType(Location loc, Type type) {
   }
   if (auto iType = dyn_cast<IndexType>(type))
     return (os << "size_t"), success();
+  if (auto sType = dyn_cast<emitc::SizeTType>(type))
+    return (os << "size_t"), success();
+  if (auto sType = dyn_cast<emitc::SignedSizeTType>(type))
+    return (os << "ssize_t"), success();
----------------
cferry-AMD wrote:

Me too, don't worry. I thought those two types came together, indeed they don't. 

`intmax_t` will be able to represent any value `index` can, `ptrdiff_t` seems more geared towards pointer arithmetics. On the other hand, if we use `size_t` for the unsigned type, casts from `intmax_t` to `size_t` aren't guaranteed to preserve the value (`intmax_t` may be much larger than `size_t`), whereas

> For char arrays shorter than [PTRDIFF_MAX](https://en.cppreference.com/w/c/types/limits), ptrdiff_t acts as the signed counterpart of [size_t](https://en.cppreference.com/w/c/types/size_t)

also per the MLIR doc:

> The index type models target-specific values of pointer width, like `intptr_t`.

so we don't need anything wider than `ptrdiff_t`. Should we use `intmax_t` for the signed type, we'd need `uintmax_t` for the unsigned type.

Thoughts?

https://github.com/llvm/llvm-project/pull/93155


More information about the Mlir-commits mailing list