Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 48b4714

Browse files
committed
Split record_header_indices loop to work around rustc/LLVM bug, on relevant targets
rustc issue: rust-lang/rust#55105 Steps to reproduce: ``` rustup target add armv7-linux-androideabi RUSTFLAGS="-Ctarget-feature=+neon" cargo build --target armv7-linux-androideabi --release ``` Output without this change: ``` Compiling hyper v0.12.11 (/home/simon/projects/servo-deps/hyper) LLVM ERROR: ran out of registers during register allocation error: Could not compile `hyper`. ```
1 parent 66a857d commit 48b4714

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

src/proto/h1/role.rs

+35-7
Original file line numberDiff line numberDiff line change
@@ -920,13 +920,41 @@ struct HeaderIndices {
920920

921921
fn record_header_indices(bytes: &[u8], headers: &[httparse::Header], indices: &mut [HeaderIndices]) {
922922
let bytes_ptr = bytes.as_ptr() as usize;
923-
for (header, indices) in headers.iter().zip(indices.iter_mut()) {
924-
let name_start = header.name.as_ptr() as usize - bytes_ptr;
925-
let name_end = name_start + header.name.len();
926-
indices.name = (name_start, name_end);
927-
let value_start = header.value.as_ptr() as usize - bytes_ptr;
928-
let value_end = value_start + header.value.len();
929-
indices.value = (value_start, value_end);
923+
924+
// FIXME: This should be a single plain `for` loop.
925+
// Splitting it is a work-around for https://github.com/rust-lang/rust/issues/55105
926+
macro_rules! split_loops_if {
927+
(
928+
cfg($($cfg: tt)+)
929+
for $i: pat in ($iter: expr) {
930+
$body1: block
931+
$body2: block
932+
}
933+
) => {
934+
for $i in $iter {
935+
$body1
936+
#[cfg(not($($cfg)+))] $body2
937+
}
938+
#[cfg($($cfg)+)]
939+
for $i in $iter {
940+
$body2
941+
}
942+
}
943+
}
944+
split_loops_if! {
945+
cfg(all(target_arch = "arm", target_feature = "v7", target_feature = "neon"))
946+
for (header, indices) in (headers.iter().zip(indices.iter_mut())) {
947+
{
948+
let name_start = header.name.as_ptr() as usize - bytes_ptr;
949+
let name_end = name_start + header.name.len();
950+
indices.name = (name_start, name_end);
951+
}
952+
{
953+
let value_start = header.value.as_ptr() as usize - bytes_ptr;
954+
let value_end = value_start + header.value.len();
955+
indices.value = (value_start, value_end);
956+
}
957+
}
930958
}
931959
}
932960

0 commit comments

Comments
 (0)