diff options
author | Chris Lattner <sabre@nondot.org> | 2007-12-09 00:36:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-12-09 00:36:01 +0000 |
commit | 2ea81a84e21c23914a4189e8b4002149fb7cdf43 (patch) | |
tree | c9e57c2bc4e6d94bb41f1e4bbd5320182ab45b20 /CodeGen/CodeGenModule.cpp | |
parent | 44fe49c9ccf29b8e9b66ce1f2375be6ec591c03c (diff) |
implement support for functions that initialize globals.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44730 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CodeGenModule.cpp')
-rw-r--r-- | CodeGen/CodeGenModule.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp index c5e6a26859..ecabb814ae 100644 --- a/CodeGen/CodeGenModule.cpp +++ b/CodeGen/CodeGenModule.cpp @@ -202,8 +202,8 @@ static llvm::Constant *GenerateConversionToBool(llvm::Constant *Expression, /// GenerateConstantCast - Generates a constant cast to convert the Expression /// into the Target type. static llvm::Constant *GenerateConstantCast(const Expr *Expression, - QualType Target, - CodeGenModule &CGM) { + QualType Target, + CodeGenModule &CGM) { CodeGenTypes& Types = CGM.getTypes(); QualType Source = Expression->getType().getCanonicalType(); Target = Target.getCanonicalType(); @@ -346,6 +346,14 @@ static llvm::Constant *GenerateConstantExpr(const Expr *Expression, } switch (Expression->getStmtClass()) { + default: break; // default emits a warning and returns bogus value. + case Stmt::DeclRefExprClass: { + const ValueDecl *Decl = cast<DeclRefExpr>(Expression)->getDecl(); + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Decl)) + return CGM.GetAddrOfFunctionDecl(FD, false); + break; + } + // Generate constant for floating point literal values. case Stmt::FloatingLiteralClass: { const FloatingLiteral *FLiteral = cast<FloatingLiteral>(Expression); @@ -416,11 +424,10 @@ static llvm::Constant *GenerateConstantExpr(const Expr *Expression, // an array or struct. case Stmt::InitListExprClass: return GenerateAggregateInit(cast<InitListExpr>(Expression), CGM); - - default: - CGM.WarnUnsupported(Expression, "initializer"); - return llvm::UndefValue::get(Types.ConvertType(type)); } + + CGM.WarnUnsupported(Expression, "initializer"); + return llvm::UndefValue::get(Types.ConvertType(type)); } llvm::Constant *CodeGenModule::EmitGlobalInit(const Expr *Expression) { |