diff options
author | Kim Gräsman <kim.grasman@gmail.com> | 2022-07-10 09:28:31 +0200 |
---|---|---|
committer | Kim Gräsman <kim.grasman@gmail.com> | 2022-09-01 20:03:59 +0200 |
commit | eee6d6a1994d1b2e70bd7c20e8e271318ad28921 (patch) | |
tree | 8aa37f4545418ac2d546810b6d48eb51d52cb42f | |
parent | 6f772242cfc0f5dff0b0193e9b31d9fc6bf3d4e3 (diff) |
Drop -save-temps command-line args
IWYU doesn't produce any outputs, so -save-temps does not have any useful
effect.
Before this patch, passing -save-temps did, however, generate multiple
compilation jobs which caused a fatal error:
error: unable to handle compilation, expected exactly one compiler job
Filter the arguments out, similar to what Clang tools do by default.
Fixes issue #1060.
-rw-r--r-- | iwyu_driver.cc | 7 | ||||
-rw-r--r-- | tests/driver/save_temps.c | 21 |
2 files changed, 28 insertions, 0 deletions
diff --git a/iwyu_driver.cc b/iwyu_driver.cc index 42fea35..f7bd110 100644 --- a/iwyu_driver.cc +++ b/iwyu_driver.cc @@ -21,6 +21,7 @@ #include "llvm/ADT/ArrayRef.h" // IWYU pragma: keep #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Triple.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/ErrorOr.h" @@ -175,6 +176,12 @@ CompilerInstance* CreateCompilerInstance(int argc, const char **argv) { ExpandArgv(argc, argv, args, SavedStrings); + // Drop -save-temps arguments to avoid multiple compilation jobs. + llvm::erase_if(args, [](const char *v) { + StringRef arg(v); + return arg.startswith("-save-temps") || arg.startswith("--save-temps"); + }); + // FIXME: This is a hack to try to force the driver to do something we can // recognize. We need to extend the driver library to support this use model // (basically, exactly one input, and the operation mode is hard wired). diff --git a/tests/driver/save_temps.c b/tests/driver/save_temps.c new file mode 100644 index 0000000..3ca657c --- /dev/null +++ b/tests/driver/save_temps.c @@ -0,0 +1,21 @@ +//===--- save_temps.c - test input file for iwyu --------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Run IWYU with some variations of '-save-temps' to prove that it can still run +// to completion (see issue #1060). + +// IWYU_ARGS: -save-temps --save-temps -save-temps=obj + +struct Unused {}; + +/**** IWYU_SUMMARY + +(tests/driver/save_temps.c has correct #includes/fwd-decls) + +***** IWYU_SUMMARY */ |