@@ -41,9 +41,6 @@ use crate::type_of::LayoutGccExt;
4141// TODO(antoyo)
4242type Funclet = ( ) ;
4343
44- // TODO(antoyo): remove this variable.
45- static mut RETURN_VALUE_COUNT : usize = 0 ;
46-
4744enum ExtremumOperation {
4845Max ,
4946Min ,
@@ -52,13 +49,18 @@ enum ExtremumOperation {
5249pub struct Builder < ' a : ' gcc , ' gcc , ' tcx > {
5350pub cx : & ' a CodegenCx < ' gcc , ' tcx > ,
5451pub block : Block < ' gcc > ,
55- stack_var_count : Cell < usize > ,
5652pub location : Option < Location < ' gcc > > ,
53+ value_counter : Cell < u64 > ,
5754}
5855
5956impl < ' a , ' gcc , ' tcx > Builder < ' a , ' gcc , ' tcx > {
6057fn with_cx ( cx : & ' a CodegenCx < ' gcc , ' tcx > , block : Block < ' gcc > ) -> Self {
61- Builder { cx, block, stack_var_count : Cell :: new ( 0 ) , location : None }
58+ Builder { cx, block, location : None , value_counter : Cell :: new ( 0 ) }
59+ }
60+
61+ fn next_value_counter ( & self ) -> u64 {
62+ self . value_counter . set ( self . value_counter . get ( ) + 1 ) ;
63+ self . value_counter . get ( )
6264}
6365
6466fn atomic_extremum (
@@ -324,11 +326,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
324326let void_type = self . context . new_type :: < ( ) > ( ) ;
325327let current_func = self . block . get_function ( ) ;
326328if return_type != void_type {
327- unsafe { RETURN_VALUE_COUNT += 1 } ;
328329let result = current_func. new_local (
329330self . location ,
330331 return_type,
331- & format ! ( "returnValue{}" , unsafe { RETURN_VALUE_COUNT } ) ,
332+ & format ! ( "returnValue{}" , self . next_value_counter ( ) ) ,
332333) ;
333334self . block . add_assignment (
334335self . location ,
@@ -384,7 +385,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
384385let current_func = self . block . get_function ( ) ;
385386
386387if return_type != void_type {
387- unsafe { RETURN_VALUE_COUNT += 1 } ;
388388let return_value = self . cx . context . new_call_through_ptr ( self . location , func_ptr, & args) ;
389389let return_value = llvm:: adjust_intrinsic_return_value (
390390self ,
@@ -397,7 +397,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
397397let result = current_func. new_local (
398398self . location ,
399399 return_value. get_type ( ) ,
400- & format ! ( "ptrReturnValue{}" , unsafe { RETURN_VALUE_COUNT } ) ,
400+ & format ! ( "ptrReturnValue{}" , self . next_value_counter ( ) ) ,
401401) ;
402402self . block . add_assignment ( self . location , result, return_value) ;
403403 result. to_rvalue ( )
@@ -446,11 +446,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
446446let return_type = self . context . new_type :: < bool > ( ) ;
447447let current_func = self . block . get_function ( ) ;
448448// TODO(antoyo): return the new_call() directly? Since the overflow function has no side-effects.
449- unsafe { RETURN_VALUE_COUNT += 1 } ;
450449let result = current_func. new_local (
451450self . location ,
452451 return_type,
453- & format ! ( "overflowReturnValue{}" , unsafe { RETURN_VALUE_COUNT } ) ,
452+ & format ! ( "overflowReturnValue{}" , self . next_value_counter ( ) ) ,
454453) ;
455454self . block . add_assignment (
456455self . location ,
@@ -934,9 +933,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
934933fn alloca ( & mut self , size : Size , align : Align ) -> RValue < ' gcc > {
935934let ty = self . cx . type_array ( self . cx . type_i8 ( ) , size. bytes ( ) ) . get_aligned ( align. bytes ( ) ) ;
936935// TODO(antoyo): It might be better to return a LValue, but fixing the rustc API is non-trivial.
937- self . stack_var_count . set ( self . stack_var_count . get ( ) + 1 ) ;
938936self . current_func ( )
939- . new_local ( self . location , ty, & format ! ( "stack_var_{}" , self . stack_var_count . get ( ) ) )
937+ . new_local ( self . location , ty, & format ! ( "stack_var_{}" , self . next_value_counter ( ) ) )
940938. get_address ( self . location )
941939}
942940
@@ -959,11 +957,10 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
959957} ;
960958let ptr = self . context . new_cast ( self . location , ptr, aligned_type. make_pointer ( ) ) ;
961959let deref = ptr. dereference ( self . location ) . to_rvalue ( ) ;
962- unsafe { RETURN_VALUE_COUNT += 1 } ;
963960let loaded_value = function. new_local (
964961self . location ,
965962 aligned_type,
966- & format ! ( "loadedValue{}" , unsafe { RETURN_VALUE_COUNT } ) ,
963+ & format ! ( "loadedValue{}" , self . next_value_counter ( ) ) ,
967964) ;
968965 block. add_assignment ( self . location , loaded_value, deref) ;
969966 loaded_value. to_rvalue ( )
0 commit comments