[cfe-commits] r39849 - /cfe/trunk/CodeGen/CodeGenModule.cpp

Chris Lattner sabre at nondot.org
Fri Jul 13 17:23:28 PDT 2007


Author: lattner
Date: Fri Jul 13 19:23:28 2007
New Revision: 39849

URL: http://llvm.org/viewvc/llvm-project?rev=39849&view=rev
Log:
Implement trivial integer initializers, like 'int X = 4;' for global
vars.  Approach suggested by Keith.

Modified:
    cfe/trunk/CodeGen/CodeGenModule.cpp

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

==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Fri Jul 13 19:23:28 2007
@@ -16,6 +16,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 #include "llvm/GlobalVariable.h"
@@ -63,12 +64,16 @@
     return;
 
   // Otherwise, convert the initializer, or use zero if appropriate.
-  llvm::Constant *Init;
-  if (D->getInit() == 0)
+  llvm::Constant *Init = 0;
+  if (D->getInit() == 0) {
     Init = llvm::Constant::getNullValue(GV->getType()->getElementType());
-  else
-    assert(D->getInit() == 0 && "FIXME: Global variable initializers unimp!");
-    
+  } else if (D->getType()->isIntegerType()) {
+    llvm::APSInt Value(getContext().getTypeSize(D->getInit()->getType()));
+    if (D->getInit()->isIntegerConstantExpr(Value))
+      Init = llvm::ConstantInt::get(Value);
+  }
+  assert(Init && "FIXME: Global variable initializers unimp!");
+
   GV->setInitializer(Init);
   
   // Set the llvm linkage type as appropriate.





More information about the cfe-commits mailing list