Skip to content

Commit 69ae6cd

Browse files
matthewcarrolljrose-apple
authored andcommitted
[Driver] SR-3352: Warn on and ignore -embed-bitcode when not generating object files (#7962)
Commands like -emit-sil and -emit-module (on its own) do not produce object files. When -embed-bitcode is also set, the driver runs a backend job to generate a module that fails. This commit emits a warning instead and ignores the -embed-bitcode option. https://bugs.swift.org/browse/SR-3352
1 parent e58d02b commit 69ae6cd

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ ERROR(error_conflicting_options, none,
125125
"conflicting options '%0' and '%1'",
126126
(StringRef, StringRef))
127127

128+
WARNING(warn_ignore_embed_bitcode, none,
129+
"ignoring -embed-bitcode since no object file is being generated", ())
130+
128131
#ifndef DIAG_NO_UNDEF
129132
# if defined(DIAG)
130133
# undef DIAG

lib/Driver/Driver.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,16 @@ static bool populateOutOfDateMap(InputInfoMap &map, StringRef argsHashStr,
448448
}
449449
}
450450

451+
// warn if -embed-bitcode is set and the output type is not an object
452+
static void validateEmbedBitcode(DerivedArgList &Args, OutputInfo &OI,
453+
DiagnosticEngine &Diags) {
454+
if (Args.hasArg(options::OPT_embed_bitcode) &&
455+
OI.CompilerOutputType != types::TY_Object) {
456+
Diags.diagnose(SourceLoc(), diag::warn_ignore_embed_bitcode);
457+
Args.eraseArg(options::OPT_embed_bitcode);
458+
}
459+
}
460+
451461
std::unique_ptr<Compilation> Driver::buildCompilation(
452462
ArrayRef<const char *> Args) {
453463
llvm::PrettyStackTraceString CrashInfo("Compilation construction");
@@ -535,6 +545,8 @@ std::unique_ptr<Compilation> Driver::buildCompilation(
535545

536546
assert(OI.CompilerOutputType != types::ID::TY_INVALID &&
537547
"buildOutputInfo() must set a valid output type!");
548+
549+
validateEmbedBitcode(*TranslatedArgList, OI, Diags);
538550

539551
if (OI.CompilerMode == OutputInfo::Mode::REPL)
540552
// REPL mode expects no input files, so suppress the error.

test/Driver/embed-bitcode.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,15 @@
7777
// CHECK-LIB: -embed-bitcode
7878
// CHECK-LIB: -disable-llvm-optzns
7979
// CHECK-LIB-NOT: swift -frontend
80+
81+
// RUN: %target-swiftc_driver -embed-bitcode -emit-module %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE
82+
// RUN: %target-swiftc_driver -embed-bitcode -emit-module-path a.swiftmodule %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE
83+
// RUN: %target-swiftc_driver -embed-bitcode -emit-sib %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE
84+
// RUN: %target-swiftc_driver -embed-bitcode -emit-sibgen %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE
85+
// RUN: %target-swiftc_driver -embed-bitcode -emit-sil %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE
86+
// RUN: %target-swiftc_driver -embed-bitcode -emit-silgen %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE
87+
// RUN: %target-swiftc_driver -embed-bitcode -emit-ir %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE
88+
// RUN: %target-swiftc_driver -embed-bitcode -emit-bc %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE
89+
// RUN: %target-swiftc_driver -embed-bitcode -emit-assembly %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE
90+
// WARN-EMBED-BITCODE: warning: ignoring -embed-bitcode since no object file is being generated
91+
// WARN-EMBED-BITCODE-NOT: -embed-bitcode

0 commit comments

Comments
 (0)