diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index b1498f376725d..f8d29dc7da1b3 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -2144,18 +2144,9 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) { case CK_NonAtomicToAtomic: case CK_UserDefinedConversion: return Visit(const_cast(subExpr)); - case CK_NoOp: { - auto v = Visit(const_cast(subExpr)); - if (v) { - // CK_NoOp can model a pointer qualification conversion, which can remove - // an array bound and change the IR type. - // FIXME: Once pointee types are removed from IR, remove this. - mlir::Type t = cgf.convertType(destTy); - if (t != v.getType()) - cgf.getCIRGenModule().errorNYI("pointer qualification conversion"); - } - return v; - } + case CK_NoOp: + return ce->changesVolatileQualification() ? emitLoadOfLValue(ce) + : Visit(subExpr); case CK_IntegralToPointer: { mlir::Type destCIRTy = cgf.convertType(destTy); mlir::Value src = Visit(const_cast(subExpr)); diff --git a/clang/test/CIR/CodeGen/cast-cxx20.cpp b/clang/test/CIR/CodeGen/cast-cxx20.cpp index ebc2064dd0b69..802bcecafcb70 100644 --- a/clang/test/CIR/CodeGen/cast-cxx20.cpp +++ b/clang/test/CIR/CodeGen/cast-cxx20.cpp @@ -53,3 +53,22 @@ void cast3() { // LLVM: %[[TO_ARR_ALLOCA:.*]] = alloca ptr // LLVM: store ptr %[[ARR_ALLOCA]], ptr %[[TO_ARR_ALLOCA]] } + +void cast4() { + Arr4Ty* const *arrPP; + CArrNTy* const volatile *const constArrPP = arrPP; + + // CIR-LABEL: cir.func {{.*}}@_Z5cast4v() + // CIR: %[[ARR_PP_ALLOCA:.*]] = cir.alloca !cir.ptr>>, !cir.ptr>>>, ["arrPP"] + // CIR: %[[CONST_ARR_ALLOCA:.*]] = cir.alloca !cir.ptr>>, !cir.ptr>>>, ["constArrPP", init, const] + // CIR: %[[LOAD_ARR_PP:.*]] = cir.load align(8) %[[ARR_PP_ALLOCA]] : !cir.ptr>>>, !cir.ptr>> + // CIR: %[[CONST_ARR_CAST:.*]] = cir.cast bitcast %[[CONST_ARR_ALLOCA]] : !cir.ptr>>> -> !cir.ptr>>> + // CIR: cir.store{{.*}} %[[LOAD_ARR_PP]], %[[CONST_ARR_CAST]] : !cir.ptr>>, !cir.ptr>>> + // + // LLVM-LABEL: define {{.*}}@_Z5cast4v() + // LLVM: %[[ARR_PP_ALLOCA:.*]] = alloca ptr + // LLVM: %[[CONST_ARR_ALLOCA:.*]] = alloca ptr + // LLVM: %[[LOAD_ARR_PP:.*]] = load ptr, ptr %[[ARR_PP_ALLOCA]] + // LLVM: store ptr %[[LOAD_ARR_PP]], ptr %[[CONST_ARR_ALLOCA]] + +}