Skip to content

Commit 5dc660b

Browse files
authored
Support upgrading the alignment of a global variable (rust-lang#121)
* Renable failing test * Update to newest gccjit.rs
1 parent fc23678 commit 5dc660b

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

patches/0023-core-Ignore-failing-tests.patch

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,4 @@ index 4bc44e9..8e3c7a4 100644
4646

4747
#[test]
4848
fn cell_allows_array_cycle() {
49-
diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
50-
index 3e00e0a..8e5663b 100644
51-
--- a/library/core/tests/slice.rs
52-
+++ b/library/core/tests/slice.rs
53-
@@ -2108,6 +2108,7 @@ fn test_copy_within_panics_src_out_of_bounds() {
54-
bytes.copy_within(usize::MAX..=usize::MAX, 0);
55-
}
56-
57-
+/*
58-
#[test]
59-
fn test_is_sorted() {
60-
let empty: [i32; 0] = [];
61-
@@ -2122,6 +2123,7 @@ fn test_is_sorted() {
62-
assert!(!["c", "bb", "aaa"].is_sorted());
63-
assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
64-
}
65-
+*/
66-
67-
#[test]
68-
fn test_slice_run_destructors() {
6949
-- 2.21.0 (Apple Git-122)

src/consts.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
3535
// following:
3636
for (value, variable) in &*self.const_globals.borrow() {
3737
if format!("{:?}", value) == format!("{:?}", cv) {
38-
// TODO(antoyo): upgrade alignment.
38+
if let Some(global_variable) = self.global_lvalues.borrow().get(variable) {
39+
let alignment = align.bits() as i32;
40+
if alignment > global_variable.get_alignment() {
41+
global_variable.set_alignment(alignment);
42+
}
43+
}
3944
return *variable;
4045
}
4146
}
@@ -182,7 +187,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
182187
// globally.
183188
global.global_set_initializer_rvalue(cv);
184189
// TODO(antoyo): set unnamed address.
185-
global.get_address(None)
190+
let rvalue = global.get_address(None);
191+
self.global_lvalues.borrow_mut().insert(rvalue, global);
192+
rvalue
186193
}
187194

188195
pub fn get_static(&self, def_id: DefId) -> LValue<'gcc> {

src/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ pub struct CodegenCx<'gcc, 'tcx> {
8383

8484
/// Cache of emitted const globals (value -> global)
8585
pub const_globals: RefCell<FxHashMap<RValue<'gcc>, RValue<'gcc>>>,
86+
/// Map from the address of a global variable (rvalue) to the global variable itself (lvalue).
87+
/// TODO(antoyo): remove when the rustc API is fixed.
88+
pub global_lvalues: RefCell<FxHashMap<RValue<'gcc>, LValue<'gcc>>>,
8689

8790
/// Cache of constant strings,
8891
pub const_cstr_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>,
@@ -195,6 +198,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
195198
function_instances: Default::default(),
196199
vtables: Default::default(),
197200
const_globals: Default::default(),
201+
global_lvalues: Default::default(),
198202
const_cstr_cache: Default::default(),
199203
globals: Default::default(),
200204
scalar_types: Default::default(),

0 commit comments

Comments
 (0)