summaryrefslogtreecommitdiffstats
path: root/clang/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-12-09 00:36:01 +0000
committerChris Lattner <sabre@nondot.org>2007-12-09 00:36:01 +0000
commit283d094b75a544120d5e30cc17258218e7646af5 (patch)
treefaec0fc16cf45c3fbc99b3e2041fe01213010216 /clang/CodeGen/CodeGenModule.cpp
parentad6094ddd37182381fe0c21b4abbccf0b6a5a948 (diff)
downloadbcm5719-llvm-283d094b75a544120d5e30cc17258218e7646af5.tar.gz
bcm5719-llvm-283d094b75a544120d5e30cc17258218e7646af5.zip
implement support for functions that initialize globals.
llvm-svn: 44730
Diffstat (limited to 'clang/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/CodeGen/CodeGenModule.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/clang/CodeGen/CodeGenModule.cpp b/clang/CodeGen/CodeGenModule.cpp
index c5e6a26859e..ecabb814ae7 100644
--- a/clang/CodeGen/CodeGenModule.cpp
+++ b/clang/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) {
OpenPOWER on IntegriCloud