Skip to content

Commit 9331a88

Browse files
committed
C front-end: hide our use of single-bit bool within sizeof
In C, Boolean operations are of type int. Rejecting sizeof expressions of Boolean operations breaks building the Linux kernel.
1 parent 932599e commit 9331a88

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

regression/ansi-c/sizeof4/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,21 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
931931
}
932932
else
933933
{
934-
type.swap(to_unary_expr(expr).op().type());
934+
const exprt &op = to_unary_expr(as_const(expr)).op();
935+
// This is one of the few places where it's detectable
936+
// that we are using "bool" for boolean operators instead
937+
// of "int". We convert for this reason.
938+
if(
939+
op.type().id() == ID_bool &&
940+
(op.id() == ID_not || op.id() == ID_and || op.id() == ID_or ||
941+
op.id() == ID_equal || op.id() == ID_notequal || op.id() == ID_lt ||
942+
op.id() == ID_le || op.id() == ID_gt || op.id() == ID_ge ||
943+
op.id() == ID_if))
944+
{
945+
type = signed_int_type();
946+
}
947+
else
948+
type = op.type();
935949
}
936950

937951
exprt new_expr;

0 commit comments

Comments
 (0)