[cfe-users] Question about libclang 4.0/3.9 compatibility.

Devin Hussey via cfe-users cfe-users at lists.llvm.org
Sun Nov 25 08:59:16 PST 2018


I am trying to make https://github.com/AnacondaRecipes/c99-to-c89
(obviously a c99 to c89 converter) work with newer Clang versions.

I mainly want to use it so we can use full C99 features with an old
version of gcc (2.95), which we are stuck with for a project.

Something between 3.9 and 4.0 broke the program, and when it tries to
convert compound literals, it fails to place braces properly.
I was unable to find anything on an api change in the changelogs, and
manually fiddling with the code was only helping a little bit, and I
feel that I am just going to break something.

Code to convert:
    extern void foo(int[]);
    void bar(void)
    {
         foo((int []) { 1, 2, 3 });
    }

Expected output (from clang 3.9):
    extern void foo(int[]);
    void bar(void)
    {
         {   int tmp__0 [] =   { 1, 2, 3 }; foo(tmp__0                   ); }
    }

or, formatted,
    extern void foo(int[]);
    void bar(void)
    {
        {
            int tmp__0[] = { 1, 2, 3 };
            foo(tmp__0);
        }
    }

Actual output (from clang versions 4-7, all the same output):
    extern void foo(int[]);
    void bar(void)
    {
         {   int tmp__0 [] =   { 1, 2, 3; foo(tmp__0                  } });
    }

or, formatted,
    extern void foo(int[]);
    void bar(void)
    {
        {
            int tmp__0[] = { 1, 2, 3;
            foo(tmp__0
            }
        });
    }

Note the lack of closing braces on the initializer list and the two
closing braces in the parentheses.

Everything else seems to work fine.

For the output of the first unit test, I have it on this gist:
https://gist.github.com/easyaspi314/f38b379e2af2fe27d1014c2b3010f914

Can someone help me with this?



More information about the cfe-users mailing list