comparison gen/functions.cpp @ 149:4c577c2b7229 trunk

[svn r155] Fixed a bunch of linkage problems (especially with templates)
author lindquist
date Mon, 24 Mar 2008 19:43:02 +0100
parents a27941d00351
children 2c447715c047
comparison
equal deleted inserted replaced
148:86d3bb8ca33e 149:4c577c2b7229
351 351
352 // construct function 352 // construct function
353 const llvm::FunctionType* functype = DtoFunctionType(fdecl); 353 const llvm::FunctionType* functype = DtoFunctionType(fdecl);
354 llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name); 354 llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name);
355 if (!func) 355 if (!func)
356 func = new llvm::Function(functype, DtoLinkage(fdecl->protection, fdecl->storage_class), mangled_name, gIR->module); 356 func = new llvm::Function(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
357 else 357 else
358 assert(func->getFunctionType() == functype); 358 assert(func->getFunctionType() == functype);
359 359
360 // add func to IRFunc 360 // add func to IRFunc
361 fdecl->irFunc->func = func; 361 fdecl->irFunc->func = func;
362 362
363 // calling convention 363 // calling convention
364 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic) 364 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic)
365 func->setCallingConv(DtoCallingConv(f->linkage)); 365 func->setCallingConv(DtoCallingConv(f->linkage));
366 366 else // fall back to C, it should be the right thing to do
367 // template instances should have weak linkage
368 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic && fdecl->parent && DtoIsTemplateInstance(fdecl->parent))
369 func->setLinkage(llvm::GlobalValue::WeakLinkage);
370
371 // extern(C) functions are always external
372 if (f->linkage == LINKc)
373 func->setLinkage(llvm::GlobalValue::ExternalLinkage);
374
375 // intrinsics are always external C
376 if (fdecl->llvmInternal == LLVMintrinsic)
377 {
378 func->setLinkage(llvm::GlobalValue::ExternalLinkage);
379 func->setCallingConv(llvm::CallingConv::C); 367 func->setCallingConv(llvm::CallingConv::C);
380 }
381 368
382 fdecl->irFunc->func = func; 369 fdecl->irFunc->func = func;
383 assert(llvm::isa<llvm::FunctionType>(f->llvmType->get())); 370 assert(llvm::isa<llvm::FunctionType>(f->llvmType->get()));
384 371
385 // main 372 // main