[LLVMbugs] [Bug 2971] New: &((char*)0)[0] not regarded as static initializer

Neil Booth neil at daikokuya.co.uk
Wed Oct 29 05:51:49 PDT 2008


bugzilla-daemon at cs.uiuc.edu wrote:-

> http://llvm.org/bugs/show_bug.cgi?id=2971
> 
>            Summary: &((char*)0)[0] not regarded as static initializer
>            Product: clang
>            Version: unspecified
>           Platform: All
>         OS/Version: All
>             Status: NEW
>           Severity: normal
>           Priority: P2
>          Component: LLVM Codegen
>         AssignedTo: unassignedbugs at nondot.org
>         ReportedBy: nunoplopes at sapo.pt
>                 CC: llvmbugs at cs.uiuc.edu
> 
> 
> The following code crashes clang:
> 
> typedef struct FuncDef FuncDef;
> struct FuncDef {};
> 
> void sqlite3RegisterDateTimeFunctions(void){
>   static FuncDef aDateTimeFuncs = {((void*)&((char*)0)[0])};
> }
> 
> 
> With the error message:
> clang: CGDecl.cpp:86: llvm::GlobalValue*
> clang::CodeGen::CodeGenFunction::GenerateStaticBlockVarDecl(const
> clang::VarDecl&, bool, const char*): Assertion
> `getContext().getLangOptions().CPlusPlus && "only C++ supports non-constant
> static initializers!"' failed.
> 
> (I'm not sure if this a duplicate or not. I have the strange feeling it's not
> the first time I'm seeing this bug..)

It's not a bug; casts must be to arithmetic type (it would be nice if
Clang were more explicit about the real problem, rather than just saying
it's no good...).

Neil.



More information about the llvm-bugs mailing list