Skip to content

Commit bbc7b04

Browse files
committed
Use default value in LLVM and enable tests
1 parent ce5248a commit bbc7b04

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ RUN(NAME test_dict_07 LABELS cpython llvm)
295295
RUN(NAME test_dict_08 LABELS cpython llvm c)
296296
RUN(NAME test_dict_09 LABELS cpython llvm c)
297297
RUN(NAME test_dict_10 LABELS cpython llvm) # TODO: Add support of dict with string in C backend
298-
RUN(NAME test_dict_11 LABELS cpython c) # TODO: Add LLVM support
298+
RUN(NAME test_dict_11 LABELS cpython llvm c)
299299
RUN(NAME test_for_loop LABELS cpython llvm c)
300300
RUN(NAME modules_01 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
301301
RUN(NAME modules_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,9 +1793,18 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
17931793
this->visit_expr_wrapper(x.m_key, true);
17941794
ptr_loads = ptr_loads_copy;
17951795
llvm::Value *key = tmp;
1796+
llvm::Type *val_type = get_type_from_ttype_t_util(dict_type->m_value_type);
1797+
llvm::Value *def_value_ptr = nullptr;
1798+
if (x.m_default) {
1799+
def_value_ptr = builder->CreateAlloca(val_type, nullptr);
1800+
ptr_loads = !LLVM::is_llvm_struct(dict_type->m_value_type);
1801+
this->visit_expr_wrapper(x.m_default, true);
1802+
ptr_loads = ptr_loads_copy;
1803+
builder->CreateStore(tmp, def_value_ptr);
1804+
}
17961805

17971806
set_dict_api(dict_type);
1798-
tmp = llvm_utils->dict_api->read_item(pdict, key, *module, dict_type,
1807+
tmp = llvm_utils->dict_api->read_item(pdict, key, *module, dict_type, def_value_ptr,
17991808
LLVM::is_llvm_struct(dict_type->m_value_type));
18001809
}
18011810

0 commit comments

Comments
 (0)