Menu

#517 Fix sdcc crash when only compile mode from stdin

open
nobody
None
other
5
16 hours ago
2026-09-03
No

Fixes bugs:#4034.

  1. NULL pointer dereference crash fix in dwFindFileIndex() (src/SDCCdwarf2.c:1594-1599):
    Using --c1mode with --debug would crash with SIGSEGV because fullSrcFileName was NULL when reading from stdin. Fixed by adding a fallback to "<stdin>" when the filename is unavailable.

  2. New --c1mode-src <file> CLI option (src/SDCCmain.c):
    Allows specifying the original source filename for DWARF debug info when using --c1mode (preprocessed input via stdin). Without this, DWARF output had no file reference when --c1mode was used.

  3. DWARF generation crash for _BitInt types (src/SDCCdwarf2.c:2569-2588):
    Using --debug with C23 _BitInt(N) types would crash with FATAL error "unhandled base type _BitInt(N)" because dwTagFromType() was missing a case for V_BITINT/V_BITINTBITFIELD. Fixed by adding proper DWARF type tag generation (DW_TAG_base_type with DW_AT_bit_size).

Test coverage added:

  • support/regression/tests/bug-4034.c: Exercises various _BitInt types (signed/unsigned, different widths, bitfields) with --debug flag forced via EXTRA_COMPILE_HACK in Makefile.in. Pre-fix this would crash during DWARF generation; post-fix it compiles and runs successfully.

  • support/regression/test-c1mode-debug.py: Platform-independent Python script (works on Windows) that directly tests --c1mode --debug (piping source through stdin) and --c1mode-src <file> option. Pre-fix both would crash; post-fix both pass.

  • Wired test-c1mode-debug into make test-ports dependency chain so it runs automatically during the regression suite.

1 Attachments

Discussion

  • Vladimir Setyaev

    ChangeLog:

    • SDCCglobl.h: Added new command line option --c1mode-src
    • src/SDCCmain.c (parseCmdLine): Added new command line option --c1mode-src to specify source file in debug information
    • SDCCdwarf2.c (dwWriteModule, dwMatchTypes,dwHashType): Add support _BitInt(N)/BitIntField for dwarf
    • SDCCdwarf2.c (dwFindFileIndex, dwWriteModule) Set module name from source file
    • support/regression/tests/bug-4034.c: New regression test for _BitInt(N).
    • test-c1mode-debug.py: New test to check the operation of the --c1mode --debug -c1mode-src arguments
    • Makefile.in: Run test test-c1mode-debug
     
  • Philipp Klaus Krause

    The changes to SDCC itself look good to me. But I'm not a Python programmer, so I'd like to get the opinion of someone who knows Python (used for the test) before the patch goes in.

     

Log in to post a comment.