Skip to content

Commit

Permalink
[SR-2660] Do not generate modules for -g
Browse files Browse the repository at this point in the history
The following two invocations of `swiftc` behave differently, despite
their only difference being the `-g` option:

```
swiftc foo.swift bar.o baz.swiftmodule -o foo
swiftc -g foo.swift bar.o baz.swiftmodule -o foo
```

The first invocation compiles `foo.swift`, links it with `bar.o`, and
passes the AST information from `baz.swiftmodule` to the linker. The
second invocation results in the following error:

```
<unknown>:0: error: cannot load module 'baz' as 'foo'
```

The source of the problem is that the driver determines whether to
perform a merge-module action based on the level of debug info
requested. Remove this logic so that merge-module actions are only
performed when explicitly requested or when otherwise necessary (such
as when an Objective-C header is requested to be emitted).
  • Loading branch information
modocache committed Oct 22, 2017
1 parent f2e8e0a commit e4a7bb1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 45 deletions.
4 changes: 1 addition & 3 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,9 +1202,7 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
// top-level output.
OI.ShouldGenerateModule = true;
OI.ShouldTreatModuleAsTopLevelOutput = true;
} else if ((OI.DebugInfoKind > IRGenDebugInfoKind::LineTables &&
OI.shouldLink()) ||
Args.hasArg(options::OPT_emit_objc_header,
} else if (Args.hasArg(options::OPT_emit_objc_header,
options::OPT_emit_objc_header_path)) {
// An option has been passed which requires a module, but the user hasn't
// requested one. Generate a module, but treat it as an intermediate output.
Expand Down
22 changes: 11 additions & 11 deletions test/Driver/actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@
// RUN: %swiftc_driver -driver-print-actions -gnone -g %s 2>&1 | %FileCheck %s -check-prefix=DEBUG
// DEBUG: 0: input, "{{.*}}actions.swift", swift
// DEBUG: 1: compile, {0}, object
// DEBUG: 2: merge-module, {1}, swiftmodule
// DEBUG: 3: link, {1, 2}, image
// DEBUG: 4: generate-dSYM, {3}, dSYM
// DEBUG: 2: link, {1}, image
// DEBUG: 3: generate-dSYM, {2}, dSYM

// RUN: %swiftc_driver -driver-print-actions -gnone %s 2>&1 | %FileCheck %s -check-prefix=BASIC
// RUN: %swiftc_driver -driver-print-actions -g -gnone %s 2>&1 | %FileCheck %s -check-prefix=BASIC

// RUN: %swiftc_driver -driver-print-actions -g -verify-debug-info %s 2>&1 | %FileCheck %s -check-prefixes=DEBUG,VERIFY-DEBUG-INFO
// RUN: %swiftc_driver -driver-print-actions -gnone -g -verify-debug-info %s 2>&1 | %FileCheck %s -check-prefixes=DEBUG,VERIFY-DEBUG-INFO
// VERIFY-DEBUG-INFO: 5: verify-debug-info, {4}, none
// VERIFY-DEBUG-INFO: 4: verify-debug-info, {3}, none

// RUN: %swiftc_driver -driver-print-actions -gdwarf-types -verify-debug-info %s 2>&1 | %FileCheck %s -check-prefixes=EXEC-AND-MODULE,VERIFY-DEBUG-DWARF
// RUN: %swiftc_driver -driver-print-actions -gdwarf-types -verify-debug-info %s 2>&1 | %FileCheck %s -check-prefixes=EXEC-AND-LINK,VERIFY-DEBUG-DWARF
// EXEC-AND-LINK: 0: input, "{{.*}}actions.swift", swift
// EXEC-AND-LINK: 1: compile, {0}, object
// EXEC-AND-LINK: 2: link, {1}, image
// VERIFY-DEBUG-DWARF-TYPES: 4: generate-dSYM, {3}, dSYM
// VERIFY-DEBUG-DWARF-TYPES: 5: verify-debug-info, {4}, none

Expand Down Expand Up @@ -96,9 +98,8 @@
// DEBUG-MULTI: 3: compile, {2}, object
// DEBUG-MULTI: 4: input, "{{.*}}actions.swift", swift
// DEBUG-MULTI: 5: compile, {4}, object
// DEBUG-MULTI: 6: merge-module, {1, 3, 5}, swiftmodule
// DEBUG-MULTI: 7: link, {1, 3, 5, 6}, image
// DEBUG-MULTI: 8: generate-dSYM, {7}, dSYM
// DEBUG-MULTI: 6: link, {1, 3, 5}, image
// DEBUG-MULTI: 7: generate-dSYM, {6}, dSYM


// RUN: touch %t/a.o %t/b.o
Expand All @@ -114,9 +115,8 @@
// DEBUG-LINK-ONLY: 1: input, "{{.*}}/b.o", object
// DEBUG-LINK-ONLY: 2: input, "{{.*}}/a.swiftmodule", swiftmodule
// DEBUG-LINK-ONLY: 3: input, "{{.*}}/b.swiftmodule", swiftmodule
// DEBUG-LINK-ONLY: 4: merge-module, {2, 3}, swiftmodule
// DEBUG-LINK-ONLY: 5: link, {0, 1, 4}, image
// DEBUG-LINK-ONLY: 6: generate-dSYM, {5}, dSYM
// DEBUG-LINK-ONLY: 4: link, {0, 1, 2, 3}, image
// DEBUG-LINK-ONLY: 5: generate-dSYM, {4}, dSYM

// RUN: touch %t/c.swift
// RUN: %swiftc_driver -driver-print-actions %t/c.swift %t/a.o %t/b.o %t/a.swiftmodule %t/b.swiftmodule -o main 2>&1 | %FileCheck %s -check-prefix=LINK-SWIFTMODULES
Expand Down
4 changes: 2 additions & 2 deletions test/Driver/bindings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@

// RUN: touch %t/a.swiftmodule %t/b.swiftmodule
// RUN: %swiftc_driver -driver-print-bindings -target x86_64-apple-macosx10.9 -g %t/a.o %t/b.o %t/a.swiftmodule %t/b.swiftmodule -o main 2>&1 | %FileCheck %s -check-prefix=DEBUG-LINK-ONLY
// DEBUG-LINK-ONLY: # "x86_64-apple-macosx10.9" - "swift", inputs: ["{{.*}}/a.swiftmodule", "{{.*}}/b.swiftmodule"], output: {swiftmodule: "[[MERGED:.+\.swiftmodule]]", swiftdoc: "{{.+}}.swiftdoc"}
// DEBUG-LINK-ONLY: # "x86_64-apple-macosx10.9" - "ld", inputs: ["{{.*}}/a.o", "{{.*}}/b.o", "[[MERGED]]"], output: {image: "main"}
// DEBUG-LINK-NOT: "swift"
// DEBUG-LINK-ONLY: # "x86_64-apple-macosx10.9" - "ld", inputs: ["{{.*}}/a.o", "{{.*}}/b.o", "{{.*}}/a.swiftmodule", "{{.*}}/b.swiftmodule"], output: {image: "main"}
14 changes: 5 additions & 9 deletions test/Driver/linker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 -g %s | %FileCheck -check-prefix DEBUG %s

// RUN: %empty-directory(%t)
// RUN: touch %t/a.o
// RUN: touch %t/a.swiftmodule
// RUN: touch %t/b.o
// RUN: touch %t/b.swiftmodule
// RUN: touch %t/a.o %t/a.swiftmodule %t/b.o %t/b.swiftmodule
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 %s %t/a.o %t/a.swiftmodule %t/b.o %t/b.swiftmodule -o linker | %FileCheck -check-prefix LINK-SWIFTMODULES %s
// RUN: %swiftc_driver -driver-print-jobs -g -target x86_64-apple-macosx10.9 %s %t/a.o %t/a.swiftmodule %t/b.o %t/b.swiftmodule -o linker | %FileCheck -check-prefix LINK-SWIFTMODULES %s

// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.10 %s > %t.simple-macosx10.10.txt
// RUN: %FileCheck %s < %t.simple-macosx10.10.txt
Expand Down Expand Up @@ -264,13 +262,11 @@
// LINUX_DYNLIB-x86_64: -o dynlib.out

// DEBUG: bin/swift
// DEBUG-NEXT: bin/swift
// DEBUG-NEXT: bin/ld{{"? }}
// DEBUG: -add_ast_path {{.*}}/{{[^/]+}}.swiftmodule
// DEBUG: -o linker
// DEBUG-SAME: -o linker
// DEBUG-NEXT: {{^|bin/}}dsymutil
// DEBUG: linker
// DEBUG: -o linker.dSYM
// DEBUG-SAME: linker
// DEBUG-SAME: -o linker.dSYM

// LINK-SWIFTMODULES: bin/swift
// LINK-SWIFTMODULES-NEXT: bin/ld{{"? }}
Expand Down
2 changes: 1 addition & 1 deletion test/Driver/modulewrap.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-unknown-linux-gnu -g %s | %FileCheck %s
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-unknown-linux-gnu -g -emit-objc-header %s | %FileCheck %s

// CHECK: bin/swift -frontend{{.*}}-emit-module-path [[MOD:.*\.swiftmodule]]
// CHECK: bin/swift {{.*}}-emit-module [[MOD]]
Expand Down
30 changes: 12 additions & 18 deletions test/Driver/sdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,26 @@

// OSX-NOT: warning: no such SDK:
// OSX: bin/swift
// OSX: Driver/sdk.swift
// OSX: -sdk {{.*}}/Inputs/clang-importer-sdk
// OSX-NEXT: bin/swift
// OSX: -sdk {{.*}}/Inputs/clang-importer-sdk
// OSX: bin/{{.+}} {{.*}}.o{{[ "]}}
// OSX: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk
// OSX-SAME: Driver/sdk.swift
// OSX-SAME: -sdk {{.*}}/Inputs/clang-importer-sdk
// OSX-NEXT: bin/{{.+}} {{.*}}.o{{[ "]}}
// OSX-SAME: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk

// LINUX-NOT: warning: no such SDK:
// LINUX: bin/swift
// LINUX: Driver/sdk.swift
// LINUX: -sdk {{.*}}/Inputs/clang-importer-sdk
// LINUX-NEXT: bin/swift
// LINUX: -sdk {{.*}}/Inputs/clang-importer-sdk
// LINUX-SAME: Driver/sdk.swift
// LINUX-SAME: -sdk {{.*}}/Inputs/clang-importer-sdk
// LINUX: bin/{{.+}} {{.*}}swift_begin.o
// LINUX: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk
// LINUX: {{.*}}swift_end.o
// LINUX-SAME: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk
// LINUX-SAME: {{.*}}swift_end.o

// FREEBSD-NOT: warning: no such SDK:
// FREEBSD: bin/swift
// FREEBSD: Driver/sdk.swift
// FREEBSD: -sdk {{.*}}/Inputs/clang-importer-sdk
// FREEBSD-NEXT: bin/swift
// FREEBSD: -sdk {{.*}}/Inputs/clang-importer-sdk
// FREEBSD-SAME: Driver/sdk.swift
// FREEBSD-SAME: -sdk {{.*}}/Inputs/clang-importer-sdk
// FREEBSD: bin/{{.+}} {{.*}}swift_begin.o
// FREEBSD: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk
// FREEBSD: {{.*}}swift_end.o
// FREEBSD-SAME: {{-syslibroot|--sysroot}} {{.*}}/Inputs/clang-importer-sdk
// FREEBSD-SAME: {{.*}}swift_end.o

// RUN: %swift_driver -driver-print-jobs -repl -sdk %S/Inputs/nonexistent-sdk 2>&1 | %FileCheck %s --check-prefix=SDKWARNING
// RUN: %swift_driver -driver-print-jobs -sdk %S/Inputs/nonexistent-sdk 2>&1 | %FileCheck %s --check-prefix=SDKWARNING
Expand Down
2 changes: 1 addition & 1 deletion test/Driver/temp-files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// MAIN5-elf-NOT: .dSYM

// RUN: %empty-directory(%t) && %empty-directory(%t/tmp) && touch %t/tmp/dummy
// RUN: env TMPDIR=%t/tmp/ %swiftc_driver -target %target-triple -sdk %sdk -module-cache-path %t -emit-executable %s -o %t/main6 -g -save-temps
// RUN: env TMPDIR=%t/tmp/ %swiftc_driver -target %target-triple -sdk %sdk -module-cache-path %t -emit-executable %s -o %t/main6 -g -emit-objc-header -save-temps
// RUN: ls %t/main6
// RUN: ls %t | %FileCheck -check-prefix=MAIN6-%target-object-format %s
// RUN: ls %t/tmp | %FileCheck -check-prefix=SAVE-TEMPS %s
Expand Down

0 comments on commit e4a7bb1

Please sign in to comment.