diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index d50173195d07e..f79cec8c594e2 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -1105,8 +1105,11 @@ void IRGenerator::emitGlobalTopLevel(llvm::StringSet<> *linkerDirectives) { IGM->emitSILDifferentiabilityWitness(&dw); } - // Emit code coverage mapping data. - PrimaryIGM->emitCoverageMapping(); + // Emit code coverage mapping data for all modules + for (auto Iter : *this) { + IRGenModule *IGM = Iter.second; + IGM->emitCoverageMapping(); + } for (auto Iter : *this) { IRGenModule *IGM = Iter.second; diff --git a/test/Profiler/Inputs/coverage_num_threads1.swift b/test/Profiler/Inputs/coverage_num_threads1.swift new file mode 100644 index 0000000000000..6ca641732e7e1 --- /dev/null +++ b/test/Profiler/Inputs/coverage_num_threads1.swift @@ -0,0 +1 @@ +func func1() {} diff --git a/test/Profiler/Inputs/coverage_num_threads2.swift b/test/Profiler/Inputs/coverage_num_threads2.swift new file mode 100644 index 0000000000000..639ea1b4ad4b7 --- /dev/null +++ b/test/Profiler/Inputs/coverage_num_threads2.swift @@ -0,0 +1 @@ +func func2() {} diff --git a/test/Profiler/coverage_num_threads.swift b/test/Profiler/coverage_num_threads.swift new file mode 100644 index 0000000000000..12156483c079e --- /dev/null +++ b/test/Profiler/coverage_num_threads.swift @@ -0,0 +1,13 @@ +// RUN: %target-swift-frontend -profile-generate -profile-coverage-mapping -num-threads 0 -emit-ir %S/Inputs/coverage_num_threads1.swift | %FileCheck %s -check-prefix=SINGLE-SOURCE --implicit-check-not="llvm_coverage_mapping =" + +// SINGLE-SOURCE: llvm_coverage_mapping = + +// RUN: %target-swift-frontend -profile-generate -profile-coverage-mapping -num-threads 0 -emit-ir %S/Inputs/coverage_num_threads1.swift %S/Inputs/coverage_num_threads2.swift | %FileCheck %s -check-prefix=SINGLE-OBJECT --implicit-check-not="llvm_coverage_mapping =" + +// SINGLE-OBJECT: llvm_coverage_mapping = + +// Using 1 goes down the multithreaded codepath but only operates with a single thread to work around an issue on Windows where the output of both IR modules is interleaved and therefore the output is invalid +// RUN: %target-swift-frontend -profile-generate -profile-coverage-mapping -num-threads 1 -emit-ir %S/Inputs/coverage_num_threads1.swift %S/Inputs/coverage_num_threads2.swift | %FileCheck %s -check-prefix=MULTIPLE-OBJECTS --implicit-check-not="llvm_coverage_mapping =" + +// MULTIPLE-OBJECTS: llvm_coverage_mapping = +// MULTIPLE-OBJECTS: llvm_coverage_mapping =