From 0738b5408f7eeae38657135e3859e2a0002a12de Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Mon, 17 Jul 2023 03:26:26 +0530 Subject: [PATCH 1/2] LLVM: Support global unsigned int variables --- src/libasr/codegen/asr_to_llvm.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 109e76a348..3f50e4537f 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -2353,8 +2353,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor this->visit_expr_wrapper(x.m_symbolic_value, true); init_value = llvm::dyn_cast(tmp); } - if (x.m_type->type == ASR::ttypeType::Integer) { - int a_kind = down_cast(x.m_type)->m_kind; + if (x.m_type->type == ASR::ttypeType::Integer + || x.m_type->type == ASR::ttypeType::UnsignedInteger) { + int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); llvm::Type *type; int init_value_bits = 8*a_kind; type = llvm_utils->getIntType(a_kind); From b4f1bb0bb6d7e8b8e0db13ba8d9e7339a4dbfab7 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Mon, 17 Jul 2023 03:26:59 +0530 Subject: [PATCH 2/2] TEST: Add test for global unsigned int variable --- integration_tests/CMakeLists.txt | 1 + integration_tests/expr_04u.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 integration_tests/expr_04u.py diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 510a40c437..5d9e17851d 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -428,6 +428,7 @@ RUN(NAME expr_20 LABELS cpython llvm c) RUN(NAME expr_01u LABELS cpython llvm c NOFAST) RUN(NAME expr_02u LABELS cpython llvm c NOFAST) RUN(NAME expr_03u LABELS cpython llvm c NOFAST) +RUN(NAME expr_04u LABELS cpython llvm c) RUN(NAME loop_01 LABELS cpython llvm c) RUN(NAME loop_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64) diff --git a/integration_tests/expr_04u.py b/integration_tests/expr_04u.py new file mode 100644 index 0000000000..5c4a22bb8d --- /dev/null +++ b/integration_tests/expr_04u.py @@ -0,0 +1,12 @@ +from lpython import u8, u16, u32, u64 + +FLAG1 : u8 = u8(1) << u8(4) +FLAG2 : u16 = u16(1) << u16(4) +FLAG3: u32 = u32(1) << u32(4) +FLAG4: u64 = u64(1) << u64(4) + +print(FLAG1, FLAG2, FLAG3, FLAG4) +assert FLAG1 == u8(16) +assert FLAG2 == u16(16) +assert FLAG3 == u32(16) +assert FLAG4 == u64(16)