comparison gen/tollvm.cpp @ 1214:7e5547d8e59f

Give all symbols nested in functions internal linkage, unless it's one of the other special cases. (for example: this shouldn't be done if the symbol in question is also nested in a template; such symbols should get template-like linkage)
author Frits van Bommel <fvbommel wxs.nl>
date Mon, 13 Apr 2009 16:16:03 +0200
parents 3d4581761b4c
children 7977096f0e49 79758fd2f48a
comparison
equal deleted inserted replaced
1213:9430d4959ab4 1214:7e5547d8e59f
270 if (VarDeclaration* vd = sym->isVarDeclaration()) 270 if (VarDeclaration* vd = sym->isVarDeclaration())
271 { 271 {
272 // template 272 // template
273 if (needsTemplateLinkage(sym)) 273 if (needsTemplateLinkage(sym))
274 return TEMPLATE_LINKAGE_TYPE; 274 return TEMPLATE_LINKAGE_TYPE;
275 // local static
276 else if (sym->parent && sym->parent->isFuncDeclaration())
277 return llvm::GlobalValue::InternalLinkage;
278 } 275 }
279 // function 276 // function
280 else if (FuncDeclaration* fdecl = sym->isFuncDeclaration()) 277 else if (FuncDeclaration* fdecl = sym->isFuncDeclaration())
281 { 278 {
282 assert(fdecl->type->ty == Tfunction); 279 assert(fdecl->type->ty == Tfunction);
309 } 306 }
310 else 307 else
311 { 308 {
312 assert(0 && "not global/function"); 309 assert(0 && "not global/function");
313 } 310 }
314 311
312 // Any symbol nested in a function can't be referenced directly from
313 // outside that function, so we can give such symbols internal linkage.
314 // This holds even if nested indirectly, such as member functions of
315 // aggregates nested in functions.
316 //
317 // Note: This must be checked after things like template member-ness or
318 // symbols nested in templates would get duplicated for each module,
319 // breaking things like
320 // ---
321 // int counter(T)() { static int i; return i++; }"
322 // ---
323 // if instances get emitted in multiple object files because they'd use
324 // different instances of 'i'.
325 for (Dsymbol* parent = sym->parent; parent ; parent = parent->parent) {
326 if (parent->isFuncDeclaration())
327 return llvm::GlobalValue::InternalLinkage;
328 }
329
315 // default to external linkage 330 // default to external linkage
316 return llvm::GlobalValue::ExternalLinkage; 331 return llvm::GlobalValue::ExternalLinkage;
317 } 332 }
318 333
319 llvm::GlobalValue::LinkageTypes DtoInternalLinkage(Dsymbol* sym) 334 llvm::GlobalValue::LinkageTypes DtoInternalLinkage(Dsymbol* sym)