Skip to content

Commit fe98a0d

Browse files
committed
[IRGen] Run instrprof lowering before all other module passes
This matches clang's behavior. It also makes it possible to, e.g compile with ASan *and* Code Coverage enabled. Fixes rdar://problem/26850611.
1 parent fe13e6c commit fe98a0d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ void swift::performLLVMOptimizations(IRGenOptions &Opts, llvm::Module *Module,
229229
legacy::PassManager ModulePasses;
230230
ModulePasses.add(createTargetTransformInfoWrapperPass(
231231
TargetMachine->getTargetIRAnalysis()));
232+
233+
// If we're generating a profile, add the lowering pass now.
234+
if (Opts.GenerateProfile)
235+
ModulePasses.add(createInstrProfilingPass());
236+
232237
PMBuilder.populateModulePassManager(ModulePasses);
233238

234239
// The PMBuilder only knows about LLVM AA passes. We should explicitly add
@@ -242,10 +247,6 @@ void swift::performLLVMOptimizations(IRGenOptions &Opts, llvm::Module *Module,
242247
}));
243248
}
244249

245-
// If we're generating a profile, add the lowering pass now.
246-
if (Opts.GenerateProfile)
247-
ModulePasses.add(createInstrProfilingPass());
248-
249250
if (Opts.Verify)
250251
ModulePasses.add(createVerifierPass());
251252

test/IRGen/coverage_with_asan.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-swift-frontend %s -profile-generate -profile-coverage-mapping -sanitize=address -emit-ir -o - | FileCheck %s
2+
3+
// CHECK: main
4+
func main() {}

0 commit comments

Comments
 (0)