clang -emit-llvm infinite recursion

Hi,

If I run clang on alex.i, with -emit-llvm option I get infinite
recursion, if I run without it,
it gives me errors [because struct initializers are not implemented,
the errors are ok].
I know that struct initializers are not yet implemented (right?), but
then -emit-llvm should give an error if it can't handle something, and
not infinite recursion.

I would have used bugpoint to create a reduced testcase, but I don't
know how to use it with clang, is it possible to use it?

alex.i is available from here (it is a bit large):
http://edwintorok.googlepages.com/alex.i

$ clang -emit-llvm alex.i
alex.i:661:19: warning: declaration does not declare anything
    __extension__ union
                  ^
Segmentation fault

P.S.: I hope you don't misinterpret my mails, I want to help the
development of clang/llvm by submitting the issues I encounter with
it. That doesn't mean I don't like clang/llvm :wink:

(gdb) r -emit-llvm alex.i
Starting program: /usr/local/bin/clang -emit-llvm alex.i
warning: no loadable sections found in added symbol-file
system-supplied DSO at 0x7fffd3bfd000
[Thread debugging using libthread_db enabled]
[New Thread 0x2b94d6fade50 (LWP 6242)]
alex.i:661:19: warning: declaration does not declare anything
    __extension__ union
                  ^

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x2b94d6fade50 (LWP 6242)]
0x00000000005ef179 in clang::QualType::getCanonicalType (this=Cannot
access memory at address 0x7fffd3321ff8
) at /home/edwin/llvm-svn/llvm/tools/clang/AST/../include/clang/AST/Type.h:894
...
#163 0x00000000005edc4b in clang::CodeGen::CodeGenTypes::ConvertType
(this=0xac8940, T={ThePtr = 11475776}) at CodeGenTypes.cpp:
80
#164 0x00000000005ee0f2 in clang::CodeGen::CodeGenTypes::ConvertType
(this=0xac8940, T={ThePtr = 11475728}) at CodeGenTypes.cpp:
164
#165 0x00000000005edc4b in clang::CodeGen::CodeGenTypes::ConvertType
(this=0xac8940, T={ThePtr = 11475776}) at CodeGenTypes.cpp:
80
#166 0x00000000005ee0f2 in clang::CodeGen::CodeGenTypes::ConvertType
(this=0xac8940, T={ThePtr = 11475728}) at CodeGenTypes.cpp:
164
...
Quit

--Edwin

Hi,

Hi Török,

If I run clang on alex.i, with -emit-llvm option I get infinite
recursion, if I run without it,
it gives me errors [because struct initializers are not implemented,
the errors are ok].

Ok, I'll follow up on the -fsyntax-only errors in a separate email.

I know that struct initializers are not yet implemented (right?), but
then -emit-llvm should give an error if it can't handle something, and
not infinite recursion.

The issue in this case is that clang -emit-llvm doesn't handle recursive structs at all yet. Hopefully this should be resolved in the next couple weeks. Right now -emit-llvm is only really useful for the most trivial programs.

Devang, we need to add a map to CodeGenTypes to keep track of already emitted types, as llvm-gcc does. This is a little tricky because it has to use the PATypeHandle machinery like llvm-gcc.

I would have used bugpoint to create a reduced testcase, but I don't
know how to use it with clang, is it possible to use it?

Nope, bugpoint can't handle this. It should reproduce with something like this though:

struct S {
   struct S * F;
};

struct S x;

P.S.: I hope you don't misinterpret my mails, I want to help the
development of clang/llvm by submitting the issues I encounter with
it. That doesn't mean I don't like clang/llvm :wink:

We welcome the help!

-Chris

There are two issues here. The first warning you are getting (above) is due to us not handling anonymous unions like GCC does yet. Since this is just a warning, I don't consider it to be a high priority right now.

The other issue is the array initialization case you hit. Reduced, it looks like:

unsigned char asso_values = { 34 };
int test() { return asso_values[0]; }

$ clang t.c
t.c:3:21: error: illegal subscript of non-object type 'unsigned char (*)'
int test() { return asso_values[0]; }

I'm not sure where the failure is here. Steve, should this set the type of asso_values to an array of size 1? Or should the array type decay to pointer to element? Is this something that would be reasonably easy to fix?

-Chris

Hi,

Iit gives me errors [because struct initializers are not implemented,
the errors are ok].
I know that struct initializers are not yet implemented (right?), but
then -emit-llvm should give an error if it can't handle something, and
not infinite recursion.

I would have used bugpoint to create a reduced testcase, but I don't
know how to use it with clang, is it possible to use it?

alex.i is available from here (it is a bit large):
http://edwintorok.googlepages.com/alex.i

$ clang -emit-llvm alex.i
alex.i:661:19: warning: declaration does not declare anything
   __extension__ union
                 ^

There are two issues here. The first warning you are getting (above)
is due to us not handling anonymous unions like GCC does yet. Since
this is just a warning, I don't consider it to be a high priority
right now.

The other issue is the array initialization case you hit. Reduced,
it looks like:

unsigned char asso_values = { 34 };
int test() { return asso_values[0]; }

$ clang t.c
t.c:3:21: error: illegal subscript of non-object type 'unsigned char
(*)'
int test() { return asso_values[0]; }

I'm not sure where the failure is here. Steve, should this set the
type of asso_values to an array of size 1?

Yes. Looks like a trivial bug.

I'll fix this tonight...

Snaroff

Thanks, clang -fsyntax-only doesn't show the error now.

--Edwin