https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114827
anlauf at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed| |2024-04-24 Keywords| |wrong-code --- Comment #5 from anlauf at gcc dot gnu.org --- Confirmed. Two data points which give a hint what might be wrong: 1) the valgrind error count at runtime depends on the string length passed to foo. I get no errors for a string of length 1. 2) the dump-tree of subroutine foo looks suspicious: if (b->_data == 0B) { b->_data = __builtin_malloc (MAX_EXPR <(unsigned long) rhs.1._vptr->_size, 1>); It looks like _size comes from: static struct __vtype_CHARACTER_1_ __vtab_CHARACTER_1_ = {._hash=85893463, ._size=1, ._extends=0B, ._def_init=0B, ._copy=__copy_character_1, ._final=0B}; and is always 1. On the other hand, subroutine run sets: class.2._vptr = (struct __vtype__STAR * {ref-all}) &__vtab_CHARACTER_1_; class.2._data = (void *) &"fubarfubarfubarfubarfubarfu"[1]{lb: 1 sz: 1}; class.2._len = 27; but _len is used in foo for the _copy, but not for the allocation. Thus the size allocated needs to be fixed. Changing the character argument to use kind=4, I see that _size seems to represent the element size. The allocation size thus should be changed to (_size * _len). Need to find the place where this happens... Anyone?