@@ -2325,14 +2325,27 @@ mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
23252325 const QualType typeToSize = e->getTypeOfArgument ();
23262326 const mlir::Location loc = cgf.getLoc (e->getSourceRange ());
23272327 if (auto kind = e->getKind ();
2328- kind == UETT_SizeOf || kind == UETT_DataSizeOf) {
2329- if (cgf.getContext ().getAsVariableArrayType (typeToSize)) {
2330- cgf.getCIRGenModule ().errorNYI (e->getSourceRange (),
2331- " sizeof operator for VariableArrayType" ,
2332- e->getStmtClassName ());
2333- return builder.getConstant (
2334- loc, cir::IntAttr::get (cgf.cgm .uInt64Ty ,
2335- llvm::APSInt (llvm::APInt (64 , 1 ), true )));
2328+ kind == UETT_SizeOf || kind == UETT_DataSizeOf || kind == UETT_CountOf) {
2329+ if (const VariableArrayType *vat =
2330+ cgf.getContext ().getAsVariableArrayType (typeToSize)) {
2331+ // For _Countof, we only want to evaluate if the extent is actually
2332+ // variable as opposed to a multi-dimensional array whose extent is
2333+ // constant but whose element type is variable.
2334+ bool evaluateExtent = true ;
2335+ if (kind == UETT_CountOf && vat->getElementType ()->isArrayType ()) {
2336+ evaluateExtent =
2337+ !vat->getSizeExpr ()->isIntegerConstantExpr (cgf.getContext ());
2338+ }
2339+
2340+ if (evaluateExtent) {
2341+ cgf.getCIRGenModule ().errorNYI (
2342+ e->getSourceRange (),
2343+ " sizeof operator for VariableArrayType & evaluateExtent" ,
2344+ e->getStmtClassName ());
2345+ return builder.getConstant (
2346+ loc, cir::IntAttr::get (cgf.cgm .uInt64Ty ,
2347+ -llvm::APSInt (llvm::APInt (64 , 1 ), true )));
2348+ }
23362349 }
23372350 } else if (e->getKind () == UETT_OpenMPRequiredSimdAlign) {
23382351 cgf.getCIRGenModule ().errorNYI (
0 commit comments