diff --git a/clang/CodeGen/CGDecl.cpp b/clang/CodeGen/CGDecl.cpp index 75a32854ab58..09a47b9e5e6b 100644 --- a/clang/CodeGen/CGDecl.cpp +++ b/clang/CodeGen/CGDecl.cpp @@ -75,9 +75,14 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const BlockVarDecl &D) { llvm::Constant *Init = 0; if (D.getInit() == 0) { Init = llvm::Constant::getNullValue(LTy); - } else - assert(0 && "FIXME: Support initializers"); - + } else if (D.getType()->isIntegerType()) { + llvm::APSInt Value(static_cast( + getContext().getTypeSize(D.getInit()->getType(), SourceLocation()))); + if (D.getInit()->isIntegerConstantExpr(Value, getContext())) + Init = llvm::ConstantInt::get(Value); + } + + assert(Init && "FIXME: Support initializers"); DMEntry = new llvm::GlobalVariable(LTy, false, diff --git a/clang/test/CodeGen/staticinit.c b/clang/test/CodeGen/staticinit.c new file mode 100644 index 000000000000..7411be32202c --- /dev/null +++ b/clang/test/CodeGen/staticinit.c @@ -0,0 +1,5 @@ +// RUN: clang -emit-llvm %s + +void f() { + static int i = 42; +}