comparison gen/toobj.cpp @ 824:b972fec8a5f5

Fixed problem with moduleinfo thinking it imports itself, causing assertion failure, fixes #138
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Thu, 04 Dec 2008 14:36:11 +0100
parents 35de5ba7d36d
children ba390e5e9150
comparison
equal deleted inserted replaced
823:794c8af186ce 824:b972fec8a5f5
741 int aimports_dim = aimports.dim; 741 int aimports_dim = aimports.dim;
742 std::vector<LLConstant*> importInits; 742 std::vector<LLConstant*> importInits;
743 for (size_t i = 0; i < aimports.dim; i++) 743 for (size_t i = 0; i < aimports.dim; i++)
744 { 744 {
745 Module *m = (Module *)aimports.data[i]; 745 Module *m = (Module *)aimports.data[i];
746 if (!m->needModuleInfo()) 746 if (!m->needModuleInfo() || m == this)
747 continue; 747 continue;
748 748
749 // declare the imported module info 749 // declare the imported module info
750 std::string m_name("_D"); 750 std::string m_name("_D");
751 m_name.append(m->mangle()); 751 m_name.append(m->mangle());
865 // create name 865 // create name
866 std::string MIname("_D"); 866 std::string MIname("_D");
867 MIname.append(mangle()); 867 MIname.append(mangle());
868 MIname.append("8__ModuleZ"); 868 MIname.append("8__ModuleZ");
869 869
870 // declare 870 // declare global
871 // flags will be modified at runtime so can't make it constant 871 // flags will be modified at runtime so can't make it constant
872 872
873 llvm::GlobalVariable* gvar = gIR->module->getGlobalVariable(MIname); 873 // it makes no sense that the our own module info already exists!
874 if (!gvar) gvar = new llvm::GlobalVariable(constMI->getType(), false, llvm::GlobalValue::ExternalLinkage, NULL, MIname, gIR->module); 874 assert(!gIR->module->getGlobalVariable(MIname));
875 else assert(gvar->getType()->getContainedType(0) == constMI->getType()); 875 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(constMI->getType(), false, llvm::GlobalValue::ExternalLinkage, constMI, MIname, gIR->module);
876 gvar->setInitializer(constMI);
877 876
878 // build the modulereference and ctor for registering it 877 // build the modulereference and ctor for registering it
879 LLFunction* mictor = build_module_reference_and_ctor(gvar); 878 LLFunction* mictor = build_module_reference_and_ctor(gvar);
880 879
881 // register this ctor in the magic llvm.global_ctors appending array 880 // register this ctor in the magic llvm.global_ctors appending array