bool(int32) is broken #119

Closed
opened 2021-11-29 18:21:26 +08:00 by sb10q · 0 comments
@extern
def output_int(x: int32):
    ...

def run() -> int32:
    if bool(6):
        output_int(0)
    else:
        output_int(1)
    return 0
$ ./run_demo.sh classes
setup time: 1ms
parse time: 0ms
analysis time: 0ms
codegen time (including LLVM): 15ms
total time: 17ms
1

The correct logic should be bool(x): x != 0. It seems currently that it does a naive cast to i1, which only looks at bit 0 i.e. returns if the number is odd.

```python @extern def output_int(x: int32): ... def run() -> int32: if bool(6): output_int(0) else: output_int(1) return 0 ``` ``` $ ./run_demo.sh classes setup time: 1ms parse time: 0ms analysis time: 0ms codegen time (including LLVM): 15ms total time: 17ms 1 ``` The correct logic should be ``bool(x): x != 0``. It seems currently that it does a naive cast to i1, which only looks at bit 0 i.e. returns if the number is odd.
sb10q added the
high-priority
label 2021-11-29 18:21:26 +08:00
sb10q added this to the Prealpha milestone 2021-11-29 18:21:55 +08:00
ychenfo was assigned by sb10q 2021-11-29 18:24:20 +08:00
sb10q closed this issue 2021-12-01 23:02:19 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#119
There is no content yet.