Skip to content

Commit a55beaa

Browse files
authored
Merge pull request swiftlang#75139 from artemcm/FixScanSourceLocUseAfterFree
[Dependency Scanning][NFC] Associate single-shot scanner service lifetime with the owning compilation instance's `ASTContext`
2 parents 0d25417 + 6132775 commit a55beaa

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,15 +1216,15 @@ bool swift::dependencies::scanDependencies(CompilerInstance &instance) {
12161216
std::string path = opts.InputsAndOutputs.getSingleOutputFilename();
12171217
// `-scan-dependencies` invocations use a single new instance
12181218
// of a module cache
1219-
SwiftDependencyScanningService service;
1219+
SwiftDependencyScanningService *service = Context.Allocate<SwiftDependencyScanningService>();
12201220
if (opts.ReuseDependencyScannerCache)
1221-
deserializeDependencyCache(instance, service);
1221+
deserializeDependencyCache(instance, *service);
12221222

1223-
if (service.setupCachingDependencyScanningService(instance))
1223+
if (service->setupCachingDependencyScanningService(instance))
12241224
return true;
12251225

12261226
ModuleDependenciesCache cache(
1227-
service, instance.getMainModule()->getNameStr().str(),
1227+
*service, instance.getMainModule()->getNameStr().str(),
12281228
instance.getInvocation().getFrontendOptions().ExplicitModulesOutputPath,
12291229
instance.getInvocation().getModuleScanningHash());
12301230

@@ -1235,7 +1235,7 @@ bool swift::dependencies::scanDependencies(CompilerInstance &instance) {
12351235
// Serialize the dependency cache if -serialize-dependency-scan-cache
12361236
// is specified
12371237
if (opts.SerializeDependencyScannerCache)
1238-
serializeDependencyCache(instance, service);
1238+
serializeDependencyCache(instance, *service);
12391239

12401240
if (dependenciesOrErr.getError())
12411241
return true;
@@ -1259,9 +1259,9 @@ bool swift::dependencies::prescanDependencies(CompilerInstance &instance) {
12591259
std::string path = opts.InputsAndOutputs.getSingleOutputFilename();
12601260
// `-scan-dependencies` invocations use a single new instance
12611261
// of a module cache
1262-
SwiftDependencyScanningService singleUseService;
1262+
SwiftDependencyScanningService *singleUseService = Context.Allocate<SwiftDependencyScanningService>();
12631263
ModuleDependenciesCache cache(
1264-
singleUseService, instance.getMainModule()->getNameStr().str(),
1264+
*singleUseService, instance.getMainModule()->getNameStr().str(),
12651265
instance.getInvocation().getFrontendOptions().ExplicitModulesOutputPath,
12661266
instance.getInvocation().getModuleScanningHash());
12671267

test/ScanDependencies/error_path.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
// REQUIRES: objc_interop
44
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 2>&1 | %FileCheck %s
55

6-
// There is a use-after-free in ScanDependencies rdar://131388478
7-
// XFAIL: asan
8-
96
import P
107

118
// CHECK: {{.*}}{{/|\\}}Z.swiftinterface:3:8: error: Unable to find module dependency: 'missing_module'

test/ScanDependencies/error_source_locations.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import P
77
import FooBar
88

99

10-
// There is a use-after-free in ScanDependencies rdar://131388478
11-
// XFAIL: asan
12-
1310
// CHECK: {{.*}}{{/|\\}}error_source_locations.swift:7:8: error: Unable to find module dependency: 'FooBar'
1411
// CHECK-NEXT: 5 |
1512
// CHECK-NEXT: 6 | import P

0 commit comments

Comments
 (0)