Skip to content

Commit 065a58a

Browse files
fix array symbol duplication in interactive mode (#2734)
* fix array symbol duplication in interactive mode * add test * update according to code review
1 parent 98227da commit 065a58a

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,9 +2776,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
27762776
llvm::StructType* array_type = static_cast<llvm::StructType*>(
27772777
llvm_utils->get_type_from_ttype_t_util(x.m_type, module.get()));
27782778
llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, array_type);
2779-
module->getNamedGlobal(x.m_name)->setInitializer(
2780-
llvm::ConstantStruct::get(array_type,
2781-
llvm::Constant::getNullValue(array_type)));
2779+
if (!external) {
2780+
module->getNamedGlobal(x.m_name)->setInitializer(
2781+
llvm::ConstantStruct::get(array_type,
2782+
llvm::Constant::getNullValue(array_type)));
2783+
}
27822784
llvm_symtab[h] = ptr;
27832785
} else if (x.m_type->type == ASR::ttypeType::Logical) {
27842786
llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name,

src/lpython/tests/test_llvm.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,23 @@ def my_concat(x: str, y: str) -> str:
14501450
CHECK(std::strcmp(r.result.str, "Python REPL") == 0);
14511451
}
14521452

1453+
TEST_CASE("PythonCompiler Array 1") {
1454+
CompilerOptions cu;
1455+
cu.po.disable_main = true;
1456+
cu.emit_debug_line_column = false;
1457+
cu.generate_object_code = false;
1458+
cu.interactive = true;
1459+
cu.po.runtime_library_dir = LCompilers::LPython::get_runtime_library_dir();
1460+
PythonCompiler e(cu);
1461+
LCompilers::Result<PythonCompiler::EvalResult>
1462+
r = e.evaluate2("i: i32[10] = empty(10, dtype=int32)");
1463+
CHECK(r.ok);
1464+
CHECK(r.result.type == PythonCompiler::EvalResult::statement);
1465+
r = e.evaluate2("print(i)");
1466+
CHECK(r.ok);
1467+
CHECK(r.result.type == PythonCompiler::EvalResult::statement);
1468+
}
1469+
14531470
TEST_CASE("PythonCompiler asr verify 1") {
14541471
CompilerOptions cu;
14551472
cu.po.disable_main = true;

0 commit comments

Comments
 (0)