Skip to content

Commit

Permalink
Add type_array to BaseTypeMethods
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Ayush1325 authored and antoyo committed Mar 1, 2023
1 parent dd930a3 commit a897864
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,27 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
fn val_ty(&self, value: RValue<'gcc>) -> Type<'gcc> {
value.get_type()
}

fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> {
if let Some(struct_type) = ty.is_struct() {
if struct_type.get_field_count() == 0 {
// NOTE: since gccjit only supports i32 for the array size and libcore's tests uses a
// size of usize::MAX in test_binary_search, we workaround this by setting the size to
// zero for ZSTs.
// FIXME(antoyo): fix gccjit API.
len = 0;
}
}

// NOTE: see note above. Some other test uses usize::MAX.
if len == u64::MAX {
len = 0;
}

let len: i32 = len.try_into().expect("array len");

self.context.new_array_type(None, ty, len)
}
}

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

pub fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> {
if let Some(struct_type) = ty.is_struct() {
if struct_type.get_field_count() == 0 {
// NOTE: since gccjit only supports i32 for the array size and libcore's tests uses a
// size of usize::MAX in test_binary_search, we workaround this by setting the size to
// zero for ZSTs.
// FIXME(antoyo): fix gccjit API.
len = 0;
}
}

// NOTE: see note above. Some other test uses usize::MAX.
if len == u64::MAX {
len = 0;
}

let len: i32 = len.try_into().expect("array len");

self.context.new_array_type(None, ty, len)
pub fn type_bool(&self) -> Type<'gcc> {
self.context.new_type::<bool>()
}
}

Expand Down

0 comments on commit a897864

Please sign in to comment.