1212 * dead variable and does NOT wrtie it back to the stack.
1313 */
1414
15+ /* Aligns size to nearest multiple of 4, this meets
16+ * ARMv7's alignment requirement.
17+ *
18+ * This function should
19+ * be called whenever handling with user-defined type's
20+ * size.
21+ */
22+ int align_size (int i )
23+ {
24+ return i <= 4 ? 4 : (i + 3 ) & ~3 ;
25+ }
26+
1527bool check_live_out (basic_block_t * bb , var_t * var )
1628{
1729 for (int i = 0 ; i < bb -> live_out_idx ; i ++ ) {
@@ -239,11 +251,11 @@ void reg_alloc()
239251 src0 = GLOBAL_FUNC .stack_size ;
240252 if (global_insn -> rd -> is_ptr )
241253 GLOBAL_FUNC .stack_size +=
242- (PTR_SIZE * global_insn -> rd -> array_size );
254+ align_size (PTR_SIZE * global_insn -> rd -> array_size );
243255 else {
244256 type_t * type = find_type (global_insn -> rd -> type_name , 0 );
245257 GLOBAL_FUNC .stack_size +=
246- (global_insn -> rd -> array_size * type -> size );
258+ align_size (global_insn -> rd -> array_size * type -> size );
247259 }
248260
249261 dest =
@@ -260,7 +272,7 @@ void reg_alloc()
260272 strcmp (global_insn -> rd -> type_name , "char" ) &&
261273 strcmp (global_insn -> rd -> type_name , "_Bool" )) {
262274 type_t * type = find_type (global_insn -> rd -> type_name , 0 );
263- GLOBAL_FUNC .stack_size += type -> size ;
275+ GLOBAL_FUNC .stack_size += align_size ( type -> size ) ;
264276 } else
265277 /* 'char' is aligned to one byte for the convenience */
266278 GLOBAL_FUNC .stack_size += 4 ;
@@ -365,9 +377,10 @@ void reg_alloc()
365377 }
366378
367379 if (insn -> rd -> array_size )
368- fn -> func -> stack_size += (insn -> rd -> array_size * sz );
380+ fn -> func -> stack_size +=
381+ align_size (insn -> rd -> array_size * sz );
369382 else
370- fn -> func -> stack_size += sz ;
383+ fn -> func -> stack_size += align_size ( sz ) ;
371384
372385 dest = prepare_dest (bb , insn -> rd , -1 , -1 );
373386 ir = bb_add_ph2_ir (bb , OP_address_of );
0 commit comments