mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 09:58:34 +00:00
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:
@ -263,7 +263,7 @@ def _allocate_for_constant(builder, var_name, rval, local_sym_tab):
|
||||
"""Allocate memory for variable assigned from a constant."""
|
||||
|
||||
if isinstance(rval.value, bool):
|
||||
ir_type = ir.IntType(1)
|
||||
ir_type = IntTy(1, False) # a bool widens to 0 or 1, never sign-extends
|
||||
var = builder.alloca(ir_type, name=var_name)
|
||||
var.align = 1
|
||||
local_sym_tab[var_name] = LocalSymbol(var, ir_type)
|
||||
|
||||
Reference in New Issue
Block a user