Core: Give bools C's rules: widen to 0 or 1, narrow by comparing with zero

A bool is ir.IntType(1), so convert() handled it as a 1-bit integer: a
bool slot's plain descriptor read as signed and True sign-extended to
-1 on the way out, and an integer narrowed to a bool by truncation, so
2 became false. Both predate this branch. C widens a bool to 0 or 1 and
narrows to it with != 0, and Python's truthiness agrees on the second.

signedness() now answers unsigned for any 1-bit integer whatever it is
wrapped in, convert() narrows to width 1 with icmp ne 0, and a bool
constant's slot carries the unsigned descriptor like the comparison
results already do.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Pragyansh Chaturvedi
2026-09-24 16:52:59 +05:30
parent eaaa12eecb
commit a230b440b9
3 changed files with 10 additions and 1 deletions

View File

@ -50,6 +50,11 @@ def int_literal_type(value: int) -> IntTy:
def signedness(ty) -> bool:
"""Sign of a descriptor: an IntTy says; a vmlinux Field says through its
ctype; a 1-bit integer is a bool and never negative, whatever it is
wrapped in; anything else is signed, the pre-signedness default."""
if isinstance(ty, ir.IntType) and ty.width == 1:
return False
"""Sign of an integer type descriptor.
IntTy carries it directly. A vmlinux Field carries a ctypes class in .type,