Skip to content

Commit 0af7642

Browse files
authored
Merge pull request rust-lang#96 from wasmerio/debug
fix misuse of LLVM API found through inkwell tests
2 parents 89507bd + 1dd910f commit 0af7642

16 files changed

+50
-325
lines changed

src/builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,14 +834,14 @@ impl Builder {
834834
/// #![allow(overflowing_literals)]
835835
///
836836
/// // Logical Right Shift
837-
/// assert_eq!(0b1100_0000 >> 2, 0b0011_0000);
838-
/// assert_eq!(0b0000_0010 >> 1, 0b0000_0001);
839-
/// assert_eq!(0b0000_1100 >> 2, 0b0000_0011);
837+
/// assert_eq!(0b1100_0000u8 >> 2, 0b0011_0000);
838+
/// assert_eq!(0b0000_0010u8 >> 1, 0b0000_0001);
839+
/// assert_eq!(0b0000_1100u8 >> 2, 0b0000_0011);
840840
///
841841
/// // Sign Extended Right Shift
842842
/// assert_eq!(0b0100_0000i8 >> 2, 0b0001_0000);
843-
/// assert_eq!(0b1110_0000i8 >> 1, 0b1111_0000);
844-
/// assert_eq!(0b1100_0000i8 >> 2, 0b1111_0000);
843+
/// assert_eq!(0b1110_0000u8 as i8 >> 1, 0b1111_0000u8 as i8);
844+
/// assert_eq!(0b1100_0000u8 as i8 >> 2, 0b1111_0000u8 as i8);
845845
/// ```
846846
///
847847
/// In Rust, functions that could do this for 8bit values look like:

src/types/array_type.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -174,34 +174,6 @@ impl ArrayType {
174174
ArrayValue::new(value)
175175
}
176176

177-
/// Creates a null `ArrayValue` of this `ArrayType`.
178-
/// It will be automatically assigned this `ArrayType`'s `Context`.
179-
///
180-
/// # Example
181-
/// ```
182-
/// use inkwell::context::Context;
183-
/// use inkwell::types::FloatType;
184-
/// use inkwell::AddressSpace;
185-
///
186-
/// // Global Context
187-
/// let f32_type = FloatType::f32_type();
188-
/// let f32_array_type = f32_type.array_type(7);
189-
/// let f32_array_null = f32_array_type.const_null();
190-
///
191-
/// assert!(f32_array_null.is_null());
192-
///
193-
/// // Custom Context
194-
/// let context = Context::create();
195-
/// let f32_type = context.f32_type();
196-
/// let f32_array_type = f32_type.array_type(7);
197-
/// let f32_array_null = f32_array_type.const_null();
198-
///
199-
/// assert!(f32_array_null.is_null());
200-
/// ```
201-
pub fn const_null(&self) -> ArrayValue {
202-
ArrayValue::new(self.array_type.const_null())
203-
}
204-
205177
/// Creates a constant zero value of this `ArrayType`.
206178
///
207179
/// # Example

src/types/float_type.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,27 +138,6 @@ impl FloatType {
138138
FloatValue::new(value)
139139
}
140140

141-
/// Creates a constant null value of this `FloatType`.
142-
/// It will be automatically assigned this `FloatType`'s `Context`.
143-
///
144-
/// # Example
145-
/// ```
146-
/// use inkwell::context::Context;
147-
/// use inkwell::types::FloatType;
148-
///
149-
/// // Global Context
150-
/// let f32_type = FloatType::f32_type();
151-
/// let f32_value = f32_type.const_null();
152-
///
153-
/// // Custom Context
154-
/// let context = Context::create();
155-
/// let f32_type = context.f32_type();
156-
/// let f32_value = f32_type.const_null();
157-
/// ```
158-
pub fn const_null(&self) -> FloatValue {
159-
FloatValue::new(self.float_type.const_null())
160-
}
161-
162141
/// Creates a constant zero value of this `FloatType`.
163142
///
164143
/// # Example
@@ -170,7 +149,7 @@ impl FloatType {
170149
/// let f32_type = context.f32_type();
171150
/// let f32_zero = f32_type.const_zero();
172151
///
173-
/// assert_eq!(f32_zero.print_to_string().to_string(), "f32 0");
152+
/// assert_eq!(f32_zero.print_to_string().to_string(), "float 0.000000e+00");
174153
/// ```
175154
pub fn const_zero(&self) -> FloatValue {
176155
FloatValue::new(self.float_type.const_zero())

src/types/int_type.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,26 +280,6 @@ impl IntType {
280280
IntValue::new(value)
281281
}
282282

283-
/// Creates a constant null value of this `IntType`.
284-
///
285-
/// # Example
286-
/// ```
287-
/// use inkwell::context::Context;
288-
/// use inkwell::types::IntType;
289-
///
290-
/// // Global Context
291-
/// let i32_type = IntType::i32_type();
292-
/// let i32_value = i32_type.const_null();
293-
///
294-
/// // Custom Context
295-
/// let context = Context::create();
296-
/// let i32_type = context.i32_type();
297-
/// let i32_value = i32_type.const_null();
298-
/// ```
299-
pub fn const_null(&self) -> IntValue {
300-
IntValue::new(self.int_type.const_null())
301-
}
302-
303283
/// Creates a constant zero value of this `IntType`.
304284
///
305285
/// # Example

src/types/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ impl Type {
7272
}
7373
}
7474

75-
// Even though the LLVM fuction has the word "Pointer", it doesn't seem to create
76-
// a pointer at all, just a null value of the current type...
77-
fn const_null(&self) -> LLVMValueRef {
78-
unsafe {
79-
LLVMConstPointerNull(self.type_)
80-
}
81-
}
82-
8375
fn const_zero(&self) -> LLVMValueRef {
8476
unsafe {
8577
LLVMConstNull(self.type_)

src/types/ptr_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl PointerType {
208208
/// assert!(f32_ptr_null.is_null());
209209
/// ```
210210
pub fn const_null(&self) -> PointerValue {
211-
PointerValue::new(self.ptr_type.const_null())
211+
PointerValue::new(self.ptr_type.const_zero())
212212
}
213213

214214
// REVIEW: Unlike the other const_zero functions, this one becomes null instead of a 0 value. Maybe remove?

src/types/struct_type.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -110,33 +110,6 @@ impl StructType {
110110
StructValue::new(value)
111111
}
112112

113-
/// Creates a null `StructValue` of this `StructType`.
114-
/// It will be automatically assigned this `StructType`'s `Context`.
115-
///
116-
/// # Example
117-
/// ```
118-
/// use inkwell::context::Context;
119-
/// use inkwell::types::{FloatType, StructType};
120-
///
121-
/// // Global Context
122-
/// let f32_type = FloatType::f32_type();
123-
/// let struct_type = StructType::struct_type(&[f32_type.into(), f32_type.into()], false);
124-
/// let struct_null = struct_type.const_null();
125-
///
126-
/// assert!(struct_null.is_null());
127-
///
128-
/// // Custom Context
129-
/// let context = Context::create();
130-
/// let f32_type = context.f32_type();
131-
/// let struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
132-
/// let struct_null = struct_type.const_null();
133-
///
134-
/// assert!(struct_null.is_null());
135-
/// ```
136-
pub fn const_null(&self) -> StructValue {
137-
StructValue::new(self.struct_type.const_null())
138-
}
139-
140113
/// Creates a constant zero value of this `StructType`.
141114
///
142115
/// # Example
@@ -486,25 +459,6 @@ impl StructType {
486459
is_opaque
487460
}
488461

489-
/// Creates a `VectorType` with this `StructType` for its element type.
490-
///
491-
/// # Example
492-
///
493-
/// ```no_run
494-
/// use inkwell::context::Context;
495-
///
496-
/// let context = Context::create();
497-
/// let f32_type = context.f32_type();
498-
/// let struct_type = context.struct_type(&[f32_type.into(), f32_type.into()], false);
499-
/// let struct_vec_type = struct_type.vec_type(3);
500-
///
501-
/// assert_eq!(struct_vec_type.get_size(), 3);
502-
/// assert_eq!(struct_vec_type.get_element_type().into_struct_type(), struct_type);
503-
/// ```
504-
pub fn vec_type(&self, size: u32) -> VectorType {
505-
self.struct_type.vec_type(size)
506-
}
507-
508462
/// Creates a constant `ArrayValue`.
509463
///
510464
/// # Example

src/types/vec_type.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -133,33 +133,6 @@ impl VectorType {
133133
VectorValue::new(vec_value)
134134
}
135135

136-
/// Creates a null `VectorValue` of this `VectorType`.
137-
/// It will be automatically assigned this `VectorType`'s `Context`.
138-
///
139-
/// # Example
140-
/// ```
141-
/// use inkwell::context::Context;
142-
/// use inkwell::types::FloatType;
143-
///
144-
/// // Global Context
145-
/// let f32_type = FloatType::f32_type();
146-
/// let f32_vec_type = f32_type.vec_type(7);
147-
/// let f32_vec_null = f32_vec_type.const_null();
148-
///
149-
/// assert!(f32_vec_null.is_null());
150-
///
151-
/// // Custom Context
152-
/// let context = Context::create();
153-
/// let f32_type = context.f32_type();
154-
/// let f32_vec_type = f32_type.vec_type(7);
155-
/// let f32_vec_null = f32_vec_type.const_null();
156-
///
157-
/// assert!(f32_vec_null.is_null());
158-
/// ```
159-
pub fn const_null(&self) -> VectorValue {
160-
VectorValue::new(self.vec_type.const_null())
161-
}
162-
163136
/// Creates a constant zero value of this `VectorType`.
164137
///
165138
/// # Example
@@ -226,25 +199,6 @@ impl VectorType {
226199

227200
}
228201

229-
/// Creates a `VectorType` with this `VectorType` for its element type.
230-
///
231-
/// # Example
232-
///
233-
/// ```no_run
234-
/// use inkwell::context::Context;
235-
///
236-
/// let context = Context::create();
237-
/// let f32_type = context.f32_type();
238-
/// let f32_vector_type = f32_type.vec_type(3);
239-
/// let f32_vector_vector_type = f32_vector_type.vec_type(3);
240-
///
241-
/// assert_eq!(f32_vector_vector_type.get_size(), 3);
242-
/// assert_eq!(f32_vector_vector_type.get_element_type().into_vector_type(), f32_vector_type);
243-
/// ```
244-
pub fn vec_type(&self, size: u32) -> VectorType {
245-
self.vec_type.vec_type(size)
246-
}
247-
248202
/// Creates a `PointerType` with this `VectorType` for its element type.
249203
///
250204
/// # Example

src/types/void_type.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::support::LLVMString;
77
use crate::types::traits::AsTypeRef;
88
use crate::types::{Type, BasicTypeEnum, FunctionType, PointerType};
99

10-
/// A `VoidType` is a special type with no possible direct instances. It's particularly
11-
/// useful as a pointer element type or a function return type.
10+
/// A `VoidType` is a special type with no possible direct instances. It's only
11+
/// useful as a function return type.
1212
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
1313
pub struct VoidType {
1414
void_type: Type,
@@ -24,7 +24,7 @@ impl VoidType {
2424
}
2525

2626
// REVIEW: Always false -> const fn?
27-
/// Gets whether or not this `VectorType` is sized or not. This may always
27+
/// Gets whether or not this `VoidType` is sized or not. This may always
2828
/// be false and as such this function may be removed in the future.
2929
///
3030
/// # Example
@@ -57,24 +57,6 @@ impl VoidType {
5757
self.void_type.get_context()
5858
}
5959

60-
/// Creates a `PointerType` with this `VoidType` for its element type.
61-
///
62-
/// # Example
63-
///
64-
/// ```no_run
65-
/// use inkwell::context::Context;
66-
/// use inkwell::AddressSpace;
67-
///
68-
/// let context = Context::create();
69-
/// let void_type = context.void_type();
70-
/// let void_ptr_type = void_type.ptr_type(AddressSpace::Generic);
71-
///
72-
/// assert_eq!(void_ptr_type.get_element_type().into_void_type(), void_type);
73-
/// ```
74-
pub fn ptr_type(&self, address_space: AddressSpace) -> PointerType {
75-
self.void_type.ptr_type(address_space)
76-
}
77-
7860
/// Creates a `FunctionType` with this `VoidType` for its return type.
7961
/// This means the function does not return.
8062
///

src/values/int_value.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ impl IntValue {
420420
if !self.is_const() {
421421
return None;
422422
}
423+
if self.get_type().get_bit_width() > 64 {
424+
return None;
425+
}
423426

424427
unsafe {
425428
Some(LLVMConstIntGetZExtValue(self.as_value_ref()))
@@ -444,6 +447,9 @@ impl IntValue {
444447
if !self.is_const() {
445448
return None;
446449
}
450+
if self.get_type().get_bit_width() > 64 {
451+
return None;
452+
}
447453

448454
unsafe {
449455
Some(LLVMConstIntGetSExtValue(self.as_value_ref()))

src/values/ptr_value.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ impl PointerValue {
5151
///
5252
/// let context = Context::create();
5353
/// let void_type = context.void_type();
54-
/// let void_ptr_null = void_type.ptr_type(AddressSpace::Generic).const_null();
55-
///
56-
/// assert!(void_ptr_null.is_const());
5754
/// ```
5855
pub fn is_const(&self) -> bool {
5956
self.ptr_value.is_const()

src/values/vec_value.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ impl VectorValue {
3232
/// let context = Context::create();
3333
/// let i8_type = context.i8_type();
3434
/// let i8_vec_type = i8_type.vec_type(3);
35-
/// let i8_vec_null = i8_vec_type.const_null();
35+
/// let i8_vec_zero = i8_vec_type.const_zero();
3636
///
37-
/// assert!(i8_vec_null.is_const());
37+
/// assert!(i8_vec_zero.is_const());
3838
/// ```
3939
pub fn is_const(&self) -> bool {
4040
self.vec_value.is_const()

0 commit comments

Comments
 (0)