diff options
author | Chris Lattner <sabre@nondot.org> | 2007-07-14 00:23:28 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-07-14 00:23:28 +0000 |
commit | 9d3b0e0001411cc54aef84947285f663dce960d6 (patch) | |
tree | 6328374dfeb37eebd908e7331989250eab1c5e6a /clang/CodeGen/CodeGenModule.cpp | |
parent | 6ee31f5df844f0fd52db01605742afbe552cdf1b (diff) | |
download | bcm5719-llvm-9d3b0e0001411cc54aef84947285f663dce960d6.tar.gz bcm5719-llvm-9d3b0e0001411cc54aef84947285f663dce960d6.zip |
Implement trivial integer initializers, like 'int X = 4;' for global
vars. Approach suggested by Keith.
llvm-svn: 39849
Diffstat (limited to 'clang/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/CodeGen/CodeGenModule.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/CodeGen/CodeGenModule.cpp b/clang/CodeGen/CodeGenModule.cpp index 4bf4b86bcb6..d091dd73eb5 100644 --- a/clang/CodeGen/CodeGenModule.cpp +++ b/clang/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. |