-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support atomicrmw instructions (with LLVM 10)
Fixes #12.
- Loading branch information
1 parent
47f4f67
commit c5f372f
Showing
6 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
source_filename = "<no source file>" | ||
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-apple-macosx10.15.0" | ||
|
||
define i32 @atomicrmwops(i32, i32) local_unnamed_addr { | ||
%addr = alloca i32, align 4 | ||
|
||
; initial value at %addr is %0 | ||
store i32 %0, i32* %addr, align 4 | ||
|
||
%3 = atomicrmw xchg i32* %addr, i32 %1 monotonic | ||
; now %3 is %0 and the value is %1 | ||
|
||
%4 = atomicrmw add i32* %addr, i32 %3 acquire | ||
; now %4 is %1 and the value is %1 + %3 (so, %1 + %0) | ||
|
||
%5 = atomicrmw sub i32* %addr, i32 %1 release | ||
; now %5 is %1 + %0 and the value is %0 | ||
|
||
%6 = atomicrmw and i32* %addr, i32 %4 acq_rel | ||
; now %6 is %0 and the value is %0 & %1 | ||
|
||
%7 = atomicrmw xor i32* %addr, i32 3 seq_cst | ||
; now %7 is %0 & %1 and the value is (%0 & %1) ^ 3 | ||
|
||
%8 = atomicrmw umax i32* %addr, i32 %0 monotonic | ||
; now %8 is (%0 & %1) ^ 3 and the value is umax(%8, %0) | ||
|
||
%9 = load i32, i32* %addr, align 4 | ||
|
||
ret i32 %9 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#![cfg(not(feature = "llvm-9"))] // With LLVM 9 and earlier, Haybale doesn't support AtomicRMW | ||
|
||
use haybale::backend::DefaultBackend; | ||
use haybale::solver_utils::PossibleSolutions; | ||
use haybale::*; | ||
use llvm_ir::Name; | ||
|
||
fn init_logging() { | ||
// capture log messages with test harness | ||
let _ = env_logger::builder().is_test(true).try_init(); | ||
} | ||
|
||
fn get_project() -> Project { | ||
let modname = "tests/bcfiles/atomicrmw.bc"; | ||
Project::from_bc_path(modname) | ||
.unwrap_or_else(|e| panic!("Failed to parse module {:?}: {}", modname, e)) | ||
} | ||
|
||
#[test] | ||
fn atomicrmw() { | ||
init_logging(); | ||
let proj = get_project(); | ||
let funcname: String = "atomicrmwops".into(); | ||
let ret = get_possible_return_values_of_func( | ||
&funcname, | ||
&proj, | ||
Config::default(), | ||
Some(vec![ | ||
ParameterVal::ExactValue(0xFF00), | ||
ParameterVal::ExactValue(0x00FF), | ||
]), | ||
None, | ||
10, | ||
); | ||
assert_eq!( | ||
ret, | ||
PossibleSolutions::exactly_one(ReturnValue::Return(0xFF00)) | ||
); | ||
|
||
let mut em = symex_function( | ||
&funcname, | ||
&proj, | ||
Config::<DefaultBackend>::default(), | ||
Some(vec![ | ||
ParameterVal::ExactValue(0xFF00), | ||
ParameterVal::Range(1, 3), | ||
]), | ||
).unwrap(); | ||
let _ = em | ||
.next() | ||
.unwrap() | ||
.map_err(|e| em.state().full_error_message_with_context(e)) | ||
.unwrap(); | ||
let var0 = em.state().get_bv_by_irname(&funcname, &Name::from(0)); | ||
let var1 = em.state().get_bv_by_irname(&funcname, &Name::from(1)); | ||
let var3 = em.state().get_bv_by_irname(&funcname, &Name::from(3)); | ||
let var4 = em.state().get_bv_by_irname(&funcname, &Name::from(4)); | ||
let var5 = em.state().get_bv_by_irname(&funcname, &Name::from(5)); | ||
let var6 = em.state().get_bv_by_irname(&funcname, &Name::from(6)); | ||
let var7 = em.state().get_bv_by_irname(&funcname, &Name::from(7)); | ||
let var8 = em.state().get_bv_by_irname(&funcname, &Name::from(8)); | ||
assert!(em.state().bvs_must_be_equal(var3, var0).unwrap()); | ||
assert!(em.state().bvs_must_be_equal(var4, var1).unwrap()); | ||
assert!(em.state().bvs_must_be_equal(var5, &var0.add(var1)).unwrap()); | ||
assert!(em.state().bvs_must_be_equal(var6, var0).unwrap()); | ||
assert!(em.state().bvs_must_be_equal(var7, &em.state().zero(var7.get_width())).unwrap()); // given the values we provided for %0 and %1, %7 must always be 0 | ||
let sol8 = em.state().get_possible_solutions_for_bv(var8, 6).unwrap().as_u64_solutions().unwrap(); | ||
assert_eq!(sol8, PossibleSolutions::exactly_one(3)); | ||
} |