diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index f297cf2007..456e6f66ea 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -571,6 +571,7 @@ RUN(NAME test_unary_op_04 LABELS cpython llvm c) # unary bitinvert RUN(NAME test_unary_op_05 LABELS cpython llvm c) # unsigned unary minus, plus RUN(NAME test_unary_op_06 LABELS cpython llvm c) # unsigned unary bitnot RUN(NAME test_unsigned_01 LABELS cpython llvm c) # unsigned bitshift left, right +RUN(NAME test_unsigned_02 LABELS cpython llvm c) RUN(NAME test_bool_binop LABELS cpython llvm c) RUN(NAME test_issue_518 LABELS cpython llvm c NOFAST) RUN(NAME structs_01 LABELS cpython llvm c) diff --git a/integration_tests/test_unsigned_02.py b/integration_tests/test_unsigned_02.py new file mode 100644 index 0000000000..d880ff9193 --- /dev/null +++ b/integration_tests/test_unsigned_02.py @@ -0,0 +1,10 @@ +from lpython import u16, i32 + +# test issue 2170 + +i : i32 +u : u16 = u16(32768) +x : i32 + +for i in range(i32(u)): + x = i * 2 diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 109e76a348..6554da8ea3 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -2374,6 +2374,27 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } llvm_symtab[h] = ptr; + } else if (x.m_type->type == ASR::ttypeType::UnsignedInteger) { + int a_kind = down_cast(x.m_type)->m_kind; + llvm::Type *type; + int init_value_bits = 8*a_kind; + type = llvm_utils->getIntType(a_kind); + llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, + type); + if (!external) { + if (ASRUtils::is_array(x.m_type)) { + throw CodeGenError("Arrays are not supported by visit_Variable"); + } + if (init_value) { + module->getNamedGlobal(x.m_name)->setInitializer( + init_value); + } else { + module->getNamedGlobal(x.m_name)->setInitializer( + llvm::ConstantInt::get(context, + llvm::APInt(init_value_bits, 0))); + } + } + llvm_symtab[h] = ptr; } else if (x.m_type->type == ASR::ttypeType::Real) { int a_kind = down_cast(x.m_type)->m_kind; llvm::Type *type;