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

Chris Lattner clattner at apple.com
Tue Dec 11 20:41:39 PST 2007


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



More information about the cfe-dev mailing list