summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-02-24 16:10:54 -0500
committerPeter Zhu <peter@peterzhu.ca>2023-02-24 16:10:54 -0500
commitfa1eb31fcafc8ffbc8bd8557119e9a30905101b2 (patch)
treeef0306ca519f0df69fd670c0232648fb7a7d6c10 /gc.c
parent3e098224077e8c43a1d8c2070b26ffdfda422780 (diff)
[ci skip] Add note in gc.c about ambiguous case
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/gc.c b/gc.c
index dcd248f8aa..d830fd9fae 100644
--- a/gc.c
+++ b/gc.c
@@ -2495,11 +2495,24 @@ gc_event_hook_body(rb_execution_context_t *ec, rb_objspace_t *objspace, const rb
* the currently executing instruction. We should increment the PC
* because the source line is calculated with PC-1 in calc_pos.
*
- * 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.
+ * If the previous instruction is not a leaf instruction and the
+ * current 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.
+ *
+ * However, this implementation still has a bug. Consider the
+ * following situation:
+ *
+ * non-leaf
+ * leaf <-
+ *
+ * Where the PC currently points to a leaf instruction. We don't know
+ * which instruction we really are at since we could be at the non-leaf
+ * instruction (since it incremented the PC before executing the
+ * instruction). We could also be at the leaf instruction since the PC
+ * doesn't get incremented until the instruction finishes.
*/
if (rb_insns_leaf_p(prev_opcode)) {
ec->cfp->pc++;