File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ //@ run-pass
2+ //! Check that we can codegen setting and getting discriminants, including non-null niches,
3+ //! for enums with a pointer-like ABI. This used to crash llvm.
4+
5+ #![ feature( rustc_attrs) ]
6+ use std:: ptr;
7+
8+
9+ #[ rustc_layout_scalar_valid_range_start( 1 ) ]
10+ #[ rustc_layout_scalar_valid_range_end( 100 ) ]
11+ #[ derive( Copy , Clone ) ]
12+ struct PointerWithRange ( #[ allow( dead_code) ] * const u8 ) ;
13+
14+
15+ fn main ( ) {
16+ let val = unsafe { PointerWithRange ( ptr:: without_provenance ( 90 ) ) } ;
17+
18+ let ptr = Some ( val) ;
19+ let Some ( _) = ptr else { unreachable ! ( ) } ;
20+ let ptr = Some ( Some ( val) ) ;
21+ let Some ( Some ( _) ) = ptr else { unreachable ! ( ) } ;
22+ let ptr: Option < Option < PointerWithRange > > = None ;
23+ let None = ptr else { unreachable ! ( ) } ;
24+ }
Original file line number Diff line number Diff line change 55#![ allow( dead_code) ]
66#![ feature( never_type) ]
77#![ feature( pointer_is_aligned_to) ]
8+ #![ feature( rustc_attrs) ]
89
910use std:: mem:: size_of;
1011use std:: num:: NonZero ;
@@ -237,6 +238,15 @@ struct VecDummy {
237238 len : usize ,
238239}
239240
241+ #[ rustc_layout_scalar_valid_range_start( 1 ) ]
242+ #[ rustc_layout_scalar_valid_range_end( 100 ) ]
243+ struct PointerWithRange ( #[ allow( dead_code) ] * const u8 ) ;
244+
245+ const _: ( ) = {
246+ assert ! ( size_of:: <Option <PointerWithRange >>( ) == size_of:: <PointerWithRange >( ) ) ;
247+ assert ! ( size_of:: <Option <Option <PointerWithRange >>>( ) == size_of:: <PointerWithRange >( ) ) ;
248+ } ;
249+
240250pub fn main ( ) {
241251 assert_eq ! ( size_of:: <u8 >( ) , 1 as usize ) ;
242252 assert_eq ! ( size_of:: <u32 >( ) , 4 as usize ) ;
@@ -354,4 +364,6 @@ pub fn main() {
354364 assert ! ( ptr:: from_ref( & v. a) . addr( ) > ptr:: from_ref( & v. b) . addr( ) ) ;
355365
356366
367+ assert_eq ! ( size_of:: <Option <PointerWithRange >>( ) , size_of:: <PointerWithRange >( ) ) ;
368+ assert_eq ! ( size_of:: <Option <Option <PointerWithRange >>>( ) , size_of:: <PointerWithRange >( ) ) ;
357369}
You can’t perform that action at this time.
0 commit comments