mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
Core: Return through the same value path as every other consumer
A pointer used where a value is expected is dereferenced to it, with a null check, in helper arguments, printk arguments, binary-operation operands and comparisons, all through deref_to_depth. return was the one consumer that never joined that convention, so `return p` on a map lookup emitted `ret i64*` and left it to llc to reject. handle_return now goes through get_typed_operand, which is that path, and converts the result to the declared return type like the augmented-assignment store does. convert() no longer passes a non-integer through silently: every caller either checks both sides or is on an integer-only path, so what reaches that branch is a type error, and it is raised with both types named instead of surfacing from llc with an IR line number. Returning a struct value is the case that now fails at compile time. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@ -53,7 +53,12 @@ def convert(builder, val, from_ty, to_ty):
|
||||
value itself, which may already be wider than its descriptor says.
|
||||
"""
|
||||
if not (isinstance(to_ty, ir.IntType) and isinstance(val.type, ir.IntType)):
|
||||
return val
|
||||
# Every caller either checks both sides are integers or sits on a path
|
||||
# that only carries integers, so reaching here is a type error that
|
||||
# would otherwise surface as an llc rejection with no Python line.
|
||||
raise TypeError(
|
||||
f"integer conversion requested for a {val.type} value to {to_ty}"
|
||||
)
|
||||
if val.type.width > to_ty.width:
|
||||
return builder.trunc(val, to_ty)
|
||||
if val.type.width < to_ty.width:
|
||||
|
||||
Reference in New Issue
Block a user