@@ -2704,6 +2704,8 @@ impl<'a> Linearizer<'a> {
27042704 self . types . pointer_to ( static_info. typ ) ,
27052705 ) ) ;
27062706 return result;
2707+ } else {
2708+ unreachable ! ( "static local sentinel without static_locals entry" ) ;
27072709 }
27082710 }
27092711 let result = self . alloc_pseudo ( ) ;
@@ -3629,16 +3631,7 @@ impl<'a> Linearizer<'a> {
36293631 if let Some ( local) = self . locals . get ( & name_str) . cloned ( ) {
36303632 // Check if this is a static local (sentinel value)
36313633 if local. sym . 0 == u32:: MAX {
3632- // Static local - look up the global name and emit store to global
3633- let key = format ! ( "{}.{}" , self . current_func_name, & name_str) ;
3634- if let Some ( static_info) = self . static_locals . get ( & key) . cloned ( ) {
3635- let sym_id = self . alloc_pseudo ( ) ;
3636- let pseudo = Pseudo :: sym ( sym_id, static_info. global_name ) ;
3637- if let Some ( func) = & mut self . current_func {
3638- func. add_pseudo ( pseudo) ;
3639- }
3640- self . emit ( Instruction :: store ( final_result, sym_id, 0 , typ, store_size) ) ;
3641- }
3634+ self . emit_static_local_store ( & name_str, final_result, typ, store_size) ;
36423635 } else {
36433636 // Regular local variable
36443637 self . emit ( Instruction :: store (
@@ -3947,22 +3940,7 @@ impl<'a> Linearizer<'a> {
39473940 if let Some ( local) = self . locals . get ( & name_str) . cloned ( ) {
39483941 // Check if this is a static local (sentinel value)
39493942 if local. sym . 0 == u32:: MAX {
3950- // Static local - look up the global name and emit store to global
3951- let key = format ! ( "{}.{}" , self . current_func_name, & name_str) ;
3952- if let Some ( static_info) = self . static_locals . get ( & key) . cloned ( ) {
3953- let sym_id = self . alloc_pseudo ( ) ;
3954- let pseudo = Pseudo :: sym ( sym_id, static_info. global_name ) ;
3955- if let Some ( func) = & mut self . current_func {
3956- func. add_pseudo ( pseudo) ;
3957- }
3958- self . emit ( Instruction :: store (
3959- final_result,
3960- sym_id,
3961- 0 ,
3962- typ,
3963- store_size,
3964- ) ) ;
3965- }
3943+ self . emit_static_local_store ( & name_str, final_result, typ, store_size) ;
39663944 } else {
39673945 // Regular local variable
39683946 self . emit ( Instruction :: store (
@@ -4146,6 +4124,8 @@ impl<'a> Linearizer<'a> {
41464124 self . emit ( Instruction :: load ( result, sym_id, 0 , typ, size) ) ;
41474125 return result;
41484126 }
4127+ } else {
4128+ unreachable ! ( "static local sentinel without static_locals entry" ) ;
41494129 }
41504130 }
41514131 let result = self . alloc_pseudo ( ) ;
@@ -4798,6 +4778,23 @@ impl<'a> Linearizer<'a> {
47984778 id
47994779 }
48004780
4781+ /// Emit a store to a static local variable.
4782+ /// The caller must have already verified that `name_str` refers to a static local
4783+ /// (i.e., the local's sym is the sentinel value u32::MAX).
4784+ fn emit_static_local_store ( & mut self , name_str : & str , value : PseudoId , typ : TypeId , size : u32 ) {
4785+ let key = format ! ( "{}.{}" , self . current_func_name, name_str) ;
4786+ if let Some ( static_info) = self . static_locals . get ( & key) . cloned ( ) {
4787+ let sym_id = self . alloc_pseudo ( ) ;
4788+ let pseudo = Pseudo :: sym ( sym_id, static_info. global_name ) ;
4789+ if let Some ( func) = & mut self . current_func {
4790+ func. add_pseudo ( pseudo) ;
4791+ }
4792+ self . emit ( Instruction :: store ( value, sym_id, 0 , typ, size) ) ;
4793+ } else {
4794+ unreachable ! ( "static local sentinel without static_locals entry" ) ;
4795+ }
4796+ }
4797+
48014798 /// Emit stores to zero-initialize an aggregate (struct, union, or array)
48024799 /// This handles C99 6.7.8p19: uninitialized members must be zero-initialized
48034800 fn emit_aggregate_zero ( & mut self , base_sym : PseudoId , typ : TypeId ) {
@@ -5895,22 +5892,7 @@ impl<'a> Linearizer<'a> {
58955892 if let Some ( local) = self . locals . get ( & name_str) . cloned ( ) {
58965893 // Check if this is a static local (sentinel value)
58975894 if local. sym . 0 == u32:: MAX {
5898- // Static local - look up the global name and emit store to global
5899- let key = format ! ( "{}.{}" , self . current_func_name, & name_str) ;
5900- if let Some ( static_info) = self . static_locals . get ( & key) . cloned ( ) {
5901- let sym_id = self . alloc_pseudo ( ) ;
5902- let pseudo = Pseudo :: sym ( sym_id, static_info. global_name ) ;
5903- if let Some ( func) = & mut self . current_func {
5904- func. add_pseudo ( pseudo) ;
5905- }
5906- self . emit ( Instruction :: store (
5907- final_val,
5908- sym_id,
5909- 0 ,
5910- target_typ,
5911- target_size,
5912- ) ) ;
5913- }
5895+ self . emit_static_local_store ( & name_str, final_val, target_typ, target_size) ;
59145896 } else {
59155897 // Regular local variable: emit Store
59165898 self . emit ( Instruction :: store (
0 commit comments