]> git.lizzy.rs Git - rust.git/commitdiff
Support upgrading the alignment of a global variable (#121)
authorantoyo <antoyo@users.noreply.github.com>
Wed, 26 Jan 2022 13:57:17 +0000 (08:57 -0500)
committerGitHub <noreply@github.com>
Wed, 26 Jan 2022 13:57:17 +0000 (08:57 -0500)
* Renable failing test
* Update to newest gccjit.rs

Cargo.lock
patches/0023-core-Ignore-failing-tests.patch
src/consts.rs
src/context.rs

index 47925f72c2cbdd30b6964213f60da8da3dc26d2f..2688ea4a4e14cca2e1d04ee4c09f9d0b76525288 100644 (file)
@@ -41,7 +41,7 @@ dependencies = [
 [[package]]
 name = "gccjit"
 version = "1.0.0"
-source = "git+https://github.com/antoyo/gccjit.rs#0672b78d162d65b6f36ea4062947253affe9fdef"
+source = "git+https://github.com/antoyo/gccjit.rs#e68fce53af18dce4d40e6b7090f881ff86a2e892"
 dependencies = [
  "gccjit_sys",
 ]
@@ -49,7 +49,7 @@ dependencies = [
 [[package]]
 name = "gccjit_sys"
 version = "0.0.1"
-source = "git+https://github.com/antoyo/gccjit.rs#0672b78d162d65b6f36ea4062947253affe9fdef"
+source = "git+https://github.com/antoyo/gccjit.rs#e68fce53af18dce4d40e6b7090f881ff86a2e892"
 dependencies = [
  "libc 0.1.12",
 ]
index 73e9c858caf2b6dbb51419d804152e83045a3ab8..ee5ba449fb8e6bb0ee310eea54ac65a01ec8842a 100644 (file)
@@ -46,24 +46,4 @@ index 4bc44e9..8e3c7a4 100644
  
  #[test]
  fn cell_allows_array_cycle() {
-diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
-index 3e00e0a..8e5663b 100644
---- a/library/core/tests/slice.rs
-+++ b/library/core/tests/slice.rs
-@@ -2108,6 +2108,7 @@ fn test_copy_within_panics_src_out_of_bounds() {
-     bytes.copy_within(usize::MAX..=usize::MAX, 0);
- }
-+/*
- #[test]
- fn test_is_sorted() {
-     let empty: [i32; 0] = [];
-@@ -2122,6 +2123,7 @@ fn test_is_sorted() {
-     assert!(!["c", "bb", "aaa"].is_sorted());
-     assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
- }
-+*/
- #[test]
- fn test_slice_run_destructors() {
 -- 2.21.0 (Apple Git-122)
index e55da7952e753e68d93037320b0eedbaf4368945..af00539f89b5fd0fb0238585e9b9a4a467adbd3a 100644 (file)
@@ -35,7 +35,12 @@ fn static_addr_of(&self, cv: RValue<'gcc>, align: Align, kind: Option<&str>) ->
         // following:
         for (value, variable) in &*self.const_globals.borrow() {
             if format!("{:?}", value) == format!("{:?}", cv) {
-                // TODO(antoyo): upgrade alignment.
+                if let Some(global_variable) = self.global_lvalues.borrow().get(variable) {
+                    let alignment = align.bits() as i32;
+                    if alignment > global_variable.get_alignment() {
+                        global_variable.set_alignment(alignment);
+                    }
+                }
                 return *variable;
             }
         }
@@ -182,7 +187,9 @@ pub fn static_addr_of_mut(&self, cv: RValue<'gcc>, align: Align, kind: Option<&s
         // globally.
         global.global_set_initializer_rvalue(cv);
         // TODO(antoyo): set unnamed address.
-        global.get_address(None)
+        let rvalue = global.get_address(None);
+        self.global_lvalues.borrow_mut().insert(rvalue, global);
+        rvalue
     }
 
     pub fn get_static(&self, def_id: DefId) -> LValue<'gcc> {
index dfcd1b6231216cb49acc361bdb83e054a43e058d..d260a9833470e9d63e30a24160c917b1da68b56d 100644 (file)
@@ -83,6 +83,9 @@ pub struct CodegenCx<'gcc, 'tcx> {
 
     /// Cache of emitted const globals (value -> global)
     pub const_globals: RefCell<FxHashMap<RValue<'gcc>, RValue<'gcc>>>,
+    /// Map from the address of a global variable (rvalue) to the global variable itself (lvalue).
+    /// TODO(antoyo): remove when the rustc API is fixed.
+    pub global_lvalues: RefCell<FxHashMap<RValue<'gcc>, LValue<'gcc>>>,
 
     /// Cache of constant strings,
     pub const_cstr_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>,
@@ -195,6 +198,7 @@ pub fn new(context: &'gcc Context<'gcc>, codegen_unit: &'tcx CodegenUnit<'tcx>,
             function_instances: Default::default(),
             vtables: Default::default(),
             const_globals: Default::default(),
+            global_lvalues: Default::default(),
             const_cstr_cache: Default::default(),
             globals: Default::default(),
             scalar_types: Default::default(),