aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2007-10-26 17:50:58 +0000
committerDevang Patel <dpatel@apple.com>2007-10-26 17:50:58 +0000
commite40daa4e84fdd6b48c311951cb63b0838c5c23de (patch)
tree67558cc9f0324a60c74174029b669e50bc206160
parent636c3d04673da8c8605d7e45640a2ff7aec648f1 (diff)
Code gen static initializer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43386 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--CodeGen/CGDecl.cpp11
-rw-r--r--test/CodeGen/staticinit.c5
2 files changed, 13 insertions, 3 deletions
diff --git a/CodeGen/CGDecl.cpp b/CodeGen/CGDecl.cpp
index 75a32854ab..09a47b9e5e 100644
--- a/CodeGen/CGDecl.cpp
+++ b/CodeGen/CGDecl.cpp
@@ -75,9 +75,14 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const BlockVarDecl &D) {
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,
diff --git a/test/CodeGen/staticinit.c b/test/CodeGen/staticinit.c
new file mode 100644
index 0000000000..7411be3220
--- /dev/null
+++ b/test/CodeGen/staticinit.c
@@ -0,0 +1,5 @@
+// RUN: clang -emit-llvm %s
+
+void f() {
+ static int i = 42;
+}