Skip to content

Commit dd2ebac

Browse files
authored
[ClangImporter] Add missing end-iterator check in Clang diag emission (swiftlang#15006)
This caused non-deterministic crashes when a high number of modules containing diagnostics were compiled for the first time. The 9-entry test case results in a crash on 64-bit macOS when run under Guard Malloc without this change. rdar://problem/33515925
1 parent d8104e7 commit dd2ebac

File tree

12 files changed

+72
-1
lines changed

12 files changed

+72
-1
lines changed

lib/ClangImporter/ClangDiagnosticConsumer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ SourceLoc ClangDiagnosticConsumer::resolveSourceLocation(
165165
const clang::SourceManager *toInsert) {
166166
return std::less<const clang::SourceManager *>()(inArray.get(), toInsert);
167167
});
168-
if (iter->get() != &clangSrcMgr)
168+
if (iter == sourceManagersWithDiagnostics.end() ||
169+
iter->get() != &clangSrcMgr) {
169170
sourceManagersWithDiagnostics.insert(iter, &clangSrcMgr);
171+
}
170172

171173
return loc;
172174
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern void old() __attribute__((deprecated));
2+
static void warnings1() {
3+
old();
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern void old() __attribute__((deprecated));
2+
static void warnings2() {
3+
old();
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern void old() __attribute__((deprecated));
2+
static void warnings3() {
3+
old();
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern void old() __attribute__((deprecated));
2+
static void warnings4() {
3+
old();
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern void old() __attribute__((deprecated));
2+
static void warnings5() {
3+
old();
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern void old() __attribute__((deprecated));
2+
static void warnings6() {
3+
old();
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern void old() __attribute__((deprecated));
2+
static void warnings7() {
3+
old();
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern void old() __attribute__((deprecated));
2+
static void warnings8() {
3+
old();
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extern void old() __attribute__((deprecated));
2+
static void warnings9() {
3+
old();
4+
}

0 commit comments

Comments
 (0)