From 10a9c0e57f888b56fd396b913e0b0eeca1eb0d0c Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 26 May 2022 00:08:50 +0900 Subject: [PATCH] Mark immutable globals as read-only with `LValue::global_set_readonly` --- src/consts.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/consts.rs b/src/consts.rs index 4b517fd85f0..9517cf8494b 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -47,7 +47,10 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> { } } let global_value = self.static_addr_of_mut(cv, align, kind); - // TODO(antoyo): set global constant. + #[cfg(feature = "master")] + self.global_lvalues.borrow().get(&global_value) + .expect("`static_addr_of_mut` did not add the global to `self.global_lvalues`") + .global_set_readonly(); self.const_globals.borrow_mut().insert(cv, global_value); global_value } @@ -88,7 +91,8 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> { // mutability are placed into read-only memory. if !is_mutable { if self.type_is_freeze(ty) { - // TODO(antoyo): set global constant. + #[cfg(feature = "master")] + global.global_set_readonly(); } }