|
|
Bug in preprocessor when evaluating equations which are constants
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) */
}
|
|
0
|
|
|
|
Reply
|
JeffR
|
12/1/2008 6:05:21 PM |
|
JeffR wrote:
> 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) */
> }
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.cs.virginia.edu/~lcc-win32
|
|
0
|
|
|
|
Reply
|
jacob
|
12/3/2008 2:33:40 PM
|
|
>
> 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/informatiquehttp://www.cs.virginia.edu/~lcc-win32
How was this fixed in the cpp source code? I would like to fix it in
our preprocessor code.
Lennie
|
|
0
|
|
|
|
Reply
|
lennie
|
12/10/2008 11:01:40 PM
|
|
lennie wrote:
>> 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/informatiquehttp://www.cs.virginia.edu/~lcc-win32
>
> How was this fixed in the cpp source code? I would like to fix it in
> our preprocessor code.
>
> Lennie
>
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.cs.virginia.edu/~lcc-win32
|
|
0
|
|
|
|
Reply
|
jacob
|
12/11/2008 9:55:15 AM
|
|
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
|
|
0
|
|
|
|
Reply
|
lennie
|
12/16/2008 8:59:47 PM
|
|
|
4 Replies
119 Views
(page loaded in 0.045 seconds)
|
|
|
|
|
|
|
|
|