Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,13 @@ static CACHED_ENV_VARS: Lazy<HashSet<&'static OsStr>> = Lazy::new(|| {
.collect()
});

const NON_HASHABLE_ARGS: &[&str] = &[
"-fdebug-prefix-map",
"-fmacro-prefix-map",
"-ffile-prefix-map",
"-fdebug-compilation-dir",
];

/// Compute the hash key of `compiler` compiling `preprocessor_output` with `args`.
pub fn hash_key(
compiler_digest: &str,
Expand All @@ -1462,7 +1469,13 @@ pub fn hash_key(
m.update(&[plusplus as u8]);
m.update(CACHE_VERSION);
m.update(language.as_str().as_bytes());
for arg in arguments {
'arg_loop: for arg in arguments {
for non_hashable in NON_HASHABLE_ARGS {
if arg.to_string_lossy().starts_with(non_hashable) {
// Skip non-hashable arguments.
continue 'arg_loop;
}
}
arg.hash(&mut HashToDigest { digest: &mut m });
}
for hash in extra_hashes {
Expand Down Expand Up @@ -1576,6 +1589,30 @@ mod test {
);
}

#[test]
fn test_hash_key_non_hashable_args() {
let digest = "abcd";
const PREPROCESSED: &[u8] = b"hello world";

let args = ovec!["arg1", "arg2", "arg3"];
let mut args_with_non_hashable: Vec<OsString> =
NON_HASHABLE_ARGS.iter().map(OsString::from).collect();

args_with_non_hashable.extend(args.clone());
assert_eq!(
hash_key(digest, Language::C, &args, &[], &[], PREPROCESSED, false),
hash_key(
digest,
Language::C,
&args_with_non_hashable,
&[],
&[],
PREPROCESSED,
false
)
);
}

#[test]
fn test_hash_key_preprocessed_content_differs() {
let args = ovec!["a", "b", "c"];
Expand Down
Loading