Skip to content

Commit 5e9e74c

Browse files
committed
Fix global alignment
1 parent 6c0a0dd commit 5e9e74c

File tree

2 files changed

+17
-38
lines changed

2 files changed

+17
-38
lines changed

gcc-test-backend/src/main.rs

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
1-
#![feature(array_chunks, slice_as_chunks)]
1+
#![feature(is_sorted)]
22

33
fn main() {
4-
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5, 6];
5-
6-
const WINDOW_SIZE: usize = 3;
7-
8-
let mut i = 0;
9-
let len = v.len();
10-
while i < len {
11-
if i + WINDOW_SIZE >= len {
12-
break;
13-
}
14-
15-
//let slice: &mut [i32; WINDOW_SIZE] = TryFrom::try_from(&mut v[i..i+WINDOW_SIZE]).unwrap();
16-
let slice = &mut v[i..i+WINDOW_SIZE];
17-
let ptr = slice.as_mut_ptr() as *mut [i32; WINDOW_SIZE];
18-
let array: &mut [i32; WINDOW_SIZE] = unsafe { &mut *ptr };
19-
//println!("{:?}", array);
20-
21-
let sum = array.iter().sum::<i32>();
22-
*array = [sum; WINDOW_SIZE];
23-
24-
i += WINDOW_SIZE;
25-
}
26-
27-
//println!("{:?}", v);
28-
assert_eq!(v, &[3, 3, 3, 12, 12, 12, 6]);
29-
30-
/*for a in v.array_chunks_mut() {
31-
let sum = a.iter().sum::<i32>();
32-
*a = [sum; 3];
33-
}
34-
assert_eq!(v, &[3, 3, 3, 12, 12, 12, 6]);*/
35-
36-
/*let v2: &mut [i32] = &mut [0, 1, 2, 3, 4, 5, 6];
37-
v2.array_chunks_mut().for_each(|[a, b]| core::mem::swap(a, b));
38-
assert_eq!(v2, &[1, 0, 3, 2, 5, 4, 6]);*/
4+
let b: u16 = 42;
5+
assert_eq!(b, 42);
6+
let empty: [i32; 0] = [];
7+
8+
assert!([1, 2, 2, 9].is_sorted());
9+
assert!(![1, 3, 2].is_sorted());
10+
assert!([42].is_sorted());
11+
assert!(empty.is_sorted());
12+
assert!(![0.0, 1.0, f32::NAN].is_sorted());
13+
assert!([-2, -1, 0, 3].is_sorted());
14+
assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
15+
assert!(!["c", "bb", "aaa"].is_sorted());
16+
assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
3917
}

src/consts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
253253
let name = self.generate_local_symbol_name(kind);
254254
// TODO: check if it's okay that TLS is off here.
255255
// TODO: check if it's okay that link_section is None here.
256+
// TODO: set alignment here as well.
256257
let gv = self.define_global(&name[..], self.val_ty(cv), false, None).unwrap_or_else(|| {
257258
bug!("symbol `{}` is already defined", name);
258259
});
@@ -262,7 +263,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
262263
_ => {
263264
let index = self.global_gen_sym_counter.get();
264265
let name = format!("global_{}_{}", index, self.codegen_unit.name());
265-
let global = self.define_private_global(self.val_ty(cv));
266+
let typ = self.val_ty(cv).get_aligned(align.bytes());
267+
let global = self.define_private_global(typ);
266268
(name, global)
267269
},
268270
};
@@ -272,7 +274,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
272274
// to import it later.
273275
self.global_names.borrow_mut().insert(cv, name);
274276
self.global_init_block.add_assignment(None, gv.dereference(None), cv);
275-
//set_global_alignment(&self, gv, align);
276277
//llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
277278
gv
278279
}

0 commit comments

Comments
 (0)