#4317 Assignment of a pointer to an int goes undiagnosed
1: Sample code that reproduces the problem.
void foo(int *i, int *j)
{
*i = *i + j;
}
2: Exact command used to run SDCC on this sample code.
sdcc --std-c11 -S example.c
3: SDCC version tested.
SDCC 4.6.5 #17328 (Linux), default MCS51 target, on Compiler Explorer.
4: Observed and expected behaviour.
SDCC exits successfully and emits no diagnostic. The same happens with the default options on Compiler Explorer.
The addition *i + j is valid and its result has type int *. Assigning that result to *i, which has type int, violates the constraints on simple assignment in C11 6.5.16.1 paragraph 1. A diagnostic is required by 5.1.1.3 paragraph 1.
Replacing the whole assignment with *i = j; reproduces the missing diagnostic.
Here's Codex's own account of its questionable choices:
I did not attach the first three candidate patches but I think the final candidate is a good patch, therefore I am attaching it. Project rules say that someone else must also approve it. It would be great to get this fix in the 4.7.0 release; I found the lack of any diagnostic message surprising and worrying.
Regression test results:
Valdiag test results: