Skip to content

Removes hasBooleanRepresentation #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// This contains code to emit Expr nodes as CIR code.
//
//===----------------------------------------------------------------------===//

#include "CIRGenBuilder.h"
#include "CIRGenCXXABI.h"
#include "CIRGenCall.h"
Expand Down Expand Up @@ -2210,9 +2209,8 @@ mlir::Value CIRGenFunction::buildLoadOfScalar(LValue lvalue,
}

mlir::Value CIRGenFunction::buildFromMemory(mlir::Value Value, QualType Ty) {
// Bool has a different representation in memory than in registers.
if (hasBooleanRepresentation(Ty)) {
llvm_unreachable("NYI");
if (!Ty->isBooleanType() && hasBooleanRepresentation(Ty)) {
llvm_unreachable("NIY");
}

return Value;
Expand Down
5 changes: 1 addition & 4 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,8 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
/// Emits the address of the l-value, then loads and returns the result.
mlir::Value buildLoadOfLValue(const Expr *E) {
LValue LV = CGF.buildLValue(E);
auto load = Builder.create<mlir::cir::LoadOp>(CGF.getLoc(E->getExprLoc()),
CGF.getCIRType(E->getType()),
LV.getPointer());
// FIXME: add some akin to EmitLValueAlignmentAssumption(E, V);
return load;
return CGF.buildLoadOfLValue(LV, E->getExprLoc()).getScalarVal();
}

mlir::Value buildLoadOfLValue(LValue LV, SourceLocation Loc) {
Expand Down
31 changes: 31 additions & 0 deletions clang/test/CIR/CodeGen/bool.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir-enable -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

#include <stdbool.h>

typedef struct {
bool x;
} S;

// 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>>
// CHECK: [[TMP1:%.*]] = cir.const(#cir.int<0> : !s32i) : !s32i
// CHECK: [[TMP2:%.*]] = cir.cast(int_to_bool, [[TMP1]] : !s32i), !cir.bool
// CHECK: [[TMP3:%.*]] = cir.load [[TMP0]] : cir.ptr <!cir.ptr<!ty_22S22>>, !cir.ptr<!ty_22S22>
// CHECK: [[TMP4:%.*]] = cir.get_member [[TMP3]][0] {name = "x"} : !cir.ptr<!ty_22S22> -> !cir.ptr<!cir.bool>
// CHECK: cir.store [[TMP2]], [[TMP4]] : !cir.bool, cir.ptr <!cir.bool>
void store_bool(S *s) {
s->x = false;
}

// CHECK: cir.func @load_bool
// CHECK: [[TMP0:%.*]] = cir.alloca !cir.ptr<!ty_22S22>, cir.ptr <!cir.ptr<!ty_22S22>>, ["s", init] {alignment = 8 : i64}
// CHECK: [[TMP1:%.*]] = cir.alloca !cir.bool, cir.ptr <!cir.bool>, ["x", init] {alignment = 1 : i64}
// CHECK: cir.store %arg0, [[TMP0]] : !cir.ptr<!ty_22S22>, cir.ptr <!cir.ptr<!ty_22S22>>
// CHECK: [[TMP2:%.*]] = cir.load [[TMP0]] : cir.ptr <!cir.ptr<!ty_22S22>>, !cir.ptr<!ty_22S22>
// CHECK: [[TMP3:%.*]] = cir.get_member [[TMP2]][0] {name = "x"} : !cir.ptr<!ty_22S22> -> !cir.ptr<!cir.bool>
// CHECK: [[TMP4:%.*]] = cir.load [[TMP3]] : cir.ptr <!cir.bool>, !cir.bool
void load_bool(S *s) {
bool x = s->x;
}