Bug in preprocessor when evaluating equations which are constants

Bug in preprocessor when evaluating equations which are constants

Post by Jeff » Wed, 03 Dec 2008 03:05:21


The following program results in the errors and warnings listed in the
comments:

#define MIN(a,b) ((a) < (b) ? (a) : (b))
//#define MIN(a,b) ((a) <= (b) ? (a) : (b)) /* Same errors */
//#define MIN(a,b) ((a) > (b) ? (b) : (a)) /* Same errors */

unsigned int test1 = MIN(0xffffffff, 0); /* bad (I'm line 5)*/
unsigned int test2 = MIN(0x80000000UL, 0UL); /* bad (I'm line 6)*/
unsigned int test3 = MIN(0x7fffffff, 0); /* OK */
unsigned int test4 = MIN(0, 0xffffffff); /* OK */
unsigned int test5 = MIN(0, 0x80000000); /* OK */

/* Produces:

lcc_test.c:5: warning: result of unsigned comparison is constant
lcc_test.c:5: initializer must be constant
lcc_test.c:6: warning: result of unsigned comparison is constant
lcc_test.c:6: initializer must be constant

Same thing w/ other MIN variations.
*/

unsigned int min (unsigned int a, unsigned int b)
{
return MIN(a,b); /* Generates good code (when no errors above) */
}
 
 
 

Bug in preprocessor when evaluating equations which are constants

Post by jacob navi » Thu, 04 Dec 2008 23:33:40


Fixed in the last release. Please download again.

Thanks for this bug report. This bug goes back to the original
lcc compiler... Incredible it is found after all this years.


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.yqcomputer.com/ . *** ia.edu/~lcc-win32

 
 
 

Bug in preprocessor when evaluating equations which are constants

Post by lenni » Fri, 12 Dec 2008 08:01:40

>

How was this fixed in the cpp source code? I would like to fix it in
our preprocessor code.

Lennie
 
 
 

Bug in preprocessor when evaluating equations which are constants

Post by jacob navi » Fri, 12 Dec 2008 18:55:15


Hi Lennie

It is not a preprocessor bug. It is a bug in the
simplifier that fails to evaluate:

(constant1 < constant2) ? const3 : const4;
in some cases like unsigned comparisons


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.yqcomputer.com/ . *** ia.edu/~lcc-win32
 
 
 

Bug in preprocessor when evaluating equations which are constants

Post by lenni » Thu, 18 Dec 2008 05:59:47

Ok but can you post which file & diff/patch for the original lcc
source so I can fix it in our compiler? Anyway you can contact the
original authors so they can update the SVN source trunk?

Thanks
Lennie