Hi. I noticed tinycc doesn't correctly scope enumerators constants defined in the argument parentheses to switches/whiles/do-whiles and ifs.

Example below:

   #include <stdio.h>
   enum{ in = 0};
   #define myassert(X) do{ if(!X) printf("%d: assertion failed\n",
   __LINE__); }while(0)
   int main(){
        {
            myassert(!in);
            if(sizeof(enum{in=1})) myassert(in);
            myassert(!in); //OOPS
        }
        {
            myassert(!in);
            switch(sizeof(enum{in=1})) { default: myassert(in); }
            myassert(!in); //OOPS
        }
        {
            myassert(!in);
            while(sizeof(enum{in=1})) { myassert(in); break; }
            myassert(!in); //OOPS
        }
        {
            myassert(!in);
            do{ myassert(!in);}while(0*sizeof(enum{in=1}));
            myassert(!in); //OOPS
        }

        {
            myassert(!in);
            for(sizeof(enum{in=1});;){ myassert(in); break; }
            myassert(!in); //OK
        }
        {
            myassert(!in);
            for(;;sizeof(enum{in=1})){ myassert(in); break; }
            myassert(!in); //OK
        }
        {
            myassert(!in);
            for(;sizeof(enum{in=1});){ myassert(in); break; }
            myassert(!in); //OK
        }

   }

Fors are done correctly.

Because I'm weird and actually make use of these scoping rules, I would welcome tinycc doing this as prescribed.

Surrounding the code parsing these statements with new_scope(&o); and prev_scope(&o,0); appears to fix the problem without introducing test breakage except when it's done for ifs -- then I get breakage in tests2.122 -- vla_reuse.

I've pushed the fixes for the rest for now (lucky for me, I don't actually need this weird feature with ifs -- just whiles/do-whiles/switches and fors).

If I've done something stupid or if anybody knows how to make it work for ifs too without breaking the vla test, then please let me know.

Cheers,
Petr Skocik

_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to