Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -3895,6 +3895,9 @@ if (!types::isLLVMIR(Input.getType())) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-x ir"; + if (!isa(JA)) + D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) + << "-c"; Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ); } Index: test/Driver/thinlto_backend.c =================================================================== --- test/Driver/thinlto_backend.c +++ test/Driver/thinlto_backend.c @@ -6,5 +6,9 @@ // CHECK-THINLTOBE-ACTION: -fthinlto-index= // Ensure clang driver gives the expected error for incorrect input type -// RUN: not %clang -O2 -o %t1.o %s -c -fthinlto-index=%t.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-WARNING -// CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir' +// RUN: not %clang -O2 -o %t1.o %s -c -fthinlto-index=%t.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERR1 +// CHECK-ERR1: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir' + +// And for incorrect output type +// RUN: not %clang -O2 -o %t1.o -x ir %s -S -fthinlto-index=%t.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERR2 +// CHECK-ERR2: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-c'