================ @@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { llvm_unreachable("Unknown unary operator kind!"); } +/// If the specified expr is a simple decay from an array to pointer, +/// return the array subexpression. +/// FIXME: this could be abstracted into a common AST helper. +static const Expr *isSimpleArrayDecayOperand(const Expr *e) { + // If this isn't just an array->pointer decay, bail out. + const auto *castExpr = dyn_cast<CastExpr>(e); + if (!castExpr || castExpr->getCastKind() != CK_ArrayToPointerDecay) + return nullptr; + + // If this is a decay from variable width array, bail out. + const Expr *subExpr = castExpr->getSubExpr(); + if (subExpr->getType()->isVariableArrayType()) + return nullptr; + + return subExpr; +} + +static mlir::IntegerAttr getConstantIndexOrNull(mlir::Value idx) { + // TODO(cir): should we consider using MLIRs IndexType instead of IntegerAttr? + if (auto constantOp = dyn_cast<cir::ConstantOp>(idx.getDefiningOp())) + return mlir::dyn_cast<mlir::IntegerAttr>(constantOp.getValue()); ---------------- andykaylor wrote:
Does this ever return non-null? I would expect the constantOp to have a `cir::IntAttr` rather than an `mlir::IntegerAttr`. I'm not sure the former can be cast to the latter. https://github.com/llvm/llvm-project/pull/134536 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits