|
1 |
| -extern crate inkwell; |
2 |
| - |
3 |
| -use self::inkwell::{AddressSpace, AtomicOrdering, AtomicRMWBinOp, OptimizationLevel}; |
4 |
| -use self::inkwell::context::Context; |
5 |
| -use self::inkwell::values::BasicValue; |
| 1 | +use inkwell::{AddressSpace, AtomicOrdering, AtomicRMWBinOp, OptimizationLevel}; |
| 2 | +use inkwell::context::Context; |
| 3 | +use inkwell::values::BasicValue; |
6 | 4 |
|
7 | 5 | // use std::ffi::CString;
|
8 | 6 | use std::ptr::null;
|
@@ -567,7 +565,7 @@ fn test_vector_binary_ops() {
|
567 | 565 | let p1_vec = fn_value.get_first_param().unwrap().into_vector_value();
|
568 | 566 | let p2_vec = fn_value.get_nth_param(1).unwrap().into_vector_value();
|
569 | 567 | let p3_vec = fn_value.get_nth_param(2).unwrap().into_vector_value();
|
570 |
| - let compared_vec = builder.build_float_compare(self::inkwell::FloatPredicate::OLT, p1_vec, p2_vec, "compared_vec"); |
| 568 | + let compared_vec = builder.build_float_compare(inkwell::FloatPredicate::OLT, p1_vec, p2_vec, "compared_vec"); |
571 | 569 | let multiplied_vec = builder.build_int_mul(compared_vec, p3_vec, "multiplied_vec");
|
572 | 570 | builder.build_return(Some(&multiplied_vec));
|
573 | 571 | assert!(fn_value.verify(true));
|
@@ -686,7 +684,7 @@ fn test_alignment_bytes() {
|
686 | 684 | }
|
687 | 685 |
|
688 | 686 | #[llvm_versions(8.0..=latest)]
|
689 |
| -fn run_memcpy_on<'ctx>(context: &'ctx Context, module: &self::inkwell::module::Module<'ctx>, alignment: u32) -> Result<(), &'static str> { |
| 687 | +fn run_memcpy_on<'ctx>(context: &'ctx Context, module: &inkwell::module::Module<'ctx>, alignment: u32) -> Result<(), &'static str> { |
690 | 688 | let i32_type = context.i32_type();
|
691 | 689 | let i64_type = context.i64_type();
|
692 | 690 | let array_len = 4;
|
@@ -750,7 +748,7 @@ fn test_memcpy() {
|
750 | 748 | }
|
751 | 749 |
|
752 | 750 | #[llvm_versions(8.0..=latest)]
|
753 |
| -fn run_memmove_on<'ctx>(context: &'ctx Context, module: &self::inkwell::module::Module<'ctx>, alignment: u32) -> Result<(), &'static str> { |
| 751 | +fn run_memmove_on<'ctx>(context: &'ctx Context, module: &inkwell::module::Module<'ctx>, alignment: u32) -> Result<(), &'static str> { |
754 | 752 | let i32_type = context.i32_type();
|
755 | 753 | let i64_type = context.i64_type();
|
756 | 754 | let array_len = 4;
|
@@ -984,3 +982,30 @@ fn test_cmpxchg() {
|
984 | 982 | let result = builder.build_cmpxchg(ptr_value, zero_value, neg_one_value, AtomicOrdering::Monotonic, AtomicOrdering::Monotonic);
|
985 | 983 | assert!(result.is_err());
|
986 | 984 | }
|
| 985 | + |
| 986 | +#[test] |
| 987 | +fn test_safe_struct_gep() { |
| 988 | + let context = Context::create(); |
| 989 | + let builder = context.create_builder(); |
| 990 | + let module = context.create_module("struct_gep"); |
| 991 | + let void_type = context.void_type(); |
| 992 | + let i32_ty = context.i32_type(); |
| 993 | + let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::Generic); |
| 994 | + let field_types = &[i32_ty.into(), i32_ty.into()]; |
| 995 | + let struct_ty = context.struct_type(field_types, false); |
| 996 | + let struct_ptr_ty = struct_ty.ptr_type(AddressSpace::Generic); |
| 997 | + let fn_type = void_type.fn_type(&[i32_ptr_ty.into(), struct_ptr_ty.into()], false); |
| 998 | + let fn_value = module.add_function("", fn_type, None); |
| 999 | + let entry = context.append_basic_block(fn_value, "entry"); |
| 1000 | + |
| 1001 | + builder.position_at_end(entry); |
| 1002 | + |
| 1003 | + let i32_ptr = fn_value.get_first_param().unwrap().into_pointer_value(); |
| 1004 | + let struct_ptr = fn_value.get_last_param().unwrap().into_pointer_value(); |
| 1005 | + |
| 1006 | + assert!(builder.build_struct_gep(i32_ptr, 0, "struct_gep").is_err()); |
| 1007 | + assert!(builder.build_struct_gep(i32_ptr, 10, "struct_gep").is_err()); |
| 1008 | + assert!(builder.build_struct_gep(struct_ptr, 0, "struct_gep").is_ok()); |
| 1009 | + assert!(builder.build_struct_gep(struct_ptr, 1, "struct_gep").is_ok()); |
| 1010 | + assert!(builder.build_struct_gep(struct_ptr, 2, "struct_gep").is_err()); |
| 1011 | +} |
0 commit comments