]> granicus.if.org Git - clang/commitdiff
Code gen static initializer.
authorDevang Patel <dpatel@apple.com>
Fri, 26 Oct 2007 17:50:58 +0000 (17:50 +0000)
committerDevang Patel <dpatel@apple.com>
Fri, 26 Oct 2007 17:50:58 +0000 (17:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43386 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGDecl.cpp
test/CodeGen/staticinit.c [new file with mode: 0644]

index 75a32854ab5870c938939a0113606d903c68466f..09a47b9e5e6b2da33e21acbed6181e51eaf08050 100644 (file)
@@ -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<uint32_t>(
+      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 (file)
index 0000000..7411be3
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: clang -emit-llvm %s
+
+void f() {
+  static int i = 42;
+}