Menu ▾ ▴

#3917 FATAL Compiler Internal Error caused by typeof_unqual on function (pointer) type names

open
nobody
None
other
5
2026-09-06
2026-01-08
No

Neither function type names nor function pointer type names can be used as the operand of the typeof_unqual operator.
Clang and LLVM permit it: https://godbolt.org/z/vY3P4ds4o
I would expect SDCC to permit it too.
If this is not addressed then this method of declaring pointers to optional-qualified function types will be unavailable to SDCC users, e.g. _Optional typeof_unqual (int (int)) *opf;
(I'm not sure why anyone would use typeof_unqual instead of typeof, but the fact remains.)

  1. Sample code that reproduces the problem:
int foo(int);
typeof_unqual (int (*)(int)) pfoo; // FATAL Compiler Internal Error
typeof_unqual (int (int)) foo; // FATAL Compiler Internal Error
typeof_unqual (int (int)) *pfoo; // FATAL Compiler Internal Error
  1. Exact command used to run SDCC on this sample code:
    sdcc --std=c23 bug2.c

  2. SDCC version tested:
    SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/r4k/r5k/r6k/sm83/tlcs90/ez80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/f8/f8l TD- 4.5.15 #15966 (Linux)
    published under GNU General Public License (GPL)

Also tested version 4.5.0 at Compiler Explorer.

  1. Copy of the error message or incorrect output:
    bug2.c:2: error 9: FATAL Compiler Internal Error in file 'SDCC.y' line number '833' : code generator internal error
    Contact Author with source code
    Internal error: validateLink failed in SPEC_NOUN((yyval.lnk)) @ SDCC.y:834: expected SPECIFIER, got DECLARATOR

Related

Bugs: #3916

Discussion

  • Christopher Bazley

    I think this bug must have been fixed because the behaviour of typeof_unqual with a newer build of SDCC appears to be broken in the same way as the behaviour of typeof, which was already reported as https://sourceforge.net/p/sdcc/bugs/3916/

    ~/optional-ts/examples $ sdcc -c --std=c23 --stack-auto 3917.c
    3917.c:3: error 1: Syntax error, declaration ignored at ')'
    Internal error: validateLink failed in DCL_PTR_CONST(type) @ SDCCast.c:3101: expected DECLARATOR, got null-link
    ~/optional-ts/examples $ sdcc -c --std=c23 3917.c
    3917.c:3: error 1: Syntax error, declaration ignored at ')'
    Internal error: validateLink failed in DCL_PTR_CONST(type) @ SDCCast.c:3101: expected DECLARATOR, got null-link
    ~/optional-ts/examples $ sdcc -v
    SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/r4k/r5k/r6k/sm83/tlcs90/ez80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/f8/f8l TD- 4.5.24 #16456 (Mac OS X ppc)
    published under GNU General Public License (GPL)
    
     
  • Christopher Bazley

    A proposed patch that implements a combined fix for this issue and bug 3916 is attached to https://sourceforge.net/p/sdcc/bugs/3916/

     

Log in to post a comment.