Skip to content
Merged
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
52 changes: 51 additions & 1 deletion src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ fn process_preprocessed_file(
// GCC precompiled header:
|| slice[1..].starts_with(PRAGMA_GCC_PCH_PREPROCESS)
// HP/AIX:
|| (&slice[1..5] == b"line "))
|| slice[1..].starts_with(b"line "))
&& (start == 0 || bytes[start - 1] == b'\n')
{
match process_preprocessor_line(
Expand Down Expand Up @@ -1905,6 +1905,56 @@ mod test {
assert_eq!(include_files.len(), 0);
}

#[test]
fn test_process_preprocessed_file_line_directive() {
let header = PathBuf::from("tests/test.h");
let fs_impl = TestFs {
metadata_results: Mutex::new(
[(
header.clone(),
PreprocessorFileMetadata {
is_dir: false,
is_file: true,
modified: Some(Timestamp::new(12341234, 0)),
ctime_or_creation: None,
},
)]
.into_iter()
.collect(),
),
open_results: Mutex::new(
[(
header.clone(),
Box::new(&b"contents"[..]) as Box<dyn std::io::Read>,
)]
.into_iter()
.collect(),
),
};
let mut bytes = br#"#line 1 "tests/test.h"
int value;
"#
.to_vec();
let mut include_files = HashMap::new();

let success = process_preprocessed_file(
Path::new("tests/test.c"),
Path::new(""),
&mut bytes,
&mut include_files,
PreprocessorCacheModeConfig::activated(),
std::time::SystemTime::now(),
fs_impl,
)
.unwrap();

assert!(success);
assert_eq!(
include_files.get(&header).map(String::as_str),
Some("a93900c371d997927c5bc568ea538bed59ae5c960021dcfe7b0b369da5267528")
);
}

/// A filesystem interface that only panics to test that we don't access it.
struct PanicFs;

Expand Down
Loading