Project

General

Profile

Actions

Bug #21012

closed

Compiling `a['a','b'],=1` with parse.y fails

Added by tompng (tomoya ishida) 3 days ago. Updated 2 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-01-06T01:50:53Z master c8e3d745fa) [x86_64-linux]
[ruby-core:120531]

Description

Compiling this code with parse.y fails with segmentation fault.

a['a','b'],=1

Compiling a['a',x],=1 generates instruction sequence that wrong contains opt_aset_with.

$ ruby --parser=parse.y --dump=insn -e "a['a',999],=1"
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,13)>
0000 putself                                                          (   1)[Li]
0001 opt_send_without_block                 <calldata!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE>
0003 putobject_INT2FIX_1_
0004 dup
0005 expandarray                            1, 0
0008 topn                                   1001
....
2006 topn                                   1001
2008 topn                                   1000
2010 opt_aset_with                          "a", <calldata!mid:[]=, argc:2, ARGS_SIMPLE>
2013 setn                                   1000
2015 pop
....
3014 pop
3015 leave

Updated by jeremyevans0 (Jeremy Evans) 3 days ago

  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED

From testing some historical versions on my system:

For: a['a','b'],=1

  • Ruby 1.9-2.5: No segfault, looks to be correct instructions
  • Ruby 2.6-3.1: Segfault
  • Ruby 3.2: No segfault, but incorrect instructions
  • Ruby 3.3-3.4: Segfault

For: a['a',10],=1:

  • Ruby 1.9-2.5: No segfault, looks to be correct instructions
  • Ruby 2.6-3.1: Segfault
  • Ruby 3.2-3.4: No segfault, but incorrect instructions

Updated by jeremyevans0 (Jeremy Evans) 2 days ago

I've submitted a PR that should fix this: https://github.com/ruby/ruby/pull/12528

Actions #3

Updated by jeremyevans (Jeremy Evans) 2 days ago

  • Status changed from Open to Closed

Applied in changeset git|e0d600ec190c64aff76cfcbd6009cffb927da166.


Avoid opt_aset_with optimization inside multiple assignment

Previously, since the opt_aset_with optimization was introduced,
use of the opt_aset_with optimization inside multiple assignment
would result in a segfault or incorrect instructions.

Fixes [Bug #21012]

Co-authored-by: Nobuyoshi Nakada

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0