We now use the CodeGenModule logic for generating the constant
initialiser expression, so happily further initialiser fixes should
automatically work for statics as well.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44495
91177308-0d34-0410-b5e6-
96231b3b80d8
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,
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) {
}
if (!Init)
- Init = EmitGlobalInit(D, GV);
+ Init = EmitGlobalInit(D->getInit());
assert(Init && "FIXME: Global variable initializers unimp!");
class ASTContext;
class FunctionDecl;
class Decl;
+ class Expr;
class ValueDecl;
class FileVarDecl;
struct LangOptions;
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() {}
};
// 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 };
}