Skip to content

Commit a897864

Browse files
Ayush1325antoyo
authored andcommitted
Add type_array to BaseTypeMethods
Moved type_array function to rustc_codegen_ssa::BaseTypeMethods trait. This allows using normal alloca function to create arrays as suggested in rust-lang/rust#104022. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
1 parent dd930a3 commit a897864

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

Diff for: src/type_.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,27 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
201201
fn val_ty(&self, value: RValue<'gcc>) -> Type<'gcc> {
202202
value.get_type()
203203
}
204+
205+
fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> {
206+
if let Some(struct_type) = ty.is_struct() {
207+
if struct_type.get_field_count() == 0 {
208+
// NOTE: since gccjit only supports i32 for the array size and libcore's tests uses a
209+
// size of usize::MAX in test_binary_search, we workaround this by setting the size to
210+
// zero for ZSTs.
211+
// FIXME(antoyo): fix gccjit API.
212+
len = 0;
213+
}
214+
}
215+
216+
// NOTE: see note above. Some other test uses usize::MAX.
217+
if len == u64::MAX {
218+
len = 0;
219+
}
220+
221+
let len: i32 = len.try_into().expect("array len");
222+
223+
self.context.new_array_type(None, ty, len)
224+
}
204225
}
205226

206227
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -227,25 +248,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
227248
self.context.new_opaque_struct_type(None, name)
228249
}
229250

230-
pub fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> {
231-
if let Some(struct_type) = ty.is_struct() {
232-
if struct_type.get_field_count() == 0 {
233-
// NOTE: since gccjit only supports i32 for the array size and libcore's tests uses a
234-
// size of usize::MAX in test_binary_search, we workaround this by setting the size to
235-
// zero for ZSTs.
236-
// FIXME(antoyo): fix gccjit API.
237-
len = 0;
238-
}
239-
}
240-
241-
// NOTE: see note above. Some other test uses usize::MAX.
242-
if len == u64::MAX {
243-
len = 0;
244-
}
245-
246-
let len: i32 = len.try_into().expect("array len");
247-
248-
self.context.new_array_type(None, ty, len)
251+
pub fn type_bool(&self) -> Type<'gcc> {
252+
self.context.new_type::<bool>()
249253
}
250254
}
251255

0 commit comments

Comments
 (0)