Skip to content

Commit f5f777b

Browse files
committed
[CIR][CIRGen] Add missing case to 'isNullValue'
Support for BoolAttr in isNullValue
1 parent 9bc8b47 commit f5f777b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
250250
if (const auto intVal = attr.dyn_cast<mlir::cir::IntAttr>())
251251
return intVal.isNullValue();
252252

253+
if (const auto boolVal = attr.dyn_cast<mlir::cir::BoolAttr>())
254+
return !boolVal.getValue();
255+
253256
if (const auto fpVal = attr.dyn_cast<mlir::FloatAttr>()) {
254257
bool ignored;
255258
llvm::APFloat FV(+0.0);

clang/test/CIR/CodeGen/bool.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ typedef struct {
77
bool x;
88
} S;
99

10+
// CHECK: cir.func @init_bool
11+
// CHECK: [[ALLOC:%.*]] = cir.alloca !ty_22S22, cir.ptr <!ty_22S22>
12+
// CHECK: [[ZERO:%.*]] = cir.const(#cir.zero : !ty_22S22) : !ty_22S22
13+
// CHECK: cir.store [[ZERO]], [[ALLOC]] : !ty_22S22, cir.ptr <!ty_22S22>
14+
void init_bool(void) {
15+
S s = {0};
16+
}
17+
1018
// CHECK: cir.func @store_bool
1119
// CHECK: [[TMP0:%.*]] = cir.alloca !cir.ptr<!ty_22S22>, cir.ptr <!cir.ptr<!ty_22S22>>
1220
// CHECK: cir.store %arg0, [[TMP0]] : !cir.ptr<!ty_22S22>, cir.ptr <!cir.ptr<!ty_22S22>>
@@ -28,4 +36,4 @@ void store_bool(S *s) {
2836
// CHECK: [[TMP4:%.*]] = cir.load [[TMP3]] : cir.ptr <!cir.bool>, !cir.bool
2937
void load_bool(S *s) {
3038
bool x = s->x;
31-
}
39+
}

0 commit comments

Comments
 (0)