Skip to content

Commit 02198d8

Browse files
committed
Fix a stack overflow caused by GCC creating too many local variables
1 parent 530cdb4 commit 02198d8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/builder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,15 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
19071907
v2: RValue<'gcc>,
19081908
mask: RValue<'gcc>,
19091909
) -> RValue<'gcc> {
1910+
// NOTE: if the `mask` is a constant value, the following code will copy it in many places,
1911+
// which will make GCC create a lot (+4000) local variables in some cases.
1912+
// So we assign it to an explicit local variable once to avoid this.
1913+
let func = self.current_func();
1914+
let mask_var = func.new_local(self.location, mask.get_type(), "mask");
1915+
let block = self.block;
1916+
block.add_assignment(self.location, mask_var, mask);
1917+
let mask = mask_var.to_rvalue();
1918+
19101919
// TODO(antoyo): use a recursive unqualified() here.
19111920
let vector_type = v1.get_type().unqualified().dyncast_vector().expect("vector type");
19121921
let element_type = vector_type.get_element_type();

0 commit comments

Comments
 (0)