tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Fixing nonconformant scoping


From: Petr Skocik
Subject: [Tinycc-devel] Fixing nonconformant scoping
Date: Sun, 5 Mar 2023 22:49:36 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]