File tree Expand file tree Collapse file tree
cpp2rust/converter/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1315,6 +1315,7 @@ bool ConverterRefCount::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) {
13151315 return false ;
13161316 }
13171317 if (expr->getCastKind () == clang::CK_NullToPointer) {
1318+ PushConversionKind push (*this , ConversionKind::Unboxed);
13181319 StrCat (GetDefaultAsString (expr->getType ()));
13191320 computed_expr_type_ = ComputedExprType::FreshPointer;
13201321 return false ;
Original file line number Diff line number Diff line change @@ -74,5 +74,30 @@ fn main_0() -> i32 {
7474 let hp: Value < Ptr < header > > = Rc :: new ( RefCell :: new ( ( h. as_pointer ( ) ) ) ) ;
7575 let v: Value < Ptr < view > > = Rc :: new ( RefCell :: new ( ( * hp. borrow ( ) ) . reinterpret_cast :: < view > ( ) ) ) ;
7676 assert ! ( ( ( ( ( * ( * ( * v. borrow( ) ) . upgrade( ) . deref( ) ) . tag. borrow( ) ) == 7 ) as i32 ) != 0 ) ) ;
77+ let data: Value < Box < [ u8 ] > > = Rc :: new ( RefCell :: new ( Box :: from ( * b"hi\0 " ) ) ) ;
78+ let vp: Value < AnyPtr > = Rc :: new ( RefCell :: new (
79+ ( ( data. as_pointer ( ) as Ptr < u8 > ) as Ptr < u8 > ) . to_any ( ) ,
80+ ) ) ;
81+ let n: Value < i32 > = Rc :: new ( RefCell :: new ( 2 ) ) ;
82+ let sel: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new (
83+ if ( ( ( ( * n. borrow ( ) ) < 100 ) as i32 ) != 0 ) {
84+ ( * vp. borrow ( ) ) . clone ( )
85+ } else {
86+ ( AnyPtr :: default ( ) )
87+ }
88+ . reinterpret_cast :: < u8 > ( ) ,
89+ ) ) ;
90+ assert ! ( ( ( ( !( ( * sel. borrow( ) ) . is_null( ) ) ) as i32 ) != 0 ) ) ;
91+ assert ! (
92+ ( ( ( ( ( ( * sel. borrow( ) ) . offset( ( 0 ) as isize ) . read( ) ) as i32 ) == ( 'h' as i32 ) ) as i32 ) != 0 )
93+ ) ;
94+ ( * n. borrow_mut ( ) ) = 200 ;
95+ ( * sel. borrow_mut ( ) ) = if ( ( ( ( * n. borrow ( ) ) < 100 ) as i32 ) != 0 ) {
96+ ( * vp. borrow ( ) ) . clone ( )
97+ } else {
98+ ( AnyPtr :: default ( ) )
99+ }
100+ . reinterpret_cast :: < u8 > ( ) ;
101+ assert ! ( ( ( ( ( * sel. borrow( ) ) . is_null( ) ) as i32 ) != 0 ) ) ;
77102 return 0 ;
78103}
Original file line number Diff line number Diff line change @@ -32,5 +32,23 @@ unsafe fn main_0() -> i32 {
3232 let mut hp: * mut header = ( & mut h as * mut header ) ;
3333 let mut v: * mut view = ( hp as * mut view ) ;
3434 assert ! ( ( ( ( ( ( * v) . tag) == ( 7 ) ) as i32 ) != 0 ) ) ;
35+ let mut data: [ libc:: c_char ; 3 ] = std:: mem:: transmute ( * b"hi\0 " ) ;
36+ let mut vp: * mut :: libc:: c_void =
37+ ( data. as_mut_ptr ( ) as * mut libc:: c_char as * mut :: libc:: c_void ) ;
38+ let mut n: i32 = 2 ;
39+ let mut sel: * mut libc:: c_char = ( if ( ( ( ( n) < ( 100 ) ) as i32 ) != 0 ) {
40+ vp
41+ } else {
42+ ( 0 as * mut :: libc:: c_void )
43+ } as * mut libc:: c_char ) ;
44+ assert ! ( ( ( ( !( ( sel) . is_null( ) ) ) as i32 ) != 0 ) ) ;
45+ assert ! ( ( ( ( ( ( * sel. offset( ( 0 ) as isize ) ) as i32 ) == ( 'h' as i32 ) ) as i32 ) != 0 ) ) ;
46+ n = 200 ;
47+ sel = ( if ( ( ( ( n) < ( 100 ) ) as i32 ) != 0 ) {
48+ vp
49+ } else {
50+ ( 0 as * mut :: libc:: c_void )
51+ } as * mut libc:: c_char ) ;
52+ assert ! ( ( ( ( ( sel) . is_null( ) ) as i32 ) != 0 ) ) ;
3553 return 0 ;
3654}
Original file line number Diff line number Diff line change 11#include <assert.h>
2+ #include <stddef.h>
23
34struct header {
45 int tag ;
@@ -20,5 +21,15 @@ int main(void) {
2021 struct header * hp = & h ;
2122 struct view * v = (struct view * )hp ;
2223 assert (v -> tag == 7 );
24+
25+ char data [] = "hi" ;
26+ void * vp = data ;
27+ int n = 2 ;
28+ char * sel = (n < 100 ) ? vp : NULL ;
29+ assert (sel != 0 );
30+ assert (sel [0 ] == 'h' );
31+ n = 200 ;
32+ sel = (n < 100 ) ? vp : NULL ;
33+ assert (sel == 0 );
2334 return 0 ;
2435}
You can’t perform that action at this time.
0 commit comments