Skip to content

Commit 0431bb2

Browse files
committed
[IRGen] Don't emit coverage maps for synthesized Clang decls
We don't need to perform coverage mapping for any Clang decls we've synthesized, as they have no user-written code. This is also needed to avoid a Clang crash when attempting to emit coverage for decls without source locations (rdar://100172217). rdar://82820628
1 parent ff768b9 commit 0431bb2

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
138138
CGO.TrapFuncName = Opts.TrapFuncName;
139139
}
140140

141+
// We don't need to perform coverage mapping for any Clang decls we've
142+
// synthesized, as they have no user-written code. This is also needed to
143+
// avoid a Clang crash when attempting to emit coverage for decls without
144+
// source locations (rdar://100172217).
145+
CGO.CoverageMapping = false;
146+
141147
auto &VFS = Importer->getClangInstance().getVirtualFileSystem();
142148
auto &HSI = Importer->getClangPreprocessor()
143149
.getHeaderSearchInfo()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct cstruct {
2+
int member : 16;
3+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module CModule {
2+
header "cmodule.h"
3+
}

test/Profiler/issue-57483.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend -emit-ir -profile-generate -profile-coverage-mapping -Xcc -fprofile-instr-generate -Xcc -fcoverage-mapping -I %S/Inputs/issue-57483 %s | %FileCheck %s
2+
3+
// https://github.com/apple/swift/issues/57483 (rdar://82820628)
4+
// Make sure we don't crash in IRGen attempting to emit the coverage map for the
5+
// implicit Clang getter for the member bitfield.
6+
7+
// CHECK: define {{.*}} @"$So7cstructV$member$getter"
8+
9+
import CModule
10+
11+
func foo(_ x: UnsafePointer<cstruct>?) {
12+
_ = x?.pointee.member
13+
}
14+
foo(nil)

0 commit comments

Comments
 (0)