[cfe-commits] r44730 - in /cfe/trunk: CodeGen/CodeGenModule.cpp test/CodeGen/globalinit.c
Chris Lattner
sabre at nondot.org
Sat Dec 8 16:36:02 PST 2007
Author: lattner
Date: Sat Dec 8 18:36:01 2007
New Revision: 44730
URL: http://llvm.org/viewvc/llvm-project?rev=44730&view=rev
Log:
implement support for functions that initialize globals.
Modified:
cfe/trunk/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/globalinit.c
Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=44730&r1=44729&r2=44730&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Sat Dec 8 18:36:01 2007
@@ -202,8 +202,8 @@
/// 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 @@
}
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 @@
// 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) {
Modified: cfe/trunk/test/CodeGen/globalinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/globalinit.c?rev=44730&r1=44729&r2=44730&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/globalinit.c (original)
+++ cfe/trunk/test/CodeGen/globalinit.c Sat Dec 8 18:36:01 2007
@@ -12,3 +12,6 @@
extern int y[];
void *g = y;
+int latin_ptr2len (char *p);
+int (*mb_ptr2len) (char *p) = latin_ptr2len;
+
More information about the cfe-commits
mailing list