bugTiny C Compiler - Bugs: bug #38557, tcc preprocessor has trouble...

 
 

bug #38557: tcc preprocessor has trouble expanding hex numbers

Submitted by:  Austin English <austin987>
Submitted on:  Wed 20 Mar 2013 08:00:10 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 04 Apr 2013 11:07:23 AM UTC, comment #3:

OK, I was not aware of this thread: http://lists.nongnu.org/archive/html/tinycc-devel/2013-03/msg00018.html

So, we have this:
#define FOO 0xfe
char bar[FOO+1];
...

TCC compiles this code sucessfully in one pass but not when you preprocess it separately with tcc -E because the tcc preprocessor generates:
char bar[0xfe+1];
and 0xfe+1 is considered as one token instead of three at the second pass.

If you try with gcc -E you can see that a white space is added right after the macro expansion to avoid this problem.

Christophe Staïesse <chastai>
Wed 03 Apr 2013 11:34:49 PM UTC, comment #2:

http://www.winehq.org/pipermail/wine-devel/2013-April/099323.html

The patch to wine was rejected:
"This has nothing to do with the preprocessor. It's a compiler bug."

Austin English <austin987>
Sun 24 Mar 2013 12:45:57 PM UTC, comment #1:

Hello,

I use the latest release (0.9.26) and the error occurs in both cases.

In fact, after some investigation, I found out that it's the correct behavior as '0xfe+1' is considered as a number token by the preprocessor. I've learned something today :)

From the C89 standard:
" 3.1.8 Preprocessing numbers:
A preprocessing number begins with a digit optionally preceded by a period (.) and may be followed by letters, underscores, digits, periods, and e+, e-, E+, or E- character sequences."

There is a similar rule in C99 (see 6.4.8).

The solution is to put a space before the sign.

Christophe Staïesse <chastai>
Wed 20 Mar 2013 08:00:10 PM UTC, original submission:

austin@debian-home:~$ tcc -E foo.c
# 2 "foo.c"

typedef struct _FOO
{
unsigned char bar[0xfe+1];
} FOO;

int main(void)
{
return 0;
}
austin@debian-home:~$ tcc -E foo.c -o foo-i.c
austin@debian-home:~$ tcc -c foo-i.c
foo-i.c:5: error: invalid number

if compiling directly, the problem does not appear, only when compiling preprocessed source:
austin@debian-home:~$ tcc -c foo.c
austin@debian-home:~$ ./a.out
austin@debian-home:~$ echo $?
0

Austin English <austin987>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by chastai (Posted a comment)
  • -unavailable- added by austin987 (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup