[cfe-commits] r43386 - in /cfe/trunk: CodeGen/CGDecl.cpp test/CodeGen/staticinit.c

Devang Patel dpatel at apple.com
Fri Oct 26 10:50:58 PDT 2007


Author: dpatel
Date: Fri Oct 26 12:50:58 2007
New Revision: 43386

URL: http://llvm.org/viewvc/llvm-project?rev=43386&view=rev
Log:

Code gen static initializer.

Added:
    cfe/trunk/test/CodeGen/staticinit.c
Modified:
    cfe/trunk/CodeGen/CGDecl.cpp

Modified: cfe/trunk/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGDecl.cpp?rev=43386&r1=43385&r2=43386&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/CodeGen/CGDecl.cpp Fri Oct 26 12:50:58 2007
@@ -75,9 +75,14 @@
   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, 

Added: cfe/trunk/test/CodeGen/staticinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/staticinit.c?rev=43386&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/staticinit.c (added)
+++ cfe/trunk/test/CodeGen/staticinit.c Fri Oct 26 12:50:58 2007
@@ -0,0 +1,5 @@
+// RUN: clang -emit-llvm %s
+
+void f() {
+  static int i = 42;
+}





More information about the cfe-commits mailing list