AnsweredAssumed Answered

cosmic compiler bug

Question asked by chan.calvin on Dec 23, 2015
Latest reply on Dec 30, 2015 by luca
Hi all

Cosmic compiler:
  Parser V4.11.4 - 12 Aug 2015,
  Generator (Limited) V4.4.3 - 13 Oct 2015
  Optimizer V4.4.3 - 13 Oct 2015

Consider the attached test code - testbug.c

line 17 isCW = !isCW ; // generates incorrect code using cpl instruction, with or with optimization

The compiler does not differentiate logical not '!' construct and complement '~' construct, and treats them the same here.

when isCW is true = 0x01, !isCW using cpl instruction causes isCW becomes 0xfe.

subsequent test on isCW at line 18 always result in true and causes line 19 always execute.

The correct code generation should use bcpl instruction instead.

The temporary fix can be:
1. use static or global variable for isCW
2. use the construct isCW ^= 1 ;  // knowing that it is just the lsb of a byte.

both are not a very good fix.

An alternate good fix can be shown in mod-testbug.c.  By adding another initialized dummy boolean variable.  This way the compiler will pack the booleans into a byte, forcing the compiler to interpret each boolean correctly.


Calvin

Attachments

Outcomes