https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126104
Bug ID: 126104
Summary: gcobol ICE (segfault) on out-of-bounds reference
modification
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: cobol
Assignee: unassigned at gcc dot gnu.org
Reporter: peeterjoot at protonmail dot com
Target Milestone: ---
Created attachment 64931
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64931&action=edit
anylength-refmod-oob.cob from the inline bug report summary
# Summary
`gcobol` crashes with an internal compiler error (segmentation fault) when a
program
reference-modifies a data item at a start position beyond the item's length
(e.g. `STR(5:)` on a one-byte `PIC X` item). The compiler should emit a
diagnostic
for the out-of-bounds reference modification, not crash.
# Environment
- `gcobol (GCC) 17.0.0 20260604 (experimental)`
# Steps to reproduce
Compile the following program:
```cobol
IDENTIFICATION DIVISION.
PROGRAM-ID. CRASH1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 STR PIC X.
PROCEDURE DIVISION.
MOVE 'abcd' TO STR(5:)
STOP RUN.
```
```
gcobol -ffixed-form -c anylength-refmod-oob.cob -o /dev/null
```
# Actual result
```
cobol1: internal compiler error: Segmentation fault
0x239b373 internal_error(char const*, ...)
gcc/diagnostic-global-context.cc:787
0x109185b crash_signal
gcc/toplev.cc:325
0x9624a8 nice_name_of
gcc/cobol/parse_ante.h:322
0x9624a8 literal_refmod_valid
```
The crash is in `literal_refmod_valid` (via `nice_name_of`), i.e. while
validating the
reference modification.
# Expected result
A diagnostic that the reference modification start position (5) exceeds the
length of
`STR` (1), with a clean (non-zero) exit — no compiler crash.
# Notes
Reduced from a larger program produced by a COBOL source-to-source transformer.
In the
original the item was `ANY LENGTH`; the transformer emitted it as a fixed
one-byte `PIC X`,
after which the pre-existing `STR(5:)` reference modification became out of
bounds and
tripped this crash. The crash itself is independent of how the input was
produced — any
out-of-bounds start position reproduces it.