Skip to content

Commit 5107457

Browse files
committed
Add basic function-shared-using-header test
1 parent bf0a412 commit 5107457

6 files changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(extern_functions LANGUAGES C)
3+
add_executable(app a.c b.c)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <assert.h>
2+
#include "header.h"
3+
4+
int main(void) {
5+
assert(helper(42) == 43);
6+
return 0;
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "header.h"
2+
3+
static int unrelated1(void) { return 1; }
4+
static int unrelated2(void) { return 2; }
5+
static int unrelated3(void) { return 3; }
6+
7+
int helper(int x) {
8+
(void)unrelated1();
9+
(void)unrelated2();
10+
(void)unrelated3();
11+
return x + 1;
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
int helper(int x);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_0(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+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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_0(mut x: i32) -> i32 {
37+
(unsafe { unrelated1_1() });
38+
(unsafe { unrelated2_2() });
39+
(unsafe { unrelated3_3() });
40+
return ((x) + (1));
41+
}

0 commit comments

Comments
 (0)