https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123903

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2026-01-31
     Ever confirmed|0                           |1
                 CC|                            |anlauf at gcc dot gnu.org
          Component|libfortran                  |fortran

--- Comment #1 from anlauf at gcc dot gnu.org ---
Actually it is wrong code.

Tree-dump:

void MAIN__ ()
{
  integer(kind=8) .s;
  character(kind=1)[1:.s] * s;
...
          D.4689 = (void * restrict) __builtin_malloc (MAX_EXPR <(unsigned
long) (.s + 1), 1>);
          pstr.0 = (character(kind=1)[1:] *) D.4689;
          _gfortran_concat_string (.s + 1, pstr.0, .s, s, 1, &"a"[1]{lb: 1 sz:
1});

Note that .s is initialized to 0, but s is never set.

% gfc-16 -fdump-tree-original pr123903.f90 -g -fsanitize=address && ./a.out 

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7f8db535f08f in ???
#1  0x7f8db54851dd in ???
#2  0x401356 in MAIN__
        at /home/anlauf/gcc-bugs/pr123903.f90:2
#3  0x40176e in main
        at /home/anlauf/gcc-bugs/pr123903.f90:4
Segmentation fault

We should be able to make one of the -fcheck=... options handle this.

Reply via email to