aboutsummaryrefslogtreecommitdiffstats
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2022-04-06 17:29:13 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2022-04-07 12:49:28 -0400
commit16e08d53a0c78c149960b687c6ac735f21d5c405 (patch)
tree85fb0838090b1d091c08a3d63e7d5e22b17ff763 /vm_insnhelper.c
parent697eed63e81eff0e02226ceb6ab3bd2fd99000e3 (diff)
downloadruby-16e08d53a0c78c149960b687c6ac735f21d5c405.tar.gz
Fix strict aliasing issue
`rb_id_table_lookup()` writes to a `VALUE`, which is definitely a distinct type from `st_table *`. With LTO, the compiler is allowed by N1256 ยง6.5p7 to remove the output parameter write via type-based alias analysis. See also: a0a8f2abf53
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index ce79c5a957..f56e01d7f7 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -4937,12 +4937,16 @@ vm_ic_compile_i(VALUE *code, VALUE insn, size_t index, void *ic)
if (insn == BIN(getconstant)) {
ID id = code[index + 1];
- rb_vm_t *vm = GET_VM();
-
+ struct rb_id_table *const_cache = GET_VM()->constant_cache;
+ VALUE lookup_result;
st_table *ics;
- if (!rb_id_table_lookup(vm->constant_cache, id, (VALUE *) &ics)) {
+
+ if (rb_id_table_lookup(const_cache, id, &lookup_result)) {
+ ics = (st_table *)lookup_result;
+ }
+ else {
ics = st_init_numtable();
- rb_id_table_insert(vm->constant_cache, id, (VALUE) ics);
+ rb_id_table_insert(const_cache, id, (VALUE)ics);
}
st_insert(ics, (st_data_t) ic, (st_data_t) Qtrue);