@@ -92,6 +92,8 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
9292
9393 mlir::Value VisitCastExpr (CastExpr *E);
9494
95+ mlir::Value VisitUnaryExprOrTypeTraitExpr (const UnaryExprOrTypeTraitExpr *e);
96+
9597 // / Emit a conversion from the specified type to the specified destination
9698 // / type, both of which are CIR scalar types.
9799 // / TODO: do we need ScalarConversionOpts here? Should be done in another
@@ -148,3 +150,41 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
148150 }
149151 return {};
150152}
153+
154+ // / Return the size or alignment of the type of argument of the sizeof
155+ // / expression as an integer.
156+ mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr (
157+ const UnaryExprOrTypeTraitExpr *e) {
158+ const QualType typeToSize = e->getTypeOfArgument ();
159+ const mlir::Location loc = cgf.getLoc (e->getSourceRange ());
160+ if (auto kind = e->getKind ();
161+ kind == UETT_SizeOf || kind == UETT_DataSizeOf) {
162+ if (const VariableArrayType *variableArrTy =
163+ cgf.getContext ().getAsVariableArrayType (typeToSize)) {
164+ cgf.getCIRGenModule ().errorNYI (e->getSourceRange (),
165+ " sizeof operator for VariableArrayType" ,
166+ e->getStmtClassName ());
167+ return builder.getConstant (
168+ loc, builder.getAttr <cir::IntAttr>(
169+ cgf.cgm .UInt64Ty , llvm::APSInt (llvm::APInt (64 , 1 ), true )));
170+ }
171+ } else if (e->getKind () == UETT_OpenMPRequiredSimdAlign) {
172+ cgf.getCIRGenModule ().errorNYI (
173+ e->getSourceRange (), " sizeof operator for OpenMpRequiredSimdAlign" ,
174+ e->getStmtClassName ());
175+ return builder.getConstant (
176+ loc, builder.getAttr <cir::IntAttr>(
177+ cgf.cgm .UInt64Ty , llvm::APSInt (llvm::APInt (64 , 1 ), true )));
178+ } else if (e->getKind () == UETT_VectorElements) {
179+ cgf.getCIRGenModule ().errorNYI (e->getSourceRange (),
180+ " sizeof operator for VectorElements" ,
181+ e->getStmtClassName ());
182+ return builder.getConstant (
183+ loc, builder.getAttr <cir::IntAttr>(
184+ cgf.cgm .UInt64Ty , llvm::APSInt (llvm::APInt (64 , 1 ), true )));
185+ }
186+
187+ return builder.getConstant (
188+ loc, builder.getAttr <cir::IntAttr>(
189+ cgf.cgm .UInt64Ty , e->EvaluateKnownConstInt (cgf.getContext ())));
190+ }
0 commit comments