]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Improve statistics for “-P -E”
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 13 Apr 2021 06:45:09 +0000 (08:45 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 13 Apr 2021 18:31:40 +0000 (20:31 +0200)
“-P” is currently considered too hard, so when it’s used in conjunction
with “-E” the “unsupported compiler option” statistics counter is
increased since “-P” is found before “-E” on the command line.

Improve this by not passing “-P” to the preprocessor so that’s it’s in
effect supported. “-P -E” will then instead bail out on “-E”, increasing
“called for preprocessing” instead.

Closes #812.

src/argprocessing.cpp
src/compopt.cpp
test/suites/base.bash

index a2e600bf99b9717a3b69db967bf4a55c181719b8..b2ba1e0c32e7d7ef931af8bd5edfe4ae6793e744 100644 (file)
@@ -618,13 +618,19 @@ process_arg(Context& ctx,
     return nullopt;
   }
 
+  if (args[i] == "-P" || args[i] == "-Wp,-P") {
+    // Avoid passing -P to the preprocessor since it removes preprocessor
+    // information we need.
+    state.compiler_only_args.push_back(args[i]);
+    LOG("{} used; not compiling preprocessed code", args[i]);
+    config.set_run_second_cpp(true);
+    return nullopt;
+  }
+
   if (Util::starts_with(args[i], "-Wp,")) {
-    if (args[i] == "-Wp,-P" || args[i].find(",-P,") != std::string::npos
+    if (args[i].find(",-P,") != std::string::npos
         || Util::ends_with(args[i], ",-P")) {
-      // -P removes preprocessor information in such a way that the object file
-      // from compiling the preprocessed file will not be equal to the object
-      // file produced when compiling without ccache.
-      LOG_RAW("Too hard option -Wp,-P detected");
+      // -P together with other preprocessor options is just too hard.
       return Statistic::unsupported_compiler_option;
     } else if (Util::starts_with(args[i], "-Wp,-MD,")
                && args[i].find(',', 8) == std::string::npos) {
index d69f74aa852fcaec45536e4c3f688cb1af5588b4..96cc047c88133f1a2eeb0a6c536df0e0614a5841 100644 (file)
@@ -76,7 +76,6 @@ const CompOpt compopts[] = {
   {"-MM", TOO_HARD},
   {"-MQ", TAKES_ARG},
   {"-MT", TAKES_ARG},
-  {"-P", TOO_HARD},
   {"-U", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG},
   {"-V", TAKES_ARG},
   {"-Wa,", TAKES_CONCAT_ARG | AFFECTS_COMP},
index 9629a06d3b27a4541f689f2f182696583ed97bd4..37b7755daa86bfe72b4fd993bfcaeaedb673f65d 100644 (file)
@@ -1224,43 +1224,59 @@ EOF
     expect_stat 'files in cache' 0
 
     # -------------------------------------------------------------------------
-    TEST "-P"
+    TEST "-P -c"
 
-    # Check that -P disables ccache. (-P removes preprocessor information in
-    # such a way that the object file from compiling the preprocessed file will
-    # not be equal to the object file produced when compiling without ccache.)
+    $CCACHE_COMPILE -P -c test1.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
 
-    $CCACHE_COMPILE -c -P test1.c
+    $CCACHE_COMPILE -P -c test1.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+
+    # -------------------------------------------------------------------------
+    TEST "-P -E"
+
+    $CCACHE_COMPILE -P -E test1.c
     expect_stat 'cache hit (direct)' 0
     expect_stat 'cache hit (preprocessed)' 0
     expect_stat 'cache miss' 0
-    expect_stat 'unsupported compiler option' 1
+    expect_stat 'called for preprocessing' 1
 
     # -------------------------------------------------------------------------
     TEST "-Wp,-P"
 
-    # Check that -Wp,-P disables ccache. (-P removes preprocessor information
-    # in such a way that the object file from compiling the preprocessed file
-    # will not be equal to the object file produced when compiling without
-    # ccache.)
-
     $CCACHE_COMPILE -c -Wp,-P test1.c
     expect_stat 'cache hit (direct)' 0
     expect_stat 'cache hit (preprocessed)' 0
-    expect_stat 'cache miss' 0
-    expect_stat 'unsupported compiler option' 1
+    expect_stat 'cache miss' 1
+
+    $CCACHE_COMPILE -c -Wp,-P test1.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+
+    # -------------------------------------------------------------------------
+    TEST "-Wp,-P,-DFOO"
+
+    # Check that -P disables ccache when used in combination with other -Wp,
+    # options. (-P removes preprocessor information in such a way that the
+    # object file from compiling the preprocessed file will not be equal to the
+    # object file produced when compiling without ccache.)
 
     $CCACHE_COMPILE -c -Wp,-P,-DFOO test1.c
     expect_stat 'cache hit (direct)' 0
     expect_stat 'cache hit (preprocessed)' 0
     expect_stat 'cache miss' 0
-    expect_stat 'unsupported compiler option' 2
+    expect_stat 'unsupported compiler option' 1
 
     $CCACHE_COMPILE -c -Wp,-DFOO,-P test1.c
     expect_stat 'cache hit (direct)' 0
     expect_stat 'cache hit (preprocessed)' 0
     expect_stat 'cache miss' 0
-    expect_stat 'unsupported compiler option' 3
+    expect_stat 'unsupported compiler option' 2
 
     # -------------------------------------------------------------------------
     TEST "-Wp,-D"