[cfe-dev] Function pointers in structs in arrays codegen assert

Oliver Hunt oliver at apple.com
Tue Dec 11 20:53:42 PST 2007


Yeah the ILE with type void screws with compound initialisers -- eg  
struct of structs, array of structs, etc.
Broadly speaking the global struct initialiser logic (at least)  
should be able to handle these once the ILE
has the correct type.
Unfortunately that doesn't resolve the problem that C apparently  
allows the ILE's for initialising arrays of
structs, etc to be flattened. eg.
struct S {int a; int b;}
struct S foo[] = {{1,2}, {3,4}};
struct S bar[] = {1, 2, 3, 4};

foo and bar are both valid -- the initialiser logic will hork itself  
in that case.

--Oliver

On 11/12/2007, at 8:41 PM, Chris Lattner wrote:

>
> On Dec 10, 2007, at 6:51 PM, Keith Bauer wrote:
>
>> It's fine for function pointers in global arrays, and function
>> pointers in global structs, just not the combination...
>>
>> CookieJar:Desktop keith$ clang -emit-llvm fptrinit.c
>> Assertion failed: (ILE->getType()->isArrayType() ||
>> ILE->getType()->isStructureType()), function GenerateAggregateInit,
>> file CodeGenModule.cpp, line 283.
>
> This looks like a sema bug.  The init list expr is getting type
> "void", which is clearly wrong :)
>
> typedef void (* F)(void);
> extern void foo(void);
>
> struct S { F f; };
> void bar() {
>    struct S a[1] = { { foo } };
> }
>
> void bar()
> (CompoundStmt 0x8061c0 <t.c:5:12, line:7:1>
>    (DeclStmt 0x8061b0 <:0:0>
>      0x806100 "struct S a[1] =
>        (InitListExpr 0x806180 <t.c:6:19, col:29> 'struct S [1]'
>          (InitListExpr 0x806150 <col:21, col:27> 'void'
>            (DeclRefExpr 0x806130 <col:23> 'void (void)'
> FunctionDecl='foo' 0x806020)))"
>
> Steve, please take a look.  Incidentally, it looks like the
> sourcerange on the declstmt is wrong.
>
> -Chris
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list