================
@@ -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);
+ mlir::Value numElts = vlaSize.numElts;
+
+ // Scale the number of non-VLA elements by the non-VLA element size.
+ CharUnits eltSize = cgf.getContext().getTypeSizeInChars(vlaSize.type);
+ if (!eltSize.isOne()) {
+ mlir::Location loc = cgf.getLoc(e->getSourceRange());
+ mlir::Value eltSizeValue =
+ builder.getConstAPInt(numElts.getLoc(), numElts.getType(),
+ cgf.cgm.getSize(eltSize).getValue());
+ return builder.createMul(loc, eltSizeValue, numElts);
----------------
andykaylor wrote:
```suggestion
return builder.createMul(loc, eltSizeValue, numElts,
OverflowBehavior::NoUnsignedWrap);
```
We need to start paying closer attention to this kind of thing. It's easier to
catch as the code is added than to track down later.
https://github.com/llvm/llvm-project/pull/169993
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits