From 3e098224077e8c43a1d8c2070b26ffdfda422780 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 24 Feb 2023 09:20:14 -0500 Subject: 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] --- common.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'common.mk') diff --git a/common.mk b/common.mk index e141239ef0..6fac4bdca9 100644 --- a/common.mk +++ b/common.mk @@ -6791,6 +6791,7 @@ gc.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h gc.$(OBJEXT): $(top_srcdir)/internal/bignum.h gc.$(OBJEXT): $(top_srcdir)/internal/bits.h gc.$(OBJEXT): $(top_srcdir)/internal/class.h +gc.$(OBJEXT): $(top_srcdir)/internal/compile.h gc.$(OBJEXT): $(top_srcdir)/internal/compilers.h gc.$(OBJEXT): $(top_srcdir)/internal/complex.h gc.$(OBJEXT): $(top_srcdir)/internal/cont.h -- cgit v1.2.1