lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.51k stars 164 forks source link

BitwiseOr failing in LP but not in CP #2130

Open rebcabin opened 1 year ago

rebcabin commented 1 year ago

MVE:

from lpython import (i8, # i32, i64, f32, f64,
                     dataclass
                     )
from numpy import (empty,
                   int8,
                   )

r : i8 = i8(240)

@dataclass
class Foo:
    a : i8[4] = empty(4, dtype=int8)

def trinary_majority(x : Foo, y : Foo, z : Foo) -> Foo:
    foo : Foo = Foo()
    ##################### ATTENTION: THE OFFENDING LINE #################
    foo.a = x.a | y.a | z.a
    return foo

t1 : Foo = Foo()
t1.a = empty(4, dtype=int8)

t2 : Foo = Foo()
t2.a = empty(4, dtype=int8)

t3 : Foo = Foo()
t3.a = empty(4, dtype=int8)

r1 : Foo = trinary_majority(t1, t2, t3)

runs:

(lp) ┌─(~/CLionProjects/lpython/lasr/LP-pycharm)─────────────────────────────────────────────────────────────────────────────────────────────────────────(brian@Golf37:s012)─┐
└─(11:30:10 on brian-lasr ✹ ✭)──> ~/CLionProjects/lpython/src/bin/lpython -I. issue2126.py                                                                ──(Sun,Jul09)─┘
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
  File "/Users/brian/CLionProjects/lpython/src/bin/lpython.cpp", line 1844
    err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir,
  File "/Users/brian/CLionProjects/lpython/src/bin/lpython.cpp", line 809
    res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
  File "/Users/brian/CLionProjects/lpython/src/lpython/python_evaluator.cpp", line 58
    run_fn, infile);
  File "/Users/brian/CLionProjects/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 7863
    v.visit_asr((ASR::asr_t&)asr);
  File "../libasr/asr.h", line 4912
  File "../libasr/asr.h", line 4889
  File "../libasr/asr.h", line 4913
  File "../libasr/asr.h", line 4634
  File "/Users/brian/CLionProjects/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 858
    ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
  File "../libasr/asr.h", line 4915
  File "../libasr/asr.h", line 4642
  File "/Users/brian/CLionProjects/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 2543
    finish_module_init_function_prototype(x);
  File "/Users/brian/CLionProjects/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 3313
    visit_Function(*s);
  File "/Users/brian/CLionProjects/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 3083
    visit_procedures(x);
  File "/Users/brian/CLionProjects/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 3264
    this->visit_stmt(*x.m_body[i]);
  File "../libasr/asr.h", line 4932
  File "../libasr/asr.h", line 4666
  File "/Users/brian/CLionProjects/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 4080
    value = llvm_utils->create_gep(value, 0);
  File "/Users/brian/CLionProjects/lpython/src/libasr/codegen/llvm_utils.cpp", line 1267
    return LLVM::CreateGEP(*builder, ds, idx_vec);
  File "/Users/brian/CLionProjects/lpython/src/libasr/codegen/llvm_utils.cpp", line 25
    LCOMPILERS_ASSERT(t->isPointerTy());
AssertFailed: t->isPointerTy()
rebcabin commented 1 year ago

Here is another expression that fails in a similar way:

    # Issue 2130
    # foo.a = x.a | y.a | z.a
    foo.a = (x.a & y.a) | (y.a & z.a) | (z.a & x.a)