]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Handle semi-preprocessed source code with cpp1
authorAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 25 Jun 2017 18:41:24 +0000 (20:41 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 30 Jan 2018 20:37:20 +0000 (21:37 +0100)
When using gcc -fdirectives-only or clang -frewrite-includes,
we still need to pass preprocessor arguments to the compiler.

Also make sure to set the language for clang (but not for gcc),
since the file no longer contains regular preprocessed source.

MANUAL.txt
ccache.c

index 7e1ae40ccd1aecd583b03626f5308ad113a78d63..8bcc9a0377da8e1ae9d0518a54e94271686383f8 100644 (file)
@@ -485,6 +485,12 @@ of the original source code. This makes cache misses slightly faster since the
 source code only has to be preprocessed once. The downside is that some
 compilers won't produce the same result (for instance diagnostics warnings)
 when compiling preprocessed source code.
++
+An alternative to *run_second_cpp* is to use *-fdirectives-only* (for GCC) or
+*-frewrite-includes* (for Clang). This will cause the compiler to leave the
+macros and other preprocessor information, and only process the *#include*
+directives. When run in this way, the preprocessor arguments will be passed
+to the compiler since it still has to do _some_ preprocessing (like macros).
 
 *sloppiness* (*CCACHE_SLOPPINESS*)::
 
index dbda1030cf868b2a06bd12e7ad40465da6e0a28f..6d2de7ae43a94242ad681332fce5a35bca51dad0 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -2102,6 +2102,9 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
 
        bool found_color_diagnostics = false;
 
+       bool found_directives_only = false;
+       bool found_rewrite_includes = false;
+
        int argc = expanded_args->argc;
        char **argv = expanded_args->argv;
        args_add(stripped_args, argv[0]);
@@ -2592,6 +2595,15 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                        continue;
                }
 
+               // GCC
+               if (str_eq(argv[i], "-fdirectives-only")) {
+                       found_directives_only = true;
+               }
+               // Clang
+               if (str_eq(argv[i], "-frewrite-includes")) {
+                       found_rewrite_includes = true;
+               }
+
                // Options taking an argument that we may want to rewrite to relative paths
                // to get better hit rate. A secondary effect is that paths in the standard
                // error output produced by the compiler will be normalized.
@@ -2940,6 +2952,14 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
        *compiler_args = args_copy(stripped_args);
        if (conf->run_second_cpp) {
                args_extend(*compiler_args, cpp_args);
+       } else if (found_directives_only || found_rewrite_includes) {
+               // Need to pass the macros and any other preprocessor directives again
+               args_extend(*compiler_args, cpp_args);
+               if (found_rewrite_includes) {
+                       // The preprocessed source code still needs some more preprocessing
+                       args_add(*compiler_args, "-x");
+                       args_add(*compiler_args, actual_language);
+               }
        } else if (explicit_language) {
                // Workaround for a bug in Apple's patched distcc -- it doesn't properly
                // reset the language specified with -x, so if -x is given, we have to