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

Marius Brehler llvmlistbot at llvm.org
Mon May 27 12:24:08 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();
----------------
marbre wrote:

So far we were trying to follow the convention documented in https://github.com/llvm/llvm-project/blob/59c6bd156cc8b42758ce90909615748e21c6eee2/mlir/docs/Dialects/emitc.md, which at some point states `Else the generated code is compatible with C99.` As far as I know, this doesn't hold if `ssize_t` is emitted as this is included in the POSIX `<sys/types.h>` header but isn't strict C99. So the minimum is to update the docs accordingly. However, this introduces another include as discussed on [Discord](https://discord.com/channels/636084430946959380/1209151815007080468/1242366862549848086) (we should really try to move longer discussions to discourse though :smile:).

Furthermore, how do we handle if the emitted code should be C++?

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


More information about the Mlir-commits mailing list