Menu ▾ ▴

#1266 cobc internal compiler error "unexpected category: 0" on a relation condition between two object references

GC 3.x
open
nobody
None
5 - default
2026-10-30
2026-10-30
No

Versions: GnuCOBOL 3.2.0 (Ubuntu gnucobol3 3.2-4build1) and 3.3-dev r5751 (CI snapshot 3.3-dev.138 of 2026-10-29), x86_64 Linux. Both re-run 2026-10-30.

Attached: objc.cob (crashes on both versions) and b3.cob (crashes on 3.2.0, refused with an ordinary error on 3.3-dev).

objc.cob:

IDENTIFICATION DIVISION.
PROGRAM-ID. OBJC.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 R1 USAGE OBJECT REFERENCE.
01 R2 USAGE OBJECT REFERENCE.
PROCEDURE DIVISION.
IF R1 = R2 DISPLAY "EQ" ELSE DISPLAY "NE" END-IF
STOP RUN.

1. objc.cob: IF R1 = R2 crashes the compiler

3.2.0, cobc -std=cobol2014 -fformat=free -x objc.cob, exit 134 (also with the default dialect):

objc.cob:5: warning: OBJECTS is not implemented [-Wpending]
    3 | DATA DIVISION.
    4 | WORKING-STORAGE SECTION.
    5 > 01 R1 USAGE OBJECT REFERENCE.
    6 | 01 R2 USAGE OBJECT REFERENCE.
    7 | PROCEDURE DIVISION.
objc.cob:6: warning: OBJECTS is not implemented [-Wpending]
    4 | WORKING-STORAGE SECTION.
    5 | 01 R1 USAGE OBJECT REFERENCE.
    6 > 01 R2 USAGE OBJECT REFERENCE.
    7 | PROCEDURE DIVISION.
    8 | IF R1 = R2 DISPLAY "EQ" ELSE DISPLAY "NE" END-IF
cobc: unexpected category: 0
cobc: tree.c:1606: internal compiler error

cobc: aborting codegen for objc.cob, last statement at line 8 (PROGRAM-ID: OBJC)

cobc: Please report this!
Aborted

3.3-dev r5751, the same command, exit 139 (also with the default dialect). The internal error is now followed by a segmentation fault:

objc.cob:5: warning: OBJECTS is not implemented [-Wpending]
    3 | DATA DIVISION.
    4 | WORKING-STORAGE SECTION.
    5 > 01 R1 USAGE OBJECT REFERENCE.
    6 | 01 R2 USAGE OBJECT REFERENCE.
    7 | PROCEDURE DIVISION.
objc.cob:6: warning: OBJECTS is not implemented [-Wpending]
    6 > 01 R2 USAGE OBJECT REFERENCE.
    7 | PROCEDURE DIVISION.
    8 | IF R1 = R2 DISPLAY "EQ" ELSE DISPLAY "NE" END-IF
cobc: unexpected category: 0
cobc: tree.c:1613: internal compiler error

cobc: aborting codegen for objc.cob, last statement at line 8 (PROGRAM-ID: OBJC)

attempt to reference invalid memory address (signal SIGSEGV)

cobc: aborting codegen for objc.cob, last statement at line 8 (PROGRAM-ID: OBJC)
cobc: Please report this!
Segmentation fault

On both versions -fsyntax-only prints only the two warnings and exits 0, so the error is in code generation.

2. b3.cob: SET object-reference TO NULL (crashes on 3.2.0, fixed in 3.3-dev)

IDENTIFICATION DIVISION.
PROGRAM-ID. OBJREF.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-OBJ USAGE OBJECT REFERENCE.
PROCEDURE DIVISION.
    SET WS-OBJ TO NULL
    STOP RUN.

3.2.0, cobc -std=cobol2014 -fformat=free -x b3.cob, exit 134 (-fsyntax-only exits 0):

b3.cob:5: warning: OBJECTS is not implemented [-Wpending]
    3 | DATA DIVISION.
    4 | WORKING-STORAGE SECTION.
    5 > 01 WS-OBJ USAGE OBJECT REFERENCE.
    6 | PROCEDURE DIVISION.
    7 |     SET WS-OBJ TO NULL
cobc: unexpected category: 0
cobc: tree.c:1606: internal compiler error

cobc: aborting codegen for b3.cob, last statement at line 7 (PROGRAM-ID: OBJREF)

cobc: Please report this!
Aborted

3.3-dev r5751 refuses it with an ordinary error instead (exit 1, also with -fsyntax-only):

b3.cob:7: error: invalid SET statement
    7 >     SET WS-OBJ TO NULL
    8 |     STOP RUN.
    9 | <EOF>

So on 3.3-dev only the relation between two object references still reaches the abort.

Expected

Both programs are legal COBOL 2002/2014. ISO/IEC 1989:2023:

  • §13.18.60.4 general rule 22: "A data item described with a USAGE OBJECT REFERENCE clause is called an object reference. An object reference is a data item of class object and category object-reference."
  • §8.8.4.2.3 rule 5: "Identifier-3 and identifier-4 shall reference data items of class message-tag, object, or pointer, and shall be of the same category". §8.8.4.2.15 defines the comparison of operands of class object.
  • §14.9.39.3 syntax rules 8 and 9 (SET format 5, object-reference assignment) and §8.4.3.7.3 syntax rule 2 (NULL is of class object and category object reference) make SET WS-OBJ TO NULL legal.

Object orientation is not an optional feature in the standard. Even while it stays unimplemented, the expected result is an error diagnostic, not an internal compiler error.

Where we think the fix belongs

In cb_tree_category (cobc/tree.c, the CB_TAG_FIELD branch), an elementary item with CB_USAGE_OBJECT has no PICTURE and matches none of the POINTER, PROGRAM-POINTER, PICTURE or external-form arms, so it gets CB_CATEGORY_UNKNOWN (0). cb_tree_type, called from output_attr in cobc/codegen.c for the comparison, then reaches its default arm and aborts. Its CB_CATEGORY_OBJECT_REFERENCE case is never reached for a field. Giving such a field CB_CATEGORY_OBJECT_REFERENCE in cb_tree_category should cover both programs. (Line numbers are from the 3.2 source.)

2 Attachments

Discussion


Log in to post a comment.