forked from M-Labs/nac3
David Mak
31dcd2dde9
In LLVM, i1 represents a 1-byte integer with a single valid bit; The rest of the 7 upper bits are undefined. This causes problems when using these variables in memory operations (e.g. memcpy/memmove as needed by List slicing and assignment). We fix this by treating all local boolean variables as i8 so that they are well-defined for memory operations. Function ABIs will continue to use i1, as memory operations cannot be directly performed on function arguments or return types, instead they are always converted back into local boolean variables (which are i8s anyways). Fixes #315.
30 lines
472 B
Python
30 lines
472 B
Python
# Different cases for using boolean variables in boolean contexts.
|
|
# Tests whether all boolean variables (expressed as i8s) are lowered into i1s before used in branching instruction (`br`)
|
|
|
|
def bfunc(b: bool) -> bool:
|
|
return not b
|
|
|
|
def run() -> int32:
|
|
b1 = True
|
|
b2 = False
|
|
|
|
if b1:
|
|
pass
|
|
|
|
if not b2:
|
|
pass
|
|
|
|
while b2:
|
|
pass
|
|
|
|
l = [i for i in range(10) if b2]
|
|
|
|
b_and = True and False
|
|
b_or = True or False
|
|
|
|
b_and = b1 and b2
|
|
b_or = b1 or b2
|
|
|
|
bfunc(b1)
|
|
|
|
return 0 |