From: SourceForge.net <no...@so...> - 2012-06-04 11:28:46
|
Bugs item #3531687, was opened at 2012-06-03 10:16 Message generated for change (Comment added) made by mz-fuzzy You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=3531687&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 8 Private: No Submitted By: Martin Matyas (mz-fuzzy) Assigned to: Nobody/Anonymous (nobody) Summary: Comparisons between bool and char broken Initial Comment: Sdcc generates wrong code for condition with conditional operator. see sdccerr.lst: - result of rows 57-61 is: acc is set if param a is nonzero. Then, on 62-65, acc is compared with result of conditional expression. This works wrong for flag=1 and a>1. =================== int f(char a, char flag) { if (a == (flag ? 1 : 0)) return 0; return 1; } =================== ---------------------------------------------------------------------- Comment By: Martin Matyas (mz-fuzzy) Date: 2012-06-04 04:28 Message: Philip, for me, it's strange that you are writing about evaluating of "(flag ? 1 : 0)" as bool. It should be evaluated as "1" or "0" - meaning integers, shouldn't it? But I'm not a compiler expert, just from a logical point of view. Martin ---------------------------------------------------------------------- Comment By: Philipp Klaus Krause (spth) Date: 2012-06-04 03:17 Message: This is even more serious: 1) The bug is not z80-specific, it affects all ports. 2) It affects all comparisons (equality, less-than, etc) between char (both signed and unsigned) and bool. In all these cases the char operand is cast to bool before comparing. In your case we have the comparison == between the char a and the bool (flag ? 1 : 0) resulting in a being cast to boolbefore the comparison. Philipp ---------------------------------------------------------------------- Comment By: Martin Matyas (mz-fuzzy) Date: 2012-06-03 10:18 Message: ... sorry, forgot to add: SDCC : mcs51/gbz80/z80/z180/r2k/r3ka/ds390/pic16/pic14/TININative/ds400/hc08/s08 3.1.5 #7827 (Jun 1 2012) (Linux) command line: sdcc -mz80 -c sdccerr.c ---------------------------------------------------------------------- Comment By: Martin Matyas (mz-fuzzy) Date: 2012-06-03 10:16 Message: prio 7 as a wrong code is generated silently ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=3531687&group_id=599 |