Skip to content
Snippets Groups Projects
Commit 54e2dd55 authored by Per Lindgren's avatar Per Lindgren
Browse files

lib fix + examples

parent 9fd1a194
No related branches found
No related tags found
No related merge requests found
#![no_std]
#![feature(core_intrinsics)]
#[macro_use]
extern crate klee;
use core::ptr;
use core::intrinsics::unchecked_div;
fn main() {
let u = symbol!("u");
unsafe {
ptr::read_volatile(&f2(f1(u)));
}
}
// add 1 wrapping
fn f1(u: u8) -> u8 {
let mut j = 0;
for _i in 0..u {
j += 1;
}
j
}
fn f2(u: u8) -> u8 {
unsafe { unchecked_div(100, u) }
}
#![no_std]
#[macro_use]
extern crate klee;
use core::ptr;
fn main() {
let u = symbol!("u");
unsafe {
ptr::read_volatile(&f2(f1(u)));
}
}
// add 1 wrapping
fn f1(u: u8) -> u8 {
u + 1
}
fn f2(u: u8) -> u8 {
100 / u
}
#![no_std]
#[macro_use]
extern crate klee;
use core::ops::Add;
use core::ptr;
fn main() {
let u = symbol!("u");
unsafe {
ptr::read_volatile(&f2(f1(u)));
}
}
// add 1 saturating
fn f1(u: u8) -> u8 {
//if u < 255 { u + 1 } else { u }
u.checked_add(1).unwrap_or(u)
}
fn f2(u: u8) -> u8 {
100 / u
}
#![no_std]
#![feature(core_intrinsics)]
#[macro_use]
extern crate klee;
use core::ptr;
use core::intrinsics::unchecked_div;
fn main() {
let u = symbol!("u");
unsafe {
ptr::read_volatile(&f2(f1(u)));
}
}
// add 1 wrapping
fn f1(u: u8) -> u8 {
u.wrapping_add(1)
}
fn f2(u: u8) -> u8 {
unsafe { unchecked_div( 100, u) }
}
...@@ -13,7 +13,7 @@ fn main() { ...@@ -13,7 +13,7 @@ fn main() {
} }
} }
// add 1 and saturate // add 1 wrapping
fn f1(u: u8) -> u8 { fn f1(u: u8) -> u8 {
u.wrapping_add(1) u.wrapping_add(1)
} }
......
...@@ -9,11 +9,17 @@ mod ll; ...@@ -9,11 +9,17 @@ mod ll;
use core::mem; use core::mem;
use cty::c_void; use cty::{c_int, c_void};
#[doc(hidden)] #[doc(hidden)]
pub use cstr_core::CStr; pub use cstr_core::CStr;
//extern "C" fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int {
#[no_mangle]
pub fn memcmp(cx: *const c_void, ct: *const c_void, n: usize) -> c_int {
::abort();
}
pub fn abort() -> ! { pub fn abort() -> ! {
unsafe { ll::abort() } unsafe { ll::abort() }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment