1: Sample code that reproduces the problem.
typedef int Array[2];
_Atomic(Array) object;
2: Exact command used to run SDCC on this sample code.
sdcc -mz80 --std=c2y -S bug.c
3: SDCC version tested.
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/r4k/r5k/r6k/sm83/tlcs90/ez80/z80n/r800/ds390/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15 TD- 4.6.4 #0 (Linux)
published under GNU General Public License (GPL)
Built from clean official SVN r16981 sources on Linux.
4: Observed and expected behaviour.
SDCC exits with status 1 and prints:
Internal error: validateLink failed in SPEC_NOUN((yyval.lnk)) @ SDCC.y:755: expected SPECIFIER, got DECLARATOR
WG14 N3886,
6.7.3.5 paragraph 3, specifies the constraint violated by the sample:
The type name in an atomic type specifier shall not refer to an array type, a function type, an atomic
type, or a qualified type.
An atomic type specifier must not refer to an array or function type. SDCC exits with an internal compiler error instead of a source diagnostic. Although SDCC does not support atomics, it should diagnose unsupported atomics or the invalid type without failing an internal invariant. Corresponding ordinary array and function declarations compile cleanly.
5: Additional checks.
The behaviour reproduces on all 19 C2Y configurations below, and Z80 in C23
mode. Every valid control compiles without diagnostics.
GCC 13.3.0, invoked with -std=c2x -pedantic-errors -fsyntax-only, rejects every invalid example and accepts every valid example.
| Case | Expected | SDCC |
|---|---|---|
atomic-array.c |
Diagnostic required | Internal compiler error |
atomic-function.c |
Diagnostic required | Internal compiler error |
array-control.c |
Valid | Accepted silently |
function-control.c |
Valid | Accepted silently |
Configurations tested: MCS51 default/large/medium/stack-auto, DS390, Z80, Z180,
Rabbit 2000/4000, SM83, TLCS-90, HC08, S08, STM8 default/large, PDK13/14/15,
and eZ80. These are compiler and diagnostic checks, not runtime tests.
Implementation observation: The ATOMIC type-name action in src/SDCC.y assigns the whole type chain to $$ and then reads SPEC_ATOMIC on its head. An array or function head is a DECLARATOR, causing validateLink to fail before the unsupported-atomic diagnostic.
Please consider the attached candidate bugfix patch.
70/70 diagnostic checks passed across Z80, STM8, MCS51 default/large/stack-auto, PDK14 and S08.
The nine cases cover atomic arrays and functions, ordinary and function pointers, qualified types, nested atomic types, and valid non-atomic declarations.
The existing valdiag tests were compared before and after on five configurations: no existing test outcome changed, including the known baseline failures.