Christopher Bazley - 17 hours ago

Please consider the attached candidate bug fix patch.

The conditional-expression lowering allocated an aggregate iTemp which represented an address. Later conversion of branch assignments changed the shared temporary's type into a pointer. The return generator consequently selected its scalar path and crashed. This was not a return-only problem.

The candidate allocates an automatic backing object and uses the existing structure-assignment lowering to copy only the selected operand. Returns use the object itself; member access and arguments use its address where required. Structures and unions follow the same path.

Before the fix, the original reproducer crashes Z80 and STM8; MCS51 accepts it.

After the fix, that reproducer compiles without diagnostics on Z80, STM8 default/large, MCS51 default/large/stack-auto and PDK14.

Z80 simulation passes all 54 assertions in bug-4131.c. Coverage includes one-byte and nine-byte structures, nine-byte unions, returns, assignments, member access, arguments, selected-call side effects and nested conditionals.

The complete retained valdiag fixture set was compared before and after the fix on five configurations: 4,772 diagnostic checks, with no changed results.