mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ClangImporter] Add missing end-iterator check in Clang diag emission (#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
This commit is contained in:
@@ -165,8 +165,10 @@ SourceLoc ClangDiagnosticConsumer::resolveSourceLocation(
|
||||
const clang::SourceManager *toInsert) {
|
||||
return std::less<const clang::SourceManager *>()(inArray.get(), toInsert);
|
||||
});
|
||||
if (iter->get() != &clangSrcMgr)
|
||||
if (iter == sourceManagersWithDiagnostics.end() ||
|
||||
iter->get() != &clangSrcMgr) {
|
||||
sourceManagersWithDiagnostics.insert(iter, &clangSrcMgr);
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
4
test/ClangImporter/Inputs/custom-modules/Warnings1.h
Normal file
4
test/ClangImporter/Inputs/custom-modules/Warnings1.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern void old() __attribute__((deprecated));
|
||||
static void warnings1() {
|
||||
old();
|
||||
}
|
||||
4
test/ClangImporter/Inputs/custom-modules/Warnings2.h
Normal file
4
test/ClangImporter/Inputs/custom-modules/Warnings2.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern void old() __attribute__((deprecated));
|
||||
static void warnings2() {
|
||||
old();
|
||||
}
|
||||
4
test/ClangImporter/Inputs/custom-modules/Warnings3.h
Normal file
4
test/ClangImporter/Inputs/custom-modules/Warnings3.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern void old() __attribute__((deprecated));
|
||||
static void warnings3() {
|
||||
old();
|
||||
}
|
||||
4
test/ClangImporter/Inputs/custom-modules/Warnings4.h
Normal file
4
test/ClangImporter/Inputs/custom-modules/Warnings4.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern void old() __attribute__((deprecated));
|
||||
static void warnings4() {
|
||||
old();
|
||||
}
|
||||
4
test/ClangImporter/Inputs/custom-modules/Warnings5.h
Normal file
4
test/ClangImporter/Inputs/custom-modules/Warnings5.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern void old() __attribute__((deprecated));
|
||||
static void warnings5() {
|
||||
old();
|
||||
}
|
||||
4
test/ClangImporter/Inputs/custom-modules/Warnings6.h
Normal file
4
test/ClangImporter/Inputs/custom-modules/Warnings6.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern void old() __attribute__((deprecated));
|
||||
static void warnings6() {
|
||||
old();
|
||||
}
|
||||
4
test/ClangImporter/Inputs/custom-modules/Warnings7.h
Normal file
4
test/ClangImporter/Inputs/custom-modules/Warnings7.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern void old() __attribute__((deprecated));
|
||||
static void warnings7() {
|
||||
old();
|
||||
}
|
||||
4
test/ClangImporter/Inputs/custom-modules/Warnings8.h
Normal file
4
test/ClangImporter/Inputs/custom-modules/Warnings8.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern void old() __attribute__((deprecated));
|
||||
static void warnings8() {
|
||||
old();
|
||||
}
|
||||
4
test/ClangImporter/Inputs/custom-modules/Warnings9.h
Normal file
4
test/ClangImporter/Inputs/custom-modules/Warnings9.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern void old() __attribute__((deprecated));
|
||||
static void warnings9() {
|
||||
old();
|
||||
}
|
||||
@@ -189,3 +189,13 @@ module IndirectFields {
|
||||
module ObjCBridgeNonconforming {
|
||||
header "ObjCBridgeNonconforming.h"
|
||||
}
|
||||
|
||||
module Warnings1 { header "Warnings1.h" }
|
||||
module Warnings2 { header "Warnings2.h" }
|
||||
module Warnings3 { header "Warnings3.h" }
|
||||
module Warnings4 { header "Warnings4.h" }
|
||||
module Warnings5 { header "Warnings5.h" }
|
||||
module Warnings6 { header "Warnings6.h" }
|
||||
module Warnings7 { header "Warnings7.h" }
|
||||
module Warnings8 { header "Warnings8.h" }
|
||||
module Warnings9 { header "Warnings9.h" }
|
||||
|
||||
23
test/ClangImporter/diags-from-many-modules.swift
Normal file
23
test/ClangImporter/diags-from-many-modules.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules -module-cache-path %t 2> %t.err.txt
|
||||
// RUN: %FileCheck -input-file=%t.err.txt %s
|
||||
|
||||
import Warnings1
|
||||
import Warnings2
|
||||
import Warnings3
|
||||
import Warnings4
|
||||
import Warnings5
|
||||
import Warnings6
|
||||
import Warnings7
|
||||
import Warnings8
|
||||
import Warnings9
|
||||
|
||||
// CHECK: Warnings1.h:{{.+}}: warning: 'old' is deprecated
|
||||
// CHECK: Warnings2.h:{{.+}}: warning: 'old' is deprecated
|
||||
// CHECK: Warnings3.h:{{.+}}: warning: 'old' is deprecated
|
||||
// CHECK: Warnings4.h:{{.+}}: warning: 'old' is deprecated
|
||||
// CHECK: Warnings5.h:{{.+}}: warning: 'old' is deprecated
|
||||
// CHECK: Warnings6.h:{{.+}}: warning: 'old' is deprecated
|
||||
// CHECK: Warnings7.h:{{.+}}: warning: 'old' is deprecated
|
||||
// CHECK: Warnings8.h:{{.+}}: warning: 'old' is deprecated
|
||||
// CHECK: Warnings9.h:{{.+}}: warning: 'old' is deprecated
|
||||
Reference in New Issue
Block a user