diff options
author | Peter Zhu <[email protected]> | 2023-02-24 09:20:14 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2023-02-24 14:10:09 -0500 |
commit | 3e098224077e8c43a1d8c2070b26ffdfda422780 (patch) | |
tree | ac701b8c89d90f3e6cd632ce22d0713d149ba945 /internal/compile.h | |
parent | d2631c427ee723f6136ac1e08dd3c9c5b04c6725 (diff) |
Fix incorrect line numbers in GC hook
If the previous instruction is not a leaf instruction, then the PC was
incremented before the instruction was ran (meaning the currently
executing instruction is actually the previous instruction), so we
should not increment the PC otherwise we will calculate the source
line for the next instruction.
This bug can be reproduced in the following script:
```
require "objspace"
ObjectSpace.trace_object_allocations_start
a =
1.0 / 0.0
p [ObjectSpace.allocation_sourceline(a), ObjectSpace.allocation_sourcefile(a)]
```
Which outputs: [4, "test.rb"]
This is incorrect because the object was allocated on line 10 and not
line 4. The behaviour is correct when we use a leaf instruction (e.g.
if we replaced `1.0 / 0.0` with `"hello"`), then the output is:
[10, "test.rb"].
[Bug #19456]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7357
Diffstat (limited to 'internal/compile.h')
-rw-r--r-- | internal/compile.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/internal/compile.h b/internal/compile.h index d32c2233c9..8670785b7b 100644 --- a/internal/compile.h +++ b/internal/compile.h @@ -17,6 +17,8 @@ struct rb_iseq_struct; /* in vm_core.h */ /* compile.c */ int rb_dvar_defined(ID, const struct rb_iseq_struct *); int rb_local_defined(ID, const struct rb_iseq_struct *); +bool rb_insns_leaf_p(int i); +int rb_insn_len(VALUE insn); const char *rb_insns_name(int i); VALUE rb_insns_name_array(void); int rb_iseq_cdhash_cmp(VALUE val, VALUE lit); |