Skip to content

Fix global alignment #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 14 additions & 36 deletions gcc-test-backend/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
#![feature(array_chunks, slice_as_chunks)]
#![feature(is_sorted)]

fn main() {
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5, 6];

const WINDOW_SIZE: usize = 3;

let mut i = 0;
let len = v.len();
while i < len {
if i + WINDOW_SIZE >= len {
break;
}

//let slice: &mut [i32; WINDOW_SIZE] = TryFrom::try_from(&mut v[i..i+WINDOW_SIZE]).unwrap();
let slice = &mut v[i..i+WINDOW_SIZE];
let ptr = slice.as_mut_ptr() as *mut [i32; WINDOW_SIZE];
let array: &mut [i32; WINDOW_SIZE] = unsafe { &mut *ptr };
//println!("{:?}", array);

let sum = array.iter().sum::<i32>();
*array = [sum; WINDOW_SIZE];

i += WINDOW_SIZE;
}

//println!("{:?}", v);
assert_eq!(v, &[3, 3, 3, 12, 12, 12, 6]);

/*for a in v.array_chunks_mut() {
let sum = a.iter().sum::<i32>();
*a = [sum; 3];
}
assert_eq!(v, &[3, 3, 3, 12, 12, 12, 6]);*/

/*let v2: &mut [i32] = &mut [0, 1, 2, 3, 4, 5, 6];
v2.array_chunks_mut().for_each(|[a, b]| core::mem::swap(a, b));
assert_eq!(v2, &[1, 0, 3, 2, 5, 4, 6]);*/
let b: u16 = 42;
assert_eq!(b, 42);
let empty: [i32; 0] = [];

assert!([1, 2, 2, 9].is_sorted());
assert!(![1, 3, 2].is_sorted());
assert!([42].is_sorted());
assert!(empty.is_sorted());
assert!(![0.0, 1.0, f32::NAN].is_sorted());
assert!([-2, -1, 0, 3].is_sorted());
assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
assert!(!["c", "bb", "aaa"].is_sorted());
assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
}
5 changes: 3 additions & 2 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
let name = self.generate_local_symbol_name(kind);
// TODO: check if it's okay that TLS is off here.
// TODO: check if it's okay that link_section is None here.
// TODO: set alignment here as well.
let gv = self.define_global(&name[..], self.val_ty(cv), false, None).unwrap_or_else(|| {
bug!("symbol `{}` is already defined", name);
});
Expand All @@ -262,7 +263,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
_ => {
let index = self.global_gen_sym_counter.get();
let name = format!("global_{}_{}", index, self.codegen_unit.name());
let global = self.define_private_global(self.val_ty(cv));
let typ = self.val_ty(cv).get_aligned(align.bytes());
let global = self.define_private_global(typ);
(name, global)
},
};
Expand All @@ -272,7 +274,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
// to import it later.
self.global_names.borrow_mut().insert(cv, name);
self.global_init_block.add_assignment(None, gv.dereference(None), cv);
//set_global_alignment(&self, gv, align);
//llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
gv
}
Expand Down