Skip to content

Suppress -Warray-bounds false positive in RCLASS_WRITE_SUPER#16990

Merged
k0kubun merged 2 commits into
ruby:masterfrom
k0kubun:fix-warray-bounds
May 26, 2026
Merged

Suppress -Warray-bounds false positive in RCLASS_WRITE_SUPER#16990
k0kubun merged 2 commits into
ruby:masterfrom
k0kubun:fix-warray-bounds

Conversation

@k0kubun
Copy link
Copy Markdown
Member

@k0kubun k0kubun commented May 15, 2026

After 4bb1977 switched RCLASS_PRIME_CLASSEXT_WRITABLE_P to FL_TEST_RAW, GCC lost the RB_FL_ABLE-derived hint that klass is not a special const, and started warning that RCLASS_EXT_PRIME(klass) (used by the inlined RCLASS_WRITE_SUPER in class_associate_super) could yield a near-zero pointer. Make the existing VM_ASSERT(klass != 0) precondition visible to the optimizer via RBIMPL_ASSUME so the warning goes away without re-introducing the FL_TEST overhead.

Example warning:

In file included from ../include/ruby/internal/core/rarray.h:32,
                   from ../include/ruby/internal/core.h:23,
                   from ../include/ruby/ruby.h:29,
                   from ../constant.h:13,
                   from ../class.c:20:
  In function ‘rb_obj_write’,
      inlined from ‘RCLASS_WRITE_SUPER’ at ../internal/class.h:484:5,
      inlined from ‘class_associate_super’ at ../class.c:646:9,
      inlined from ‘rb_class_set_super’ at ../class.c:655:12:
  ../include/ruby/internal/gc.h:672:11: warning: array subscript 1 is outside array bounds of ‘rb_classext_t[0]’ {aka ‘struct rb_classext_struct[]’} [-Warray-bounds=]
    672 |     *slot = b;
        |     ~~~~~~^~~
  In function ‘rb_class_set_super’:
  cc1: note: source object is likely at address zero
  Unpacked gems/debug-1.11.1.gem
  In function ‘rb_obj_write’,
      inlined from ‘RCLASS_WRITE_SUPER’ at ../internal/class.h:484:5,
      inlined from ‘class_associate_super.constprop’ at ../class.c:646:9:
  ../include/ruby/internal/gc.h:672:11: warning: array subscript 1 is outside array bounds of ‘rb_classext_t[0]’ {aka ‘struct rb_classext_struct[]’} [-Warray-bounds=]
    672 |     *slot = b;
        |     ~~~~~~^~~
  In function ‘class_associate_super.constprop’:
  cc1: note: source object is likely at address zero
  transdb.h unchanged
  At top level:
  cc1: note: unrecognized command-line option ‘-Wno-self-assign’ may have been intended to silence earlier diagnostics
  cc1: note: unrecognized command-line option ‘-Wno-parentheses-equality’ may have been intended to silence earlier diagnostics
  cc1: note: unrecognized command-line option ‘-Wno-constant-logical-operand’ may have been intended to silence earlier diagnostics

k0kubun and others added 2 commits May 15, 2026 12:56
After 4bb1977 switched RCLASS_PRIME_CLASSEXT_WRITABLE_P to FL_TEST_RAW,
GCC lost the RB_FL_ABLE-derived hint that klass is not a special const,
and started warning that RCLASS_EXT_PRIME(klass) (used by the inlined
RCLASS_WRITE_SUPER in class_associate_super) could yield a near-zero
pointer. Make the existing VM_ASSERT(klass != 0) precondition visible
to the optimizer via RBIMPL_ASSUME so the warning goes away without
re-introducing the FL_TEST overhead.
@k0kubun k0kubun marked this pull request as ready for review May 26, 2026 21:50
@k0kubun k0kubun merged commit dcfba57 into ruby:master May 26, 2026
116 checks passed
@k0kubun k0kubun deleted the fix-warray-bounds branch May 26, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants