Skip to content

Commit 10a9c0e

Browse files
committed
Mark immutable globals as read-only with LValue::global_set_readonly
1 parent f26eb5a commit 10a9c0e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/consts.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
4747
}
4848
}
4949
let global_value = self.static_addr_of_mut(cv, align, kind);
50-
// TODO(antoyo): set global constant.
50+
#[cfg(feature = "master")]
51+
self.global_lvalues.borrow().get(&global_value)
52+
.expect("`static_addr_of_mut` did not add the global to `self.global_lvalues`")
53+
.global_set_readonly();
5154
self.const_globals.borrow_mut().insert(cv, global_value);
5255
global_value
5356
}
@@ -88,7 +91,8 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
8891
// mutability are placed into read-only memory.
8992
if !is_mutable {
9093
if self.type_is_freeze(ty) {
91-
// TODO(antoyo): set global constant.
94+
#[cfg(feature = "master")]
95+
global.global_set_readonly();
9296
}
9397
}
9498

0 commit comments

Comments
 (0)