30
30
#include " swift/AST/IRGenOptions.h"
31
31
#include " swift/Basic/Assertions.h"
32
32
#include " swift/IRGen/GenericRequirement.h"
33
+ #include " swift/IRGen/Linking.h"
33
34
#include " swift/SIL/SILModule.h"
34
35
35
36
using namespace swift ;
@@ -489,6 +490,22 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction(
489
490
paramTys.push_back (ptrTy);
490
491
collector.addPolymorphicParameterTypes (paramTys);
491
492
493
+ IRLinkage *linkage = nullptr ;
494
+ IRLinkage privateLinkage = {
495
+ llvm::GlobalValue::PrivateLinkage,
496
+ llvm::GlobalValue::DefaultVisibility,
497
+ llvm::GlobalValue::DefaultStorageClass,
498
+ };
499
+ auto &TL =
500
+ getSILModule ().Types .getTypeLowering (T, TypeExpansionContext::minimal ());
501
+ // Opaque result types might lead to different expansions in different files.
502
+ // The default hidden linkonce_odr might lead to linking an implementation
503
+ // from another file that head a different expansion/different
504
+ // signature/different implementation.
505
+ if (TL.getRecursiveProperties ().isTypeExpansionSensitive ()) {
506
+ linkage = &privateLinkage;
507
+ }
508
+
492
509
return getOrCreateHelperFunction (funcName, ptrTy, paramTys,
493
510
[&](IRGenFunction &IGF) {
494
511
auto params = IGF.collectParameters ();
@@ -500,7 +517,8 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction(
500
517
},
501
518
true /* setIsNoInline*/ ,
502
519
false /* forPrologue*/ ,
503
- collector.IGF .isPerformanceConstraint );
520
+ collector.IGF .isPerformanceConstraint ,
521
+ linkage);
504
522
}
505
523
506
524
void TypeInfo::callOutlinedDestroy (IRGenFunction &IGF,
@@ -544,6 +562,22 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedDestroyFunction(
544
562
auto funcName = mangler.mangleOutlinedDestroyFunction (manglingBits.first ,
545
563
manglingBits.second , collector.IGF .isPerformanceConstraint );
546
564
565
+ IRLinkage *linkage = nullptr ;
566
+ IRLinkage privateLinkage = {
567
+ llvm::GlobalValue::PrivateLinkage,
568
+ llvm::GlobalValue::DefaultVisibility,
569
+ llvm::GlobalValue::DefaultStorageClass,
570
+ };
571
+ auto &TL =
572
+ getSILModule ().Types .getTypeLowering (T, TypeExpansionContext::minimal ());
573
+ // Opaque result types might lead to different expansions in different files.
574
+ // The default hidden linkonce_odr might lead to linking an implementation
575
+ // from another file that head a different expansion/different
576
+ // signature/different implementation.
577
+ if (TL.getRecursiveProperties ().isTypeExpansionSensitive ()) {
578
+ linkage = &privateLinkage;
579
+ }
580
+
547
581
auto ptrTy = ti.getStorageType ()->getPointerTo ();
548
582
llvm::SmallVector<llvm::Type *, 4 > paramTys;
549
583
paramTys.push_back (ptrTy);
@@ -565,7 +599,8 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedDestroyFunction(
565
599
},
566
600
true /* setIsNoInline*/ ,
567
601
false /* forPrologue*/ ,
568
- collector.IGF .isPerformanceConstraint );
602
+ collector.IGF .isPerformanceConstraint ,
603
+ linkage);
569
604
}
570
605
571
606
llvm::Constant *IRGenModule::getOrCreateRetainFunction (const TypeInfo &ti,
0 commit comments