[clang] [CIR] Upstream SizeOf for VariableArrayType (PR #169993)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 30 04:04:54 PST 2025
================
@@ -2344,25 +2344,29 @@ mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
} else {
// C99 6.5.3.4p2: If the argument is an expression of type
// VLA, it is evaluated.
- cgf.getCIRGenModule().errorNYI(
- e->getSourceRange(),
- "sizeof operator for VariableArrayType & evaluateExtent "
- "ignoredExpr",
- e->getStmtClassName());
- return {};
+ cgf.emitIgnoredExpr(e->getArgumentExpr());
}
// For _Countof, we just want to return the size of a single dimension.
if (kind == UETT_CountOf)
return cgf.getVLAElements1D(vat).numElts;
- cgf.getCIRGenModule().errorNYI(
- e->getSourceRange(),
- "sizeof operator for VariableArrayType & evaluateExtent",
- e->getStmtClassName());
- return builder.getConstant(
- loc, cir::IntAttr::get(cgf.cgm.uInt64Ty,
- -llvm::APSInt(llvm::APInt(64, 1), true)));
+ // For sizeof and __datasizeof, we need to scale the number of elements
+ // by the size of the array element type.
+ auto vlaSize = cgf.getVLASize(vat);
----------------
AmrDeveloper wrote:
VlaSizePair is a struct inside CIRGenFunction to use the name we need to write it like
```
CIRGenFunction::VlaSizePair vlaSize = cgf.getVLASize(vat);
```
not sure if that's helpful 🤔
https://github.com/llvm/llvm-project/pull/169993
More information about the cfe-commits
mailing list