[clang] [CIR] Upstream basic support for sizeof and alignof (PR #130847)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 12 07:36:30 PDT 2025


================
@@ -148,3 +150,27 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
   }
   return {};
 }
+
+/// Return the size or alignment of the type of argument of the sizeof
+/// expression as an integer.
+mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
+    const UnaryExprOrTypeTraitExpr *e) {
+  const QualType typeToSize = e->getTypeOfArgument();
+  if (e->getKind() == UETT_SizeOf) {
+    if (const VariableArrayType *variableArrTy =
+            cgf.getContext().getAsVariableArrayType(typeToSize)) {
+      cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
----------------
erichkeane wrote:

I think instead that after each of these `errorNYI` diagnostics, we are better just returning a constant value that is reasonably sensible.  A `1` or a `ptr-size` both seem reasonable to me.

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


More information about the cfe-commits mailing list