Skip to content

Commit 239ba2c

Browse files
committed
Marked GEP functions as unsafe due to easy unsafe usage per rust-lang#33
1 parent 7bdd870 commit 239ba2c

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

.github/CODE_OF_CONDUCT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ The Inkwell team is committed to the following rules:
1212

1313
We expect others to follow these rules as well.
1414

15-
<small>This COC is based on [dpc's](https://github.com/dpc/public/blob/master/COC.md).</small>
15+
<sup><sub>This COC is based on [dpc's](https://github.com/dpc/public/blob/master/COC.md).</sup></sub>

src/builder.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ impl Builder {
9494
}
9595

9696
// REVIEW: Doesn't GEP work on array too?
97-
pub fn build_gep(&self, ptr: &PointerValue, ordered_indexes: &[IntValue], name: &str) -> PointerValue {
97+
/// GEP is very likely to segfault if indexes are used incorrectly, and is therefore an unsafe function. Maybe we can change this in the future.
98+
pub unsafe fn build_gep(&self, ptr: &PointerValue, ordered_indexes: &[IntValue], name: &str) -> PointerValue {
9899
let c_string = CString::new(name).expect("Conversion to CString failed unexpectedly");
99100

100101
let mut index_values: Vec<LLVMValueRef> = ordered_indexes.iter()
@@ -108,7 +109,8 @@ impl Builder {
108109
}
109110

110111
// REVIEW: Doesn't GEP work on array too?
111-
pub fn build_in_bounds_gep(&self, ptr: &PointerValue, ordered_indexes: &[IntValue], name: &str) -> PointerValue {
112+
/// GEP is very likely to segfault if indexes are used incorrectly, and is therefore an unsafe function. Maybe we can change this in the future.
113+
pub unsafe fn build_in_bounds_gep(&self, ptr: &PointerValue, ordered_indexes: &[IntValue], name: &str) -> PointerValue {
112114
let c_string = CString::new(name).expect("Conversion to CString failed unexpectedly");
113115

114116
let mut index_values: Vec<LLVMValueRef> = ordered_indexes.iter()
@@ -122,7 +124,8 @@ impl Builder {
122124
}
123125

124126
// REVIEW: Shouldn't this take a StructValue? Or does it still need to be PointerValue<StructValue>?
125-
pub fn build_struct_gep(&self, ptr: &PointerValue, index: u32, name: &str) -> PointerValue {
127+
/// GEP is very likely to segfault if indexes are used incorrectly, and is therefore an unsafe function. Maybe we can change this in the future.
128+
pub unsafe fn build_struct_gep(&self, ptr: &PointerValue, index: u32, name: &str) -> PointerValue {
126129
let c_string = CString::new(name).expect("Conversion to CString failed unexpectedly");
127130

128131
let value = unsafe {

src/execution_engine.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,7 @@ impl ExecutionEngine {
361361

362362
let environment_variables = vec![]; // TODO: Support envp. Likely needs to be null terminated
363363

364-
unsafe {
365-
LLVMRunFunctionAsMain(*self.execution_engine, function.as_value_ref(), raw_args.len() as u32, raw_args.as_ptr(), environment_variables.as_ptr()) // REVIEW: usize to u32 cast ok??
366-
}
364+
LLVMRunFunctionAsMain(*self.execution_engine, function.as_value_ref(), raw_args.len() as u32, raw_args.as_ptr(), environment_variables.as_ptr()) // REVIEW: usize to u32 cast ok??
367365
}
368366

369367
pub fn free_fn_machine_code(&self, function: &FunctionValue) {

src/values/ptr_value.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ impl PointerValue {
6666
}
6767

6868
// REVIEW: Should this be on array value too?
69-
pub fn const_gep(&self, ordered_indexes: &[&IntValue]) -> PointerValue {
69+
/// GEP is very likely to segfault if indexes are used incorrectly, and is therefore an unsafe function. Maybe we can change this in the future.
70+
pub unsafe fn const_gep(&self, ordered_indexes: &[IntValue]) -> PointerValue {
7071
let mut index_values: Vec<LLVMValueRef> = ordered_indexes.iter()
7172
.map(|val| val.as_value_ref())
7273
.collect();
@@ -77,7 +78,8 @@ impl PointerValue {
7778
PointerValue::new(value)
7879
}
7980

80-
pub fn const_in_bounds_gep(&self, ordered_indexes: &[&IntValue]) -> PointerValue {
81+
/// GEP is very likely to segfault if indexes are used incorrectly, and is therefore an unsafe function. Maybe we can change this in the future.
82+
pub unsafe fn const_in_bounds_gep(&self, ordered_indexes: &[IntValue]) -> PointerValue {
8183
let mut index_values: Vec<LLVMValueRef> = ordered_indexes.iter()
8284
.map(|val| val.as_value_ref())
8385
.collect();

0 commit comments

Comments
 (0)