Skip to content

Commit

Permalink
Disable direct mode if -Wp,* is present
Browse files Browse the repository at this point in the history
We define the `-Wp,*` argument for GCC/Clang, disable direct mode
if it's present, since it's too hard to handle.

`ccache` allows `-Wp,-MD,path`, `-Wp,-MMD,path` and `-Wp,-D_define_`.
We don't handle these for now, since they need more careful attention.
  • Loading branch information
Alphare authored and sylvestre committed Oct 30, 2023
1 parent 3e3d3ec commit 08aae37
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/Caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ to the C/C++ compiler one, but with additional elements:
* The hash of the input file

Note that some compiler options can disable preprocessor cache mode. As of this
writing, only `-Xpreprocessor` does.
writing, only `-Xpreprocessor` and `-Wp,*` do.
2 changes: 1 addition & 1 deletion docs/Local.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Preprocessor cache mode will be disabled if any of the following holds:

- the configuration setting `use_preprocessor_cache_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 preprocessor cache mode is used. Currently, this is only `-Xpreprocessor`, but if/when sccache grows to handle options like `-Wp,X`, then more could be added to this list.
- a compiler option not supported by the preprocessor cache mode is used. Currently, this is only `-Xpreprocessor` and `-Wp,*`, but if/when sccache grows to handle options then more could be added to this list.
- the string `__TIME__` is present in the source code

Configuration options and their default values:
Expand Down
26 changes: 18 additions & 8 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ counted_array!(pub static ARGS: [ArgInfo<ArgData>; _] = [
take_arg!("-U", OsString, CanBeSeparated, PassThrough),
take_arg!("-V", OsString, Separated, PassThrough),
flag!("-Werror=pedantic", PedanticFlag),
take_arg!("-Wp", OsString, Concatenated(','), PreprocessorArgument),
flag!("-Wpedantic", PedanticFlag),
take_arg!("-Xassembler", OsString, Separated, PassThrough),
take_arg!("-Xlinker", OsString, Separated, PassThrough),
Expand Down Expand Up @@ -422,9 +423,16 @@ where
extra_hash_files.push(cwd.join(path));
&mut common_args
}
Some(PreprocessorArgumentFlag)
| Some(PreprocessorArgument(_))
| Some(PreprocessorArgumentPath(_)) => &mut preprocessor_args,
Some(PreprocessorArgument(_)) => {
too_hard_for_preprocessor_cache_mode = match arg.flag_str() {
Some(s) => s == "-Xpreprocessor" || s == "-Wp",
_ => false,
};
&mut preprocessor_args
}
Some(PreprocessorArgumentFlag) | Some(PreprocessorArgumentPath(_)) => {
&mut preprocessor_args
}
Some(DepArgumentPath(_)) | Some(NeedDepTarget) => &mut dependency_args,
Some(DoCompilation) | Some(Language(_)) | Some(Output(_)) | Some(XClang(_))
| Some(DepTarget(_)) => continue,
Expand All @@ -436,11 +444,6 @@ where
},
};

too_hard_for_preprocessor_cache_mode = match arg.flag_str() {
Some(s) => s == "-Xpreprocessor",
_ => false,
};

// Normalize attributes such as "-I foo", "-D FOO=bar", as
// "-Ifoo", "-DFOO=bar", etc. and "-includefoo", "idirafterbar" as
// "-include foo", "-idirafter bar", etc.
Expand Down Expand Up @@ -2054,5 +2057,12 @@ mod test {
o => panic!("Got unexpected parse result: {:?}", o),
};
assert!(parsed_args.too_hard_for_preprocessor_cache_mode);

let args = stringvec!["-c", "foo.c", "-o", "foo.o", r#"-Wp,-DFOO="something""#];
let parsed_args = match parse_arguments_(args, false) {
CompilerArguments::Ok(args) => args,
o => panic!("Got unexpected parse result: {:?}", o),
};
assert!(parsed_args.too_hard_for_preprocessor_cache_mode);
}
}

0 comments on commit 08aae37

Please sign in to comment.