To fix the problem I made the follwoing change:
In SDCC.y : added copying of LineNo of condition ($3) to lineno of $1
As soon as the complete if-statement is parsed the creatIfx function is called to create the ast tree for the full if-statement. At that moment the lineno is 22
(the end of the if statenment).
From the 'while'-statement parsing in the .y file one can see that there the lineno is retrieved from $1->lineDef. As my knowlegde of yacc (bison) is limited, I don't
know what $1 refers to, so I tried first the same construction, but $1 is not defined in the context of the IF statement. However $3 refers to the condition of the if statement which usually starts at the same line as the if, so I added that to the code.
However, I am aware that it is a kind of 'best guess'. I don't know how to obtain the lineno where the if statement started from the bison environment.
I did add the piece of code that was added to the bugreport as a separate bug code file for regresssion However, it is not clear to me how I can implement a useful check to prevent this error from happening again.