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

Oliver Hunt oliver at apple.com
Sat Dec 1 16:11:26 PST 2007


Author: oliver
Date: Sat Dec  1 18:11:25 2007
New Revision: 44495

URL: http://llvm.org/viewvc/llvm-project?rev=44495&view=rev
Log:
Support initalisers for more than just int-typed static variables.

We now use the CodeGenModule logic for generating the constant 
initialiser expression, so happily further initialiser fixes should 
automatically work for statics as well.


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

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

==============================================================================
--- cfe/trunk/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/CodeGen/CGDecl.cpp Sat Dec  1 18:11:25 2007
@@ -75,14 +75,11 @@
   llvm::Constant *Init = 0;
   if (D.getInit() == 0) {
     Init = llvm::Constant::getNullValue(LTy);
-  } 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);
+  } else {
+    Init = CGM.EmitGlobalInit(D.getInit());
   }
 
-  assert(Init && "FIXME: Support initializers");
+  assert(Init && "Unable to create initialiser for static decl");
   
   DMEntry = 
     new llvm::GlobalVariable(LTy, false, 

Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=44495&r1=44494&r2=44495&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Sat Dec  1 18:11:25 2007
@@ -275,9 +275,8 @@
   return 0;
 }
 
-llvm::Constant *CodeGenModule::EmitGlobalInit(const FileVarDecl *D,
-                                              llvm::GlobalVariable *GV) {
-  return GenerateConstantExpr(D->getInit(), *this);
+llvm::Constant *CodeGenModule::EmitGlobalInit(const Expr *Expression) {
+  return GenerateConstantExpr(Expression, *this);
 }
 
 void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
@@ -300,7 +299,7 @@
   }
 
   if (!Init)
-    Init = EmitGlobalInit(D, GV);
+    Init = EmitGlobalInit(D->getInit());
 
   assert(Init && "FIXME: Global variable initializers unimp!");
 

Modified: cfe/trunk/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.h?rev=44495&r1=44494&r2=44495&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/CodeGen/CodeGenModule.h Sat Dec  1 18:11:25 2007
@@ -30,6 +30,7 @@
   class ASTContext;
   class FunctionDecl;
   class Decl;
+  class Expr;
   class ValueDecl;
   class FileVarDecl;
   struct LangOptions;
@@ -76,8 +77,7 @@
   void EmitFunction(const FunctionDecl *FD);
   void EmitGlobalVar(const FileVarDecl *D);
   void EmitGlobalVarDeclarator(const FileVarDecl *D);
-  llvm::Constant *EmitGlobalInit(const FileVarDecl *D, 
-                                 llvm::GlobalVariable *GV);
+  llvm::Constant *EmitGlobalInit(const Expr *Expression);
   
   void PrintStats() {}
 };

Modified: cfe/trunk/test/CodeGen/staticinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/staticinit.c?rev=44495&r1=44494&r2=44495&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/staticinit.c (original)
+++ cfe/trunk/test/CodeGen/staticinit.c Sat Dec  1 18:11:25 2007
@@ -1,5 +1,15 @@
 // RUN: clang -emit-llvm %s
 
+struct AStruct { 
+	int i;
+	char *s;
+	double d;
+};
+
 void f() {
   static int i = 42;
+  static int is[] = { 1, 2, 3, 4 };
+  static char* str = "forty-two";
+  static char* strs[] = { "one", "two", "three", "four" };
+  static struct AStruct myStruct = { 1, "two", 3.0 };
 }





More information about the cfe-commits mailing list