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

 
 

bug #31403: parser bug in structure

Submitter:  None
Submitted:  Thu 21 Oct 2010 09:15:21 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Confirmed
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group 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 Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tilatti (Posted a comment)
  • -email is unavailable- added by robotux (Updated the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-10-19 robotux StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code