Commit d094ae55 authored by Per Lindgren's avatar Per Lindgren

rust example test1, test2

parent d5870ac1
......@@ -27,6 +27,30 @@
"isDefault": true
}
},
{
"label": "cargo test2",
"type": "shell",
"command": "cargo rustc --release --example test2 -- -C linker=true --emit=llvm-ir,llvm-bc",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "cargo test3",
"type": "shell",
"command": "cargo rustc --release --example test3 -- -C linker=true --emit=llvm-ir,llvm-bc",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "cargo",
"label": "cargo clean",
......
......@@ -14,6 +14,13 @@ impl C {
ptr::read_volatile(&0);
}
}
#[inline(never)]
fn call_self(&mut self) {
unsafe {
ptr::read_volatile(&0);
}
}
}
#[inline(never)]
......@@ -25,7 +32,9 @@ fn f1() -> u32 {
#[no_mangle]
fn main() {
f1();
let mut c = C {};
c.call_self();
}
// cargo rustc --release -- -C linker=true --emit=llvm-ir,llvm-bc
// opt -load build/callgirl/libCallgirlPass.so -print-callgirl rust/target/release/deps/rust-*.ll -o dummy.ll
// opt -load ../build/callgirl/libCallgirlPass.so -print-callgirl target/release/examples/test1-*.ll > /dev/null
#![no_std]
#![no_main]
extern crate panic_abort;
use core::ptr;
trait Call {
fn call(&mut self);
}
struct C1 {}
struct C2 {}
impl Call for C1 {
#[inline(never)]
fn call(&mut self) {
unsafe {
ptr::read_volatile(&0);
}
}
}
impl Call for C2 {
#[inline(never)]
fn call(&mut self) {
unsafe {
ptr::read_volatile(&1);
}
}
}
#[inline(never)]
fn dispatch<T>(c: &mut T)
where
T: Call + ?Sized,
{
c.call()
}
#[no_mangle]
fn main() {
let mut c1 = C1 {};
let mut c2 = C2 {};
dispatch(&mut c1);
dispatch(&mut c2);
}
// opt -load ../build/callgirl/libCallgirlPass.so -print-callgirl target/release/examples/test2-*.ll > /dev/null
#![no_std]
#![no_main]
extern crate panic_abort;
use core::ptr;
trait Call {
fn call(&self);
}
struct C1 {}
struct C2 {
x: u32,
}
impl Call for C1 {
#[inline(never)]
fn call(&self) {
unsafe {
ptr::read_volatile(&0);
}
}
}
impl Call for C2 {
#[inline(never)]
fn call(&self) {
unsafe {
ptr::read_volatile(&self.x);
}
}
}
#[inline(never)]
fn dispatch<T>(c: &T)
where
T: Call + ?Sized,
{
c.call()
}
static mut C: &Call = &C1 {};
pub fn set_c() {
unsafe {
C = &C2 { x: 1 };
}
}
#[no_mangle]
fn main() {
unsafe {
dispatch(C);
set_c();
dispatch(C);
}
}
// opt -load ../build/callgirl/libCallgirlPass.so -print-callgirl target/release/examples/test2-*.ll > /dev/null
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment