Skip to content

Commit

Permalink
[CIR][CIRGen] Add missing case to 'isNullValue'
Browse files Browse the repository at this point in the history
Support for BoolAttr in isNullValue
  • Loading branch information
YazZz1k committed Jan 31, 2024
1 parent 9bc8b47 commit f5f777b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
if (const auto intVal = attr.dyn_cast<mlir::cir::IntAttr>())
return intVal.isNullValue();

if (const auto boolVal = attr.dyn_cast<mlir::cir::BoolAttr>())
return !boolVal.getValue();

if (const auto fpVal = attr.dyn_cast<mlir::FloatAttr>()) {
bool ignored;
llvm::APFloat FV(+0.0);
Expand Down
10 changes: 9 additions & 1 deletion clang/test/CIR/CodeGen/bool.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ typedef struct {
bool x;
} S;

// CHECK: cir.func @init_bool
// CHECK: [[ALLOC:%.*]] = cir.alloca !ty_22S22, cir.ptr <!ty_22S22>
// CHECK: [[ZERO:%.*]] = cir.const(#cir.zero : !ty_22S22) : !ty_22S22
// CHECK: cir.store [[ZERO]], [[ALLOC]] : !ty_22S22, cir.ptr <!ty_22S22>
void init_bool(void) {
S s = {0};
}

// CHECK: cir.func @store_bool
// CHECK: [[TMP0:%.*]] = cir.alloca !cir.ptr<!ty_22S22>, cir.ptr <!cir.ptr<!ty_22S22>>
// CHECK: cir.store %arg0, [[TMP0]] : !cir.ptr<!ty_22S22>, cir.ptr <!cir.ptr<!ty_22S22>>
Expand All @@ -28,4 +36,4 @@ void store_bool(S *s) {
// CHECK: [[TMP4:%.*]] = cir.load [[TMP3]] : cir.ptr <!cir.bool>, !cir.bool
void load_bool(S *s) {
bool x = s->x;
}
}

0 comments on commit f5f777b

Please sign in to comment.