From: Anders F Björklund Date: Sun, 25 Jun 2017 18:41:24 +0000 (+0200) Subject: Handle semi-preprocessed source code with cpp1 X-Git-Tag: v3.4~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8759215697ddec778b272b4d033484f591bd2f9f;p=thirdparty%2Fccache.git Handle semi-preprocessed source code with cpp1 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. --- diff --git a/MANUAL.txt b/MANUAL.txt index 7e1ae40cc..8bcc9a037 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -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*):: diff --git a/ccache.c b/ccache.c index dbda1030c..6d2de7ae4 100644 --- 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