From: Devang Patel Date: Fri, 26 Oct 2007 17:50:58 +0000 (+0000) Subject: Code gen static initializer. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e40daa4e84fdd6b48c311951cb63b0838c5c23de;p=clang Code gen static initializer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43386 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CGDecl.cpp b/CodeGen/CGDecl.cpp index 75a32854ab..09a47b9e5e 100644 --- a/CodeGen/CGDecl.cpp +++ b/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/test/CodeGen/staticinit.c b/test/CodeGen/staticinit.c new file mode 100644 index 0000000000..7411be3220 --- /dev/null +++ b/test/CodeGen/staticinit.c @@ -0,0 +1,5 @@ +// RUN: clang -emit-llvm %s + +void f() { + static int i = 42; +}