diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 6d5844734c..832d58f63f 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -2806,33 +2806,41 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::StructType* list_type = static_cast( llvm_utils->get_type_from_ttype_t_util(x.m_type, module.get())); llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, list_type); - module->getNamedGlobal(x.m_name)->setInitializer( - llvm::ConstantStruct::get(list_type, - llvm::Constant::getNullValue(list_type))); + if (!external) { + module->getNamedGlobal(x.m_name)->setInitializer( + llvm::ConstantStruct::get(list_type, + llvm::Constant::getNullValue(list_type))); + } llvm_symtab[h] = ptr; } else if (x.m_type->type == ASR::ttypeType::Tuple) { llvm::StructType* tuple_type = static_cast( llvm_utils->get_type_from_ttype_t_util(x.m_type, module.get())); llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, tuple_type); - module->getNamedGlobal(x.m_name)->setInitializer( - llvm::ConstantStruct::get(tuple_type, - llvm::Constant::getNullValue(tuple_type))); + if (!external) { + module->getNamedGlobal(x.m_name)->setInitializer( + llvm::ConstantStruct::get(tuple_type, + llvm::Constant::getNullValue(tuple_type))); + } llvm_symtab[h] = ptr; } else if(x.m_type->type == ASR::ttypeType::Dict) { llvm::StructType* dict_type = static_cast( llvm_utils->get_type_from_ttype_t_util(x.m_type, module.get())); llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, dict_type); - module->getNamedGlobal(x.m_name)->setInitializer( - llvm::ConstantStruct::get(dict_type, - llvm::Constant::getNullValue(dict_type))); + if (!external) { + module->getNamedGlobal(x.m_name)->setInitializer( + llvm::ConstantStruct::get(dict_type, + llvm::Constant::getNullValue(dict_type))); + } llvm_symtab[h] = ptr; } else if(x.m_type->type == ASR::ttypeType::Set) { llvm::StructType* set_type = static_cast( llvm_utils->get_type_from_ttype_t_util(x.m_type, module.get())); llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, set_type); - module->getNamedGlobal(x.m_name)->setInitializer( - llvm::ConstantStruct::get(set_type, - llvm::Constant::getNullValue(set_type))); + if (!external) { + module->getNamedGlobal(x.m_name)->setInitializer( + llvm::ConstantStruct::get(set_type, + llvm::Constant::getNullValue(set_type))); + } llvm_symtab[h] = ptr; } else if (x.m_type->type == ASR::ttypeType::TypeParameter) { // Ignore type variables