aboutsummaryrefslogtreecommitdiff
path: root/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-14 00:23:28 +0000
committerChris Lattner <sabre@nondot.org>2007-07-14 00:23:28 +0000
commit8f32f7189b12f67aa4a19bc7c3855b599980eca0 (patch)
treeb85e7ad5800221a5f13ab6d1f7570af661e92283 /CodeGen/CodeGenModule.cpp
parent32b266cff60737fedff00e8e721f3474533835ef (diff)
Implement trivial integer initializers, like 'int X = 4;' for global
vars. Approach suggested by Keith. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39849 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CodeGenModule.cpp')
-rw-r--r--CodeGen/CodeGenModule.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp
index 4bf4b86bcb..d091dd73eb 100644
--- a/CodeGen/CodeGenModule.cpp
+++ b/CodeGen/CodeGenModule.cpp
@@ -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 @@ void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
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.