Skip to content

Commit 71d654a

Browse files
authored
Merge pull request #2164 from Shaikh-Ubaid/llvm_global_unsigned_ints
LLVM: Support global unsigned integer variable
2 parents f8f58d0 + b4f1bb0 commit 71d654a

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

integration_tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ RUN(NAME expr_20 LABELS cpython llvm c)
428428
RUN(NAME expr_01u LABELS cpython llvm c NOFAST)
429429
RUN(NAME expr_02u LABELS cpython llvm c NOFAST)
430430
RUN(NAME expr_03u LABELS cpython llvm c NOFAST)
431+
RUN(NAME expr_04u LABELS cpython llvm c)
431432

432433
RUN(NAME loop_01 LABELS cpython llvm c)
433434
RUN(NAME loop_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)

integration_tests/expr_04u.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from lpython import u8, u16, u32, u64
2+
3+
FLAG1 : u8 = u8(1) << u8(4)
4+
FLAG2 : u16 = u16(1) << u16(4)
5+
FLAG3: u32 = u32(1) << u32(4)
6+
FLAG4: u64 = u64(1) << u64(4)
7+
8+
print(FLAG1, FLAG2, FLAG3, FLAG4)
9+
assert FLAG1 == u8(16)
10+
assert FLAG2 == u16(16)
11+
assert FLAG3 == u32(16)
12+
assert FLAG4 == u64(16)

src/libasr/codegen/asr_to_llvm.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -2353,8 +2353,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
23532353
this->visit_expr_wrapper(x.m_symbolic_value, true);
23542354
init_value = llvm::dyn_cast<llvm::Constant>(tmp);
23552355
}
2356-
if (x.m_type->type == ASR::ttypeType::Integer) {
2357-
int a_kind = down_cast<ASR::Integer_t>(x.m_type)->m_kind;
2356+
if (x.m_type->type == ASR::ttypeType::Integer
2357+
|| x.m_type->type == ASR::ttypeType::UnsignedInteger) {
2358+
int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type);
23582359
llvm::Type *type;
23592360
int init_value_bits = 8*a_kind;
23602361
type = llvm_utils->getIntType(a_kind);

0 commit comments

Comments
 (0)