Skip to content

Commit ea9715b

Browse files
authoredJul 17, 2023
Merge pull request #2171 from Smit-create/i-2170
LLVM: Support Unsigned Int in visit_Variable
2 parents 71d654a + 244d711 commit ea9715b

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
 

Diff for: ‎integration_tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ RUN(NAME test_unary_op_04 LABELS cpython llvm c) # unary bitinvert
573573
RUN(NAME test_unary_op_05 LABELS cpython llvm c) # unsigned unary minus, plus
574574
RUN(NAME test_unary_op_06 LABELS cpython llvm c) # unsigned unary bitnot
575575
RUN(NAME test_unsigned_01 LABELS cpython llvm c) # unsigned bitshift left, right
576+
RUN(NAME test_unsigned_02 LABELS cpython llvm c)
576577
RUN(NAME test_bool_binop LABELS cpython llvm c)
577578
RUN(NAME test_issue_518 LABELS cpython llvm c NOFAST)
578579
RUN(NAME structs_01 LABELS cpython llvm c)

Diff for: ‎integration_tests/test_unsigned_02.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from lpython import u16, i32
2+
3+
# test issue 2170
4+
5+
i : i32
6+
u : u16 = u16(32768)
7+
x : i32
8+
9+
for i in range(i32(u)):
10+
x = i * 2

Diff for: ‎src/libasr/codegen/asr_to_llvm.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,27 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
23752375
}
23762376
}
23772377
llvm_symtab[h] = ptr;
2378+
} else if (x.m_type->type == ASR::ttypeType::UnsignedInteger) {
2379+
int a_kind = down_cast<ASR::UnsignedInteger_t>(x.m_type)->m_kind;
2380+
llvm::Type *type;
2381+
int init_value_bits = 8*a_kind;
2382+
type = llvm_utils->getIntType(a_kind);
2383+
llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name,
2384+
type);
2385+
if (!external) {
2386+
if (ASRUtils::is_array(x.m_type)) {
2387+
throw CodeGenError("Arrays are not supported by visit_Variable");
2388+
}
2389+
if (init_value) {
2390+
module->getNamedGlobal(x.m_name)->setInitializer(
2391+
init_value);
2392+
} else {
2393+
module->getNamedGlobal(x.m_name)->setInitializer(
2394+
llvm::ConstantInt::get(context,
2395+
llvm::APInt(init_value_bits, 0)));
2396+
}
2397+
}
2398+
llvm_symtab[h] = ptr;
23782399
} else if (x.m_type->type == ASR::ttypeType::Real) {
23792400
int a_kind = down_cast<ASR::Real_t>(x.m_type)->m_kind;
23802401
llvm::Type *type;

0 commit comments

Comments
 (0)
Please sign in to comment.