Skip to content

Commit ad5e72f

Browse files
committed
[IRGen] Fetch the correct IGM for synthesized files
rdar://128870792 Synthesized files are treated as not having a parent source file, but that can cause issues for macro code. The declarations will have the source file of their use site declared as parent source file, which means they should be emitted into the same IGM. If we don't use the correct IGM, we can get inconsistencies when referencing the generated code, which will cause linking issues.
1 parent 11696cd commit ad5e72f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,8 @@ void swift::irgen::disableAddressSanitizer(IRGenModule &IGM, llvm::GlobalVariabl
25632563

25642564
/// Emit a global declaration.
25652565
void IRGenModule::emitGlobalDecl(Decl *D) {
2566+
assert(this == irgen.getGenModule(D) &&
2567+
"Current module does not match module of decl");
25662568
if (!D->isAvailableDuringLowering())
25672569
return;
25682570

lib/IRGen/IRGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ static void performParallelIRGeneration(IRGenDescriptor desc) {
14401440
}
14411441

14421442
if (auto *synthSFU = File->getSynthesizedFile()) {
1443-
CurrentIGMPtr IGM = irgen.getGenModule(synthSFU);
1443+
CurrentIGMPtr IGM = irgen.getGenModule(&synthSFU->getFileUnit());
14441444
IGM->emitSynthesizedFileUnit(*synthSFU);
14451445
}
14461446
} else {

0 commit comments

Comments
 (0)