Skip to content

Commit 337b0ec

Browse files
committed
- Add more test cases (int_to_bool, ptr_to_bool, float_to_bool)
- Handle IgnoredExpr on null_to_pointer casts
1 parent 06160a0 commit 337b0ec

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,7 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
456456

457457
case CK_NullToPointer: {
458458
if (MustVisitNullValue(subExpr))
459-
cgf.getCIRGenModule().errorNYI(
460-
subExpr->getSourceRange(),
461-
"ignored expression on null to pointer cast");
459+
cgf.emitIgnoredExpr(subExpr);
462460

463461
// Note that DestTy is used as the MLIR type instead of a custom
464462
// nullptr type.

clang/test/CIR/CodeGen/cast.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ int cStyleCasts_0(unsigned x1, int x2, float x3, short x4, double x5) {
3939
int bi = (int)ib; // bool to int
4040
// CHECK: %{{[0-9]+}} = cir.cast(bool_to_int, %{{[0-9]+}} : !cir.bool), !cir.int<s, 32>
4141

42+
bool b2 = x2; // int to bool
43+
// CHECK: %{{[0-9]+}} = cir.cast(int_to_bool, %{{[0-9]+}} : !cir.int<s, 32>), !cir.bool
44+
45+
void *p;
46+
bool b3 = p; // ptr to bool
47+
// CHECK: %{{[0-9]+}} = cir.cast(ptr_to_bool, %{{[0-9]+}} : !cir.ptr<!cir.void>), !cir.bool
48+
49+
float f;
50+
bool b4 = f; // float to bool
51+
// CHECK: %{{[0-9]+}} = cir.cast(float_to_bool, %{{[0-9]+}} : !cir.float), !cir.bool
52+
4253
return 0;
4354
}
4455

@@ -58,7 +69,8 @@ void should_not_cast() {
5869

5970
unsigned uu = (unsigned)x1;
6071
bool ib = (bool)x1;
61-
(void) ib;
72+
73+
(void) ib; // void cast
6274
}
6375

6476
// CHECK: cir.func @should_not_cast

0 commit comments

Comments
 (0)