bugTiny C Compiler - Bugs: bug #31403, parser bug in structure

 
 

bug #31403: parser bug in structure

Submitted by:  None
Submitted on:  Thu 21 Oct 2010 09:15:21 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Confirmed
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.

 

Sun 24 Mar 2013 08:46:42 AM UTC, comment #4:

My precedent code is incorrect in C (gcc throw an error) :
struct A
{
struct B {
int f1;
int f2;
};
};
Must be :
struct A
{
struct {
int f1;
int f2;
};
};

So TCC has two issues in this part of the code :
- It doesn't throw an error on the erronous code of me precedent post.
- It doesn't throw an error on nested incomplete structure. Excerpt from C standard :
"A structure or union shall not contain a member with incomplete or function type (hence,
a structure shall not contain an instance of itself, but may contain a pointer to an instance
of itself),"

Tilatti Alban <tilatti>
Sat 23 Mar 2013 06:39:08 PM UTC, comment #3:

But ps is set to point to a next field at the line 2755, just after the begin of else block :
ps = &s->next;

I guess, the loop is necessary for get all fields of the anonymous sub struct.

For example with :
struct A
{
struct B {
int f1;
int f2;
};
};
int main()
{
struct A a;
a.f1 = 0;
a.f2 = 0;
}

Tilatti Alban <tilatti>
Sat 23 Mar 2013 06:17:11 PM UTC, comment #2:

Surely it should be at least:

- while((ass = ass->next) != NULL)
+ if (ass->next && &(ass->next->next) != ps)

Note that I'm not familiar with this part of the code but the &(ass->next->next) != ps part looks wrong. I don't see how ps could point to a next field.

Thomas Preud'homme <robotux>
Project Member
Sat 23 Mar 2013 05:57:03 PM UTC, comment #1:

This patch seems to fix the bug (based on 23/03/2013 repository) :
--- ./tccgen.c 2013-03-23 18:52:13.269888637 +0100
+++ ./tccgen.c 2013-03-23 18:51:06.569993229 +0100
@@ -2862,11 +2862,14 @@
}
if (v == 0 && (type1.t & VT_BTYPE) == VT_STRUCT) {
ass = type1.ref;
- while ((ass = ass->next) != NULL)
+ if (&(ass->next->next) != ps)
{
- ss = sym_push(ass->v, &ass->type, 0, offset + ass->c);
- *ps = ss;
- ps = &ss->next;
+ while ((ass = ass->next) != NULL)
+ {
+ ss = sym_push(ass->v, &ass->type, 0, offset + ass->c);
+ *ps = ss;
+ ps = &ss->next;
+ }
}
} else if (v) {
ss = sym_push(v | SYM_FIELD, &type1, 0, offset);

Tilatti Alban <tilatti>
Thu 21 Oct 2010 09:15:21 PM UTC, original submission:

when define structure lik this
code:
struct node{
struct node;
};

the compiler compile with no error, but
add new member type to structure like this
code:
struct node {
int x;
struct node;
};

the parser loop on it forever.

Anonymous

 

(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 tilatti (Posted a comment)
  • -unavailable- added by robotux (Updated 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):

     

     

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 19 Oct 2012 02:53:28 PM UTCrobotuxStatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup