================ @@ -73,21 +73,59 @@ Address CIRGenFunction::emitPointerWithAlignment(const Expr *expr, // Casts: if (auto const *ce = dyn_cast<CastExpr>(expr)) { - if (isa<ExplicitCastExpr>(ce)) { - cgm.errorNYI(expr->getSourceRange(), - "emitPointerWithAlignment: explicit cast"); - return Address::invalid(); - } + if (const auto *ece = dyn_cast<ExplicitCastExpr>(ce)) + cgm.emitExplicitCastExprType(ece); switch (ce->getCastKind()) { // Non-converting casts (but not C's implicit conversion from void*). case CK_BitCast: case CK_NoOp: case CK_AddressSpaceConversion: { - cgm.errorNYI(expr->getSourceRange(), - "emitPointerWithAlignment: noop cast"); - return Address::invalid(); - } break; + if (const auto *ptrTy = + ce->getSubExpr()->getType()->getAs<PointerType>()) { + if (ptrTy->getPointeeType()->isVoidType()) + break; + + LValueBaseInfo innerBaseInfo; + Address addr = + emitPointerWithAlignment(ce->getSubExpr(), &innerBaseInfo); + if (baseInfo) + *baseInfo = innerBaseInfo; + + if (isa<ExplicitCastExpr>(ce)) { + LValueBaseInfo targetTypeBaseInfo; + + const QualType pointeeType = expr->getType()->getPointeeType(); + const CharUnits align = + cgm.getNaturalTypeAlignment(pointeeType, &targetTypeBaseInfo); + + // If the source l-value is opaque, honor the alignment of the + // casted-to type. + if (innerBaseInfo.getAlignmentSource() != AlignmentSource::Decl) { + if (baseInfo) + baseInfo->mergeForCast(targetTypeBaseInfo); + addr = Address(addr.getPointer(), addr.getElementType(), align); + } + } + + if (sanOpts.has(SanitizerKind::CFIUnrelatedCast) && + ce->getCastKind() == CK_BitCast) { + if (expr->getType()->getAs<PointerType>()) + llvm_unreachable("NYI"); + } + + const auto eltTy = convertTypeForMem(expr->getType()->getPointeeType()); ---------------- mmha wrote:
```suggestion const mlir::Type eltTy = convertTypeForMem(expr->getType()->getPointeeType()); ``` https://github.com/llvm/llvm-project/pull/154060 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits