Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -8232,7 +8232,9 @@ if (llvm::sys::fs::exists(LibLTOPath)) { CmdArgs.push_back("-lto_library"); CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath)); - } else { + } else if (D.isUsingLTO()) { + // Warn if we're using LTO with the system version of libLTO. It might not + // understand LLVM bitcode generated by our version of LLVM. D.Diag(diag::warn_drv_lto_libpath); } } Index: test/Driver/darwin-ld-lto.c =================================================================== --- test/Driver/darwin-ld-lto.c +++ test/Driver/darwin-ld-lto.c @@ -1,5 +1,3 @@ -// REQUIRES: system-darwin - // Check that ld gets "-lto_library" and warnings about libLTO.dylib path. // RUN: mkdir -p %T/bin @@ -12,12 +10,20 @@ // LINK_LTOLIB_PATH: {{ld(.exe)?"}} // LINK_LTOLIB_PATH: "-lto_library" -// RUN: %clang -target x86_64-apple-darwin10 -### %s \ +// Only warn if -flto is on the command line. +// +// RUN: %clang -target x86_64-apple-darwin10 -### %s -flto \ // RUN: -ccc-install-dir %S/dummytestdir -mlinker-version=133 2> %t.log // RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH_WRN %s -input-file %t.log // // LINK_LTOLIB_PATH_WRN: warning: libLTO.dylib relative to clang installed dir not found; using 'ld' default search path instead +// Don't warn if -flto isn't present of -Wno-liblto is present. +// +// RUN: %clang -target x86_64-apple-darwin10 -### %s \ +// RUN: -ccc-install-dir %S/dummytestdir -mlinker-version=133 2> %t.log +// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH_NOWRN %s -input-file %t.log +// // RUN: %clang -target x86_64-apple-darwin10 -### %s \ // RUN: -ccc-install-dir %S/dummytestdir -mlinker-version=133 -Wno-liblto 2> %t.log // RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH_NOWRN %s -input-file %t.log