From 5f868513edc6d04485f920467cbe39382a98cf3d Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Tue, 5 Jan 2021 12:54:29 +0000 Subject: [PATCH] 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. --- regression/ansi-c/sizeof4/test.desc | 2 +- src/ansi-c/c_typecheck_expr.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/regression/ansi-c/sizeof4/test.desc b/regression/ansi-c/sizeof4/test.desc index fc2b1874059..466da18b2b5 100644 --- a/regression/ansi-c/sizeof4/test.desc +++ b/regression/ansi-c/sizeof4/test.desc @@ -1,4 +1,4 @@ -KNOWNBUG +CORE main.c ^EXIT=0$ diff --git a/src/ansi-c/c_typecheck_expr.cpp b/src/ansi-c/c_typecheck_expr.cpp index 406671379a9..975123572cd 100644 --- a/src/ansi-c/c_typecheck_expr.cpp +++ b/src/ansi-c/c_typecheck_expr.cpp @@ -950,7 +950,14 @@ 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) + type = signed_int_type(); + else + type = op.type(); } exprt new_expr;