File tree Expand file tree Collapse file tree
tests/multi-file/extern_functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ add_custom_target("check-unit"
129129 ${LIT_FLAGS}
130130 "${PROJECT_SOURCE_DIR} /tests/unit"
131131 "${PROJECT_SOURCE_DIR} /tests/ub"
132+ "${PROJECT_SOURCE_DIR} /tests/multi-file"
132133 DEPENDS cpp2rust libcc2rs
133134 USES_TERMINAL
134135 )
Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.16 )
2+ project (extern_functions LANGUAGES C )
3+ add_executable (app a.c b.c )
Original file line number Diff line number Diff line change 1+ #include <assert.h>
2+
3+ extern int helper (int x );
4+
5+ int main (void ) {
6+ assert (helper (42 ) == 43 );
7+ return 0 ;
8+ }
Original file line number Diff line number Diff line change 1+ static int unrelated1 (void ) { return 1 ; }
2+ static int unrelated2 (void ) { return 2 ; }
3+ static int unrelated3 (void ) { return 3 ; }
4+
5+ int helper (int x ) {
6+ (void )unrelated1 ();
7+ (void )unrelated2 ();
8+ (void )unrelated3 ();
9+ return x + 1 ;
10+ }
Original file line number Diff line number Diff line change 1+ extern crate libcc2rs;
2+ use libcc2rs:: * ;
3+ use std:: cell:: RefCell ;
4+ use std:: collections:: BTreeMap ;
5+ use std:: io:: prelude:: * ;
6+ use std:: io:: { Read , Seek , Write } ;
7+ use std:: os:: fd:: AsFd ;
8+ use std:: rc:: { Rc , Weak } ;
9+
10+ // a.rs
11+ pub fn main ( ) {
12+ std:: process:: exit ( main_0 ( ) ) ;
13+ }
14+ fn main_0 ( ) -> i32 {
15+ assert ! (
16+ ( ( ( ( {
17+ let _x: i32 = 42 ;
18+ helper_0( _x)
19+ } ) == 43 ) as i32 )
20+ != 0 )
21+ ) ;
22+ return 0 ;
23+ }
24+ // b.rs
25+ pub fn unrelated1_1 ( ) -> i32 {
26+ return 1 ;
27+ }
28+ pub fn unrelated2_2 ( ) -> i32 {
29+ return 2 ;
30+ }
31+ pub fn unrelated3_3 ( ) -> i32 {
32+ return 3 ;
33+ }
34+ pub fn helper_4 ( x : i32 ) -> i32 {
35+ let x: Value < i32 > = Rc :: new ( RefCell :: new ( x) ) ;
36+ ( { unrelated1_1 ( ) } ) ;
37+ ( { unrelated2_2 ( ) } ) ;
38+ ( { unrelated3_3 ( ) } ) ;
39+ return ( ( * x. borrow ( ) ) + 1 ) ;
40+ }
Original file line number Diff line number Diff line change 1+ extern crate libc;
2+ use libc:: * ;
3+ extern crate libcc2rs;
4+ use libcc2rs:: * ;
5+ use std:: collections:: BTreeMap ;
6+ use std:: io:: { Read , Seek , Write } ;
7+ use std:: os:: fd:: { AsFd , FromRawFd , IntoRawFd } ;
8+ use std:: rc:: Rc ;
9+
10+ // a.rs
11+ pub fn main ( ) {
12+ unsafe {
13+ std:: process:: exit ( main_0 ( ) as i32 ) ;
14+ }
15+ }
16+ unsafe fn main_0 ( ) -> i32 {
17+ assert ! (
18+ ( ( ( ( unsafe {
19+ let _x: i32 = 42 ;
20+ helper_0( _x)
21+ } ) == ( 43 ) ) as i32 )
22+ != 0 )
23+ ) ;
24+ return 0 ;
25+ }
26+ // b.rs
27+ pub unsafe fn unrelated1_1 ( ) -> i32 {
28+ return 1 ;
29+ }
30+ pub unsafe fn unrelated2_2 ( ) -> i32 {
31+ return 2 ;
32+ }
33+ pub unsafe fn unrelated3_3 ( ) -> i32 {
34+ return 3 ;
35+ }
36+ pub unsafe fn helper_4 ( mut x : i32 ) -> i32 {
37+ ( unsafe { unrelated1_1 ( ) } ) ;
38+ ( unsafe { unrelated2_2 ( ) } ) ;
39+ ( unsafe { unrelated3_3 ( ) } ) ;
40+ return ( ( x) + ( 1 ) ) ;
41+ }
Original file line number Diff line number Diff line change 1+ no-compile
You can’t perform that action at this time.
0 commit comments