Skip to content

Commit 6132775

Browse files
committed
[Dependency Scanning][NFC] Associate single-shot scanner service lifetime with the owning compilation instance's ASTContext
Resolves rdar://131388478
1 parent 55d4a56 commit 6132775

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
@@ -1272,15 +1272,15 @@ bool swift::dependencies::scanDependencies(CompilerInstance &instance) {
12721272
std::string path = opts.InputsAndOutputs.getSingleOutputFilename();
12731273
// `-scan-dependencies` invocations use a single new instance
12741274
// of a module cache
1275-
SwiftDependencyScanningService service;
1275+
SwiftDependencyScanningService *service = Context.Allocate<SwiftDependencyScanningService>();
12761276
if (opts.ReuseDependencyScannerCache)
1277-
deserializeDependencyCache(instance, service);
1277+
deserializeDependencyCache(instance, *service);
12781278

1279-
if (service.setupCachingDependencyScanningService(instance))
1279+
if (service->setupCachingDependencyScanningService(instance))
12801280
return true;
12811281

12821282
ModuleDependenciesCache cache(
1283-
service, instance.getMainModule()->getNameStr().str(),
1283+
*service, instance.getMainModule()->getNameStr().str(),
12841284
instance.getInvocation().getFrontendOptions().ExplicitModulesOutputPath,
12851285
instance.getInvocation().getModuleScanningHash());
12861286

@@ -1291,7 +1291,7 @@ bool swift::dependencies::scanDependencies(CompilerInstance &instance) {
12911291
// Serialize the dependency cache if -serialize-dependency-scan-cache
12921292
// is specified
12931293
if (opts.SerializeDependencyScannerCache)
1294-
serializeDependencyCache(instance, service);
1294+
serializeDependencyCache(instance, *service);
12951295

12961296
if (dependenciesOrErr.getError())
12971297
return true;
@@ -1315,9 +1315,9 @@ bool swift::dependencies::prescanDependencies(CompilerInstance &instance) {
13151315
std::string path = opts.InputsAndOutputs.getSingleOutputFilename();
13161316
// `-scan-dependencies` invocations use a single new instance
13171317
// of a module cache
1318-
SwiftDependencyScanningService singleUseService;
1318+
SwiftDependencyScanningService *singleUseService = Context.Allocate<SwiftDependencyScanningService>();
13191319
ModuleDependenciesCache cache(
1320-
singleUseService, instance.getMainModule()->getNameStr().str(),
1320+
*singleUseService, instance.getMainModule()->getNameStr().str(),
13211321
instance.getInvocation().getFrontendOptions().ExplicitModulesOutputPath,
13221322
instance.getInvocation().getModuleScanningHash());
13231323

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)