Index: include/clang/Driver/Driver.h =================================================================== --- include/clang/Driver/Driver.h +++ include/clang/Driver/Driver.h @@ -289,8 +289,14 @@ bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; } bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; } - bool embedBitcodeEnabled() const { return BitcodeEmbed == EmbedBitcode; } - bool embedBitcodeMarkerOnly() const { return BitcodeEmbed == EmbedMarker; } + bool embedBitcodeEnabled() const { return BitcodeEmbed != EmbedNone; } + bool embedBitcodeInObject() const { + // LTO has no object file output so ignore embed bitcode option in LTO. + return (BitcodeEmbed == EmbedBitcode) && !isUsingLTO(); + } + bool embedBitcodeMarkerOnly() const { + return (BitcodeEmbed == EmbedMarker) && !isUsingLTO(); + } /// Compute the desired OpenMP runtime from the flags provided. OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const; Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -626,26 +626,20 @@ setLTOMode(Args); - // Ignore -fembed-bitcode options with LTO - // since the output will be bitcode anyway. - if (getLTOMode() == LTOK_None) { - if (Arg *A = Args.getLastArg(options::OPT_fembed_bitcode_EQ)) { - StringRef Name = A->getValue(); - unsigned Model = llvm::StringSwitch(Name) - .Case("off", EmbedNone) - .Case("all", EmbedBitcode) - .Case("bitcode", EmbedBitcode) - .Case("marker", EmbedMarker) - .Default(~0U); - if (Model == ~0U) { - Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) - << Name; - } else - BitcodeEmbed = static_cast(Model); - } - } else { - // claim the bitcode option under LTO so no warning is issued. - Args.ClaimAllArgs(options::OPT_fembed_bitcode_EQ); + // Process -fembed-bitcode= flags. + if (Arg *A = Args.getLastArg(options::OPT_fembed_bitcode_EQ)) { + StringRef Name = A->getValue(); + unsigned Model = llvm::StringSwitch(Name) + .Case("off", EmbedNone) + .Case("all", EmbedBitcode) + .Case("bitcode", EmbedBitcode) + .Case("marker", EmbedMarker) + .Default(~0U); + if (Model == ~0U) { + Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) + << Name; + } else + BitcodeEmbed = static_cast(Model); } std::unique_ptr UArgs = @@ -3059,7 +3053,7 @@ const JobAction *JA = cast(A); ActionList CollapsedOffloadActions; - ToolSelector TS(JA, *TC, C, isSaveTempsEnabled(), embedBitcodeEnabled()); + ToolSelector TS(JA, *TC, C, isSaveTempsEnabled(), embedBitcodeInObject()); const Tool *T = TS.getTool(Inputs, CollapsedOffloadActions); if (!T) Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -4162,7 +4162,7 @@ } // Embed-bitcode option. - if (C.getDriver().embedBitcodeEnabled() && + if (C.getDriver().embedBitcodeInObject() && (isa(JA) || isa(JA))) { // Add flags implied by -fembed-bitcode. Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ); @@ -6352,7 +6352,7 @@ // pristine IR generated by the frontend. Ideally, a new compile action should // be added so both IR can be captured. if (C.getDriver().isSaveTempsEnabled() && - !C.getDriver().embedBitcodeEnabled() && isa(JA)) + !C.getDriver().embedBitcodeInObject() && isa(JA)) CmdArgs.push_back("-disable-llvm-passes"); if (Output.getType() == types::TY_Dependencies) { @@ -8321,9 +8321,9 @@ else CmdArgs.push_back("-no_pie"); } + // for embed-bitcode, use -bitcode_bundle in linker command - if (C.getDriver().embedBitcodeEnabled() || - C.getDriver().embedBitcodeMarkerOnly()) { + if (C.getDriver().embedBitcodeEnabled()) { // Check if the toolchain supports bitcode build flow. if (MachOTC.SupportsEmbeddedBitcode()) CmdArgs.push_back("-bitcode_bundle"); Index: test/Driver/embed-bitcode.c =================================================================== --- test/Driver/embed-bitcode.c +++ test/Driver/embed-bitcode.c @@ -41,3 +41,15 @@ // CHECK-MARKER: -fembed-bitcode=marker // CHECK-MARKER-NOT: -cc1 +// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -fembed-bitcode=all -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-LINKER +// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -fembed-bitcode=marker -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-LINKER +// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -flto=full -fembed-bitcode=bitcode -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-LINKER +// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -flto=thin -fembed-bitcode=bitcode -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-LINKER +// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -fembed-bitcode=off -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-NO-LINKER +// CHECK-LINKER: ld +// CHECK-LINKER: -bitcode_bundle +// CHECK-NO-LINKER-NOT: -bitcode_bundle + +// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=5.0 %s -fembed-bitcode -### 2>&1 | \ +// RUN: FileCheck %s -check-prefix=CHECK-PLATFORM-UNSUPPORTED +// CHECK-PLATFORM-UNSUPPORTED: -fembed-bitcode is not supported on versions of iOS prior to 6.0