]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Support -Xpreprocessor -fopenmp in direct mode
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Apr 2024 13:22:40 +0000 (15:22 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 27 Apr 2024 14:12:02 +0000 (16:12 +0200)
All uses of -Xpreprocessor disable the direct mode as a safety measure
since the command line could include things like

  -Xpreprocessor -MF -Xpreprocessor file.d

which ccache needs to understand as

  -MF file.d

Ideally, ccache should handle this in a generic way. Meanwhile, let's
allow it in the a special case of "-Xpreprocessor -fopenmp" since that's
required on macOS to enable OpenMP.

Closes #1434.

doc/MANUAL.adoc
src/ccache/argprocessing.cpp
src/ccache/compopt.cpp
unittest/test_compopt.cpp

index 9e74030cb3744bb513efacc772bc9bd694a67ab2..73aca1b308a1029568b556f35a631b530e90455e 100644 (file)
@@ -1621,10 +1621,10 @@ The direct mode will be disabled if any of the following holds:
 * <<config_direct_mode,*direct_mode*>> is false
 * a modification time of one of the include files is too new (needed to avoid a
   race condition)
-* a compiler option not supported by the direct mode is used:
+* a compiler option not supported by the direct mode is used, for example:
 ** a `-Wp,++*++` compiler option other than `-Wp,-MD,<path>`, `-Wp,-MMD,<path>`,
    `-Wp,-D<macro[=defn]>` or `-Wp,-U<macro>`
-** `-Xpreprocessor`
+** most uses of `-Xpreprocessor`
 * the string `+__TIME__+` is present in the source code
 
 
index f8f454eb1863185b6c57d1159f322b760c16510a..c014983363f2c3b70f50b01deb2df024754932a6 100644 (file)
@@ -433,6 +433,23 @@ process_option_arg(const Context& ctx,
     config.set_direct_mode(false);
   }
 
+  // Handle -Xpreprocessor options.
+  if (util::starts_with(arg, "-Xpreprocessor")) {
+    if (i == args.size() - 1) {
+      LOG("Missing argument to {}", args[i]);
+      return Statistic::bad_compiler_arguments;
+    }
+    if (args[i + 1] == "-fopenmp") {
+      ++i;
+      return Statistic::none;
+    } else {
+      LOG("Unsupported compiler option for direct mode: {} {}",
+          args[i],
+          args[i + 1]);
+      config.set_direct_mode(false);
+    }
+  }
+
   // Handle -Xarch_* options.
   if (util::starts_with(arg, "-Xarch_")) {
     if (i == args.size() - 1) {
index 04be7b63610ba2a737d9da188a262dd9bbfef1e5..ee4dcb7fb2f0f1f34fc3adec1e4299b8eab01c6f 100644 (file)
@@ -96,7 +96,7 @@ const CompOpt compopts[] = {
   {"-Xclang", TAKES_ARG},
   {"-Xcompiler", AFFECTS_CPP | TAKES_ARG}, // nvcc
   {"-Xlinker", TAKES_ARG | TAKES_CONCAT_ARG | AFFECTS_COMP},
-  {"-Xpreprocessor", AFFECTS_CPP | TOO_HARD_DIRECT | TAKES_ARG},
+  {"-Xpreprocessor", AFFECTS_CPP | TAKES_ARG},
   {"-Yc", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH}, // msvc
   {"-Yu", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH}, // msvc
   {"-all_load", AFFECTS_COMP},
index 84e10bbd90953e9ca5a63b43bae5c8ce0863d1d2..220d1486ee00e3e4b2841ecd4cad2db11a8e171b 100644 (file)
@@ -65,7 +65,6 @@ TEST_CASE("too_hard")
 
 TEST_CASE("too_hard_for_direct_mode")
 {
-  CHECK(compopt_too_hard_for_direct_mode("-Xpreprocessor"));
   CHECK(!compopt_too_hard_for_direct_mode("-nostdinc"));
 }