Skip to content

Commit 77385b9

Browse files
authored
Merge pull request #2046 from Smit-create/i-2041
LLVM: Support global tuple initialization
2 parents dc3510b + 708c262 commit 77385b9

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ RUN(NAME test_list_pop2 LABELS cpython llvm NOFAST) # TODO: Remove NOFAST
457457
RUN(NAME test_tuple_01 LABELS cpython llvm c)
458458
RUN(NAME test_tuple_02 LABELS cpython llvm c NOFAST)
459459
RUN(NAME test_tuple_03 LABELS cpython llvm c)
460+
RUN(NAME test_tuple_04 LABELS cpython llvm c)
460461
RUN(NAME test_tuple_concat LABELS cpython llvm)
461462
RUN(NAME test_tuple_nested LABELS cpython llvm)
462463
RUN(NAME test_dict_01 LABELS cpython llvm c)

integration_tests/test_tuple_04.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from lpython import i32
2+
3+
# issue 2041
4+
ttype : tuple[list[i32], str] = ([-1], 'dimensions')
5+
contents : tuple[list[i32], str] = ([1, 2], '')
6+
7+
assert ttype[0] == [-1]
8+
assert len(ttype[0]) == 1
9+
assert contents[0] == [1, 2]
10+
assert len(contents[1]) == 0
11+
assert ttype[1] == 'dimensions'

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
27822782
llvm::ConstantStruct::get(list_type,
27832783
llvm::Constant::getNullValue(list_type)));
27842784
llvm_symtab[h] = ptr;
2785+
} else if (x.m_type->type == ASR::ttypeType::Tuple) {
2786+
llvm::StructType* tuple_type = static_cast<llvm::StructType*>(
2787+
get_type_from_ttype_t_util(x.m_type));
2788+
llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, tuple_type);
2789+
module->getNamedGlobal(x.m_name)->setInitializer(
2790+
llvm::ConstantStruct::get(tuple_type,
2791+
llvm::Constant::getNullValue(tuple_type)));
2792+
llvm_symtab[h] = ptr;
27852793
} else if(x.m_type->type == ASR::ttypeType::Dict) {
27862794
llvm::StructType* dict_type = static_cast<llvm::StructType*>(
27872795
get_type_from_ttype_t_util(x.m_type));

0 commit comments

Comments
 (0)