lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.37k stars 156 forks source link

Bug: Comparing lists using the `==` and `!=` operators leads to an LLVM code generation error #2676

Closed kmr-srbh closed 1 month ago

kmr-srbh commented 2 months ago
from lpython import i32

my_first_list: list[i32] = [1, 2, 3, 4]
my_second_list: list[i32] = [5, 6, 7, 8]

print(my_first_list == my_second_list)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
; ModuleID = 'LFortran'
source_filename = "LFortran"

%list = type { i32, i32, i32* }
.
.
.
declare void @_lpython_call_initial_functions(i32, i8**)

attributes #0 = { argmemonly nounwind willreturn }
asr_to_llvm: module failed verification. Error:
Basic Block in function '__module___main_____main__global_stmts' does not have terminator!
label %.entry

code generation error: asr_to_llvm: module failed verification. Error:
Basic Block in function '__module___main_____main__global_stmts' does not have terminator!
label %.entry

Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.

The issue is the same for !=. It does not occur for > and <.

Shaikh-Ubaid commented 2 months ago
% cat examples/expr2.py 
from lpython import i32

def main():
    my_first_list: list[i32] = [1, 2, 3, 4]
    my_second_list: list[i32] = [5, 6, 7, 8]

    print(my_first_list == my_second_list)

main()
% python examples/expr2.py 
False
% lpython examples/expr2.py
False

It seems this happens only for global list variables.

kmr-srbh commented 2 months ago

Thanks for confirming this @Shaikh-Ubaid!