Skip to content

Commit

Permalink
[CIR][CodeGen] Support side effects in address space casting (llvm#673)
Browse files Browse the repository at this point in the history
Continue the work of llvm#652 . Test the branch of null pointer expressions
with side effects.
  • Loading branch information
seven-mile authored and lanza committed Oct 12, 2024
1 parent e3d01b4 commit 16d736f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 2 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1522,9 +1522,8 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
// If E has side effect, it is emitted even if its final result is a
// null pointer. In that case, a DCE pass should be able to
// eliminate the useless instructions emitted during translating E.
if (Result.HasSideEffects) {
llvm_unreachable("NYI");
}
if (Result.HasSideEffects)
Visit(E);
return CGF.CGM.buildNullConstant(DestTy, CGF.getLoc(E->getExprLoc()));
}
// Since target may map different address spaces in AST to the same address
Expand Down
11 changes: 11 additions & 0 deletions clang/test/CIR/CodeGen/address-space-conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ void test_nullptr() {
// LLVM: store ptr addrspace(1) null, ptr %{{[0-9]+}}, align 8
// LLVM-NEXT: store ptr addrspace(2) null, ptr %{{[0-9]+}}, align 8
}

void test_side_effect(pi1_t b) {
pi2_t p = (pi2_t)(*b++, (int*)0);
// CIR: %{{[0-9]+}} = cir.ptr_stride(%{{[0-9]+}} : !cir.ptr<!s32i, addrspace(1)>, %{{[0-9]+}} : !s32i), !cir.ptr<!s32i, addrspace(1)>
// CIR: %[[#CAST:]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i, addrspace(2)>
// CIR-NEXT: cir.store %[[#CAST]], %{{[0-9]+}} : !cir.ptr<!s32i, addrspace(2)>, !cir.ptr<!cir.ptr<!s32i, addrspace(2)>>

// LLVM: %{{[0-9]+}} = getelementptr i32, ptr addrspace(1) %{{[0-9]+}}, i64 1
// LLVM: store ptr addrspace(2) null, ptr %{{[0-9]+}}, align 8

}

0 comments on commit 16d736f

Please sign in to comment.