File tree Expand file tree Collapse file tree 4 files changed +15
-6
lines changed 
rustc_codegen_llvm/src/debuginfo 
rustc_const_eval/src/interpret Expand file tree Collapse file tree 4 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
216216                    //        need to make sure that we don't break existing debuginfo consumers 
217217                    //        by doing that (at least not without a warning period). 
218218                    let  layout_type = if  ptr_type. is_box ( )  { 
219+                         // The assertion at the start of this function ensures we have a ZST allocator. 
220+                         // We'll make debuginfo "skip" all ZST allocators, not just the default allocator. 
219221                        Ty :: new_mut_ptr ( cx. tcx ,  pointee_type) 
220222                    }  else  { 
221223                        ptr_type
Original file line number Diff line number Diff line change @@ -438,14 +438,16 @@ where
438438        & self , 
439439        src :  & impl  Readable < ' tcx ,  M :: Provenance > , 
440440    )  -> InterpResult < ' tcx ,  MPlaceTy < ' tcx ,  M :: Provenance > >  { 
441+         if  src. layout ( ) . ty . is_box ( )  { 
442+             // Derefer should have removed all Box derefs. 
443+             // Some `Box` are not immediates (if they have a custom allocator) 
444+             // so the code below would fail. 
445+             bug ! ( "dereferencing {}" ,  src. layout( ) . ty) ; 
446+         } 
447+ 
441448        let  val = self . read_immediate ( src) ?; 
442449        trace ! ( "deref to {} on {:?}" ,  val. layout. ty,  * val) ; 
443450
444-         if  val. layout . ty . is_box ( )  { 
445-             // Derefer should have removed all Box derefs 
446-             bug ! ( "dereferencing {}" ,  val. layout. ty) ; 
447-         } 
448- 
449451        let  mplace = self . ref_to_mplace ( & val) ?; 
450452        Ok ( mplace) 
451453    } 
Original file line number Diff line number Diff line change @@ -1149,7 +1149,10 @@ impl<'tcx> Ty<'tcx> {
11491149        } 
11501150    } 
11511151
1152-     /// Tests whether this is a Box using the global allocator. 
1152+     /// Tests whether this is a Box definitely using the global allocator. 
1153+      /// 
1154+      /// If the allocator is still generic, the answer is `false`, but it may 
1155+      /// later turn out that it does use the global allocator. 
11531156     #[ inline]  
11541157    pub  fn  is_box_global ( self ,  tcx :  TyCtxt < ' tcx > )  -> bool  { 
11551158        match  self . kind ( )  { 
Original file line number Diff line number Diff line change @@ -137,6 +137,8 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
137137                                // Using `is_box_global` here is a bit sketchy: if this code is 
138138                                // generic over the allocator, we'll not add a retag! This is a hack 
139139                                // to make Stacked Borrows compatible with custom allocator code. 
140+                                 // It means the raw pointer inherits the tag of the box, which mostly works 
141+                                 // but can sometimes lead to unexpected aliasing errors. 
140142                                // Long-term, we'll want to move to an aliasing model where "cast to 
141143                                // raw pointer" is a complete NOP, and then this will no longer be 
142144                                // an issue. 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments