Skip to content

Commit

Permalink
fix array symbol duplication in interactive mode (#2734)
Browse files Browse the repository at this point in the history
* fix array symbol duplication in interactive mode

* add test

* update according to code review
  • Loading branch information
Vipul-Cariappa authored Jul 3, 2024
1 parent 98227da commit 065a58a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2776,9 +2776,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
llvm::StructType* array_type = static_cast<llvm::StructType*>(
llvm_utils->get_type_from_ttype_t_util(x.m_type, module.get()));
llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, array_type);
module->getNamedGlobal(x.m_name)->setInitializer(
llvm::ConstantStruct::get(array_type,
llvm::Constant::getNullValue(array_type)));
if (!external) {
module->getNamedGlobal(x.m_name)->setInitializer(
llvm::ConstantStruct::get(array_type,
llvm::Constant::getNullValue(array_type)));
}
llvm_symtab[h] = ptr;
} else if (x.m_type->type == ASR::ttypeType::Logical) {
llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name,
Expand Down
17 changes: 17 additions & 0 deletions src/lpython/tests/test_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,23 @@ def my_concat(x: str, y: str) -> str:
CHECK(std::strcmp(r.result.str, "Python REPL") == 0);
}

TEST_CASE("PythonCompiler Array 1") {
CompilerOptions cu;
cu.po.disable_main = true;
cu.emit_debug_line_column = false;
cu.generate_object_code = false;
cu.interactive = true;
cu.po.runtime_library_dir = LCompilers::LPython::get_runtime_library_dir();
PythonCompiler e(cu);
LCompilers::Result<PythonCompiler::EvalResult>
r = e.evaluate2("i: i32[10] = empty(10, dtype=int32)");
CHECK(r.ok);
CHECK(r.result.type == PythonCompiler::EvalResult::statement);
r = e.evaluate2("print(i)");
CHECK(r.ok);
CHECK(r.result.type == PythonCompiler::EvalResult::statement);
}

TEST_CASE("PythonCompiler asr verify 1") {
CompilerOptions cu;
cu.po.disable_main = true;
Expand Down

0 comments on commit 065a58a

Please sign in to comment.