Skip to content

Commit 9d44cb0

Browse files
committed
Remove rbimpl_rstring_getmem() usage as workaround for GCC 15.2.1 optimization bug. [Bug #21655]
1 parent c5bd4ac commit 9d44cb0

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

include/ruby/internal/core/rstring.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,9 @@ RBIMPL_ATTR_ARTIFICIAL()
415415
static inline char *
416416
RSTRING_PTR(VALUE str)
417417
{
418-
char *ptr = rbimpl_rstring_getmem(str).as.heap.ptr;
418+
char *ptr = RB_FL_TEST_RAW(str, RSTRING_NOEMBED) ?
419+
RSTRING(str)->as.heap.ptr :
420+
RSTRING(str)->as.embed.ary;
419421

420422
if (RUBY_DEBUG && RB_UNLIKELY(! ptr)) {
421423
/* :BEWARE: @shyouhei thinks that currently, there are rooms for this
@@ -441,14 +443,17 @@ RBIMPL_ATTR_ARTIFICIAL()
441443
static inline char *
442444
RSTRING_END(VALUE str)
443445
{
444-
struct RString buf = rbimpl_rstring_getmem(str);
446+
char *ptr = RB_FL_TEST_RAW(str, RSTRING_NOEMBED) ?
447+
RSTRING(str)->as.heap.ptr :
448+
RSTRING(str)->as.embed.ary;
449+
long len = RSTRING_LEN(str);
445450

446-
if (RUBY_DEBUG && RB_UNLIKELY(! buf.as.heap.ptr)) {
451+
if (RUBY_DEBUG && RB_UNLIKELY(!ptr)) {
447452
/* Ditto. */
448453
rb_debug_rstring_null_ptr("RSTRING_END");
449454
}
450455

451-
return &buf.as.heap.ptr[buf.len];
456+
return &ptr[len];
452457
}
453458

454459
RBIMPL_ATTR_ARTIFICIAL()
@@ -480,9 +485,10 @@ RSTRING_LENINT(VALUE str)
480485
#ifdef HAVE_STMT_AND_DECL_IN_EXPR
481486
# define RSTRING_GETMEM(str, ptrvar, lenvar) \
482487
__extension__ ({ \
483-
struct RString rbimpl_str = rbimpl_rstring_getmem(str); \
484-
(ptrvar) = rbimpl_str.as.heap.ptr; \
485-
(lenvar) = rbimpl_str.len; \
488+
(ptrvar) = RB_FL_TEST_RAW(str, RSTRING_NOEMBED) ? \
489+
RSTRING(str)->as.heap.ptr : \
490+
RSTRING(str)->as.embed.ary; \
491+
(lenvar) = RSTRING_LEN(str); \
486492
})
487493
#else
488494
# define RSTRING_GETMEM(str, ptrvar, lenvar) \

0 commit comments

Comments
 (0)