|
1 |
| -use inkwell::{AddressSpace, AtomicOrdering, IntPredicate, FloatPredicate}; |
2 | 1 | use inkwell::context::Context;
|
3 | 2 | use inkwell::values::{BasicValue, InstructionOpcode::*};
|
| 3 | +use inkwell::{AddressSpace, AtomicOrdering, AtomicRMWBinOp, FloatPredicate, IntPredicate}; |
4 | 4 |
|
5 | 5 | #[test]
|
6 | 6 | fn test_operands() {
|
@@ -249,6 +249,60 @@ fn test_instructions() {
|
249 | 249 | assert_eq!(instruction_clone, instruction_clone_copy);
|
250 | 250 | }
|
251 | 251 |
|
| 252 | +#[llvm_versions(10.0..=latest)] |
| 253 | +#[test] |
| 254 | +fn test_volatile_atomicrmw_cmpxchg() { |
| 255 | + let context = Context::create(); |
| 256 | + let module = context.create_module("testing"); |
| 257 | + let builder = context.create_builder(); |
| 258 | + |
| 259 | + let void_type = context.void_type(); |
| 260 | + let i32_type = context.i32_type(); |
| 261 | + let i32_ptr_type = i32_type.ptr_type(AddressSpace::Generic); |
| 262 | + let fn_type = void_type.fn_type(&[i32_ptr_type.into(), i32_type.into()], false); |
| 263 | + |
| 264 | + let function = module.add_function("mem_inst", fn_type, None); |
| 265 | + let basic_block = context.append_basic_block(function, "entry"); |
| 266 | + |
| 267 | + builder.position_at_end(basic_block); |
| 268 | + |
| 269 | + let arg1 = function.get_first_param().unwrap().into_pointer_value(); |
| 270 | + let arg2 = function.get_nth_param(1).unwrap().into_int_value(); |
| 271 | + |
| 272 | + assert!(arg1.get_first_use().is_none()); |
| 273 | + assert!(arg2.get_first_use().is_none()); |
| 274 | + |
| 275 | + let i32_val = i32_type.const_int(7, false); |
| 276 | + |
| 277 | + let atomicrmw = builder |
| 278 | + .build_atomicrmw(AtomicRMWBinOp::Add, arg1, arg2, AtomicOrdering::Unordered) |
| 279 | + .unwrap() |
| 280 | + .as_instruction_value() |
| 281 | + .unwrap(); |
| 282 | + let cmpxchg = builder |
| 283 | + .build_cmpxchg( |
| 284 | + arg1, |
| 285 | + arg2, |
| 286 | + i32_val, |
| 287 | + AtomicOrdering::Monotonic, |
| 288 | + AtomicOrdering::Monotonic, |
| 289 | + ) |
| 290 | + .unwrap() |
| 291 | + .as_instruction_value() |
| 292 | + .unwrap(); |
| 293 | + |
| 294 | + assert_eq!(atomicrmw.get_volatile().unwrap(), false); |
| 295 | + assert_eq!(cmpxchg.get_volatile().unwrap(), false); |
| 296 | + atomicrmw.set_volatile(true).unwrap(); |
| 297 | + cmpxchg.set_volatile(true).unwrap(); |
| 298 | + assert_eq!(atomicrmw.get_volatile().unwrap(), true); |
| 299 | + assert_eq!(cmpxchg.get_volatile().unwrap(), true); |
| 300 | + atomicrmw.set_volatile(false).unwrap(); |
| 301 | + cmpxchg.set_volatile(false).unwrap(); |
| 302 | + assert_eq!(atomicrmw.get_volatile().unwrap(), false); |
| 303 | + assert_eq!(cmpxchg.get_volatile().unwrap(), false); |
| 304 | +} |
| 305 | + |
252 | 306 | #[test]
|
253 | 307 | fn test_mem_instructions() {
|
254 | 308 | let context = Context::create();
|
|
0 commit comments