Skip to content

Commit

Permalink
C front-end: hide our use of single-bit bool within sizeof
Browse files Browse the repository at this point in the history
In C, Boolean operations are of type int. Rejecting sizeof expressions
of Boolean operations breaks building the Linux kernel.
  • Loading branch information
tautschnig committed Mar 3, 2021
1 parent 7f998c4 commit 565b12e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion regression/ansi-c/sizeof4/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.c

^EXIT=0$
Expand Down
16 changes: 15 additions & 1 deletion src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,21 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
}
else
{
type.swap(to_unary_expr(expr).op().type());
const exprt &op = to_unary_expr(as_const(expr)).op();
// This is one of the few places where it's detectable
// that we are using "bool" for boolean operators instead
// of "int". We convert for this reason.
if(
op.type().id() == ID_bool &&
(op.id() == ID_not || op.id() == ID_and || op.id() == ID_or ||
op.id() == ID_equal || op.id() == ID_notequal || op.id() == ID_lt ||
op.id() == ID_le || op.id() == ID_gt || op.id() == ID_ge ||
op.id() == ID_if))
{
type = signed_int_type();
}
else
type = op.type();
}

exprt new_expr;
Expand Down

0 comments on commit 565b12e

Please sign in to comment.