[cfe-commits] r68593 - in /cfe/trunk/lib/CodeGen: CGBuiltin.cpp CGDecl.cpp CGExprConstant.cpp CodeGenModule.cpp CodeGenModule.h
Anders Carlsson
andersca at mac.com
Tue Apr 7 21:48:15 PDT 2009
Author: andersca
Date: Tue Apr 7 23:48:15 2009
New Revision: 68593
URL: http://llvm.org/viewvc/llvm-project?rev=68593&view=rev
Log:
Add a destination type argument to EmitConstantExpr. This will be used for when the destination has a reference type. (No functionality change yet)
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=68593&r1=68592&r2=68593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Apr 7 23:48:15 2009
@@ -66,7 +66,7 @@
switch (BuiltinID) {
default: break; // Handle intrinsics and libm functions below.
case Builtin::BI__builtin___CFStringMakeConstantString:
- return RValue::get(CGM.EmitConstantExpr(E, 0));
+ return RValue::get(CGM.EmitConstantExpr(E, E->getType(), 0));
case Builtin::BI__builtin_stdarg_start:
case Builtin::BI__builtin_va_start:
case Builtin::BI__builtin_va_end: {
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=68593&r1=68592&r2=68593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Apr 7 23:48:15 2009
@@ -121,7 +121,7 @@
DMEntry = GV;
if (D.getInit()) {
- llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), this);
+ llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), D.getType(), this);
// If constant emission failed, then this should be a C++ static
// initializer.
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=68593&r1=68592&r2=68593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Apr 7 23:48:15 2009
@@ -55,7 +55,9 @@
// GCC cast to union extension
if (E->getType()->isUnionType()) {
const llvm::Type *Ty = ConvertType(E->getType());
- return EmitUnion(CGM.EmitConstantExpr(E->getSubExpr(), CGF), Ty);
+ Expr *SubExpr = E->getSubExpr();
+ return EmitUnion(CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF),
+ Ty);
}
if (CGM.getContext().getCanonicalType(E->getSubExpr()->getType()) ==
CGM.getContext().getCanonicalType(E->getType())) {
@@ -91,7 +93,8 @@
unsigned i = 0;
bool RewriteType = false;
for (; i < NumInitableElts; ++i) {
- llvm::Constant *C = CGM.EmitConstantExpr(ILE->getInit(i), CGF);
+ Expr *Init = ILE->getInit(i);
+ llvm::Constant *C = CGM.EmitConstantExpr(Init, Init->getType(), CGF);
if (!C)
return 0;
RewriteType |= (C->getType() != ElemTy);
@@ -117,7 +120,7 @@
void InsertBitfieldIntoStruct(std::vector<llvm::Constant*>& Elts,
FieldDecl* Field, Expr* E) {
// Calculate the value to insert
- llvm::Constant *C = CGM.EmitConstantExpr(E, CGF);
+ llvm::Constant *C = CGM.EmitConstantExpr(E, Field->getType(), CGF);
if (!C)
return;
@@ -204,7 +207,8 @@
InsertBitfieldIntoStruct(Elts, *Field, ILE->getInit(EltNo));
} else {
unsigned FieldNo = CGM.getTypes().getLLVMFieldNo(*Field);
- llvm::Constant *C = CGM.EmitConstantExpr(ILE->getInit(EltNo), CGF);
+ llvm::Constant *C = CGM.EmitConstantExpr(ILE->getInit(EltNo),
+ Field->getType(), CGF);
if (!C) return 0;
RewriteType |= (C->getType() != Elts[FieldNo]->getType());
Elts[FieldNo] = C;
@@ -283,7 +287,8 @@
return llvm::ConstantArray::get(RetTy, Elts);
}
- return EmitUnion(CGM.EmitConstantExpr(ILE->getInit(0), CGF), Ty);
+ Expr *Init = ILE->getInit(0);
+ return EmitUnion(CGM.EmitConstantExpr(Init, Init->getType(), CGF), Ty);
}
llvm::Constant *EmitVectorInitialization(InitListExpr *ILE) {
@@ -299,7 +304,8 @@
// Copy initializer elements.
unsigned i = 0;
for (; i < NumInitableElts; ++i) {
- llvm::Constant *C = CGM.EmitConstantExpr(ILE->getInit(i), CGF);
+ Expr *Init = ILE->getInit(i);
+ llvm::Constant *C = CGM.EmitConstantExpr(Init, Init->getType(), CGF);
if (!C)
return 0;
Elts.push_back(C);
@@ -319,9 +325,10 @@
llvm::Constant *VisitInitListExpr(InitListExpr *ILE) {
if (ILE->getType()->isScalarType()) {
// We have a scalar in braces. Just use the first element.
- if (ILE->getNumInits() > 0)
- return CGM.EmitConstantExpr(ILE->getInit(0), CGF);
-
+ if (ILE->getNumInits() > 0) {
+ Expr *Init = ILE->getInit(0);
+ return CGM.EmitConstantExpr(Init, Init->getType(), CGF);
+ }
const llvm::Type* RetTy = CGM.getTypes().ConvertType(ILE->getType());
return llvm::Constant::getNullValue(RetTy);
}
@@ -463,6 +470,7 @@
} // end anonymous namespace.
llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
+ QualType DestType,
CodeGenFunction *CGF) {
Expr::EvalResult Result;
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=68593&r1=68592&r2=68593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr 7 23:48:15 2009
@@ -693,7 +693,7 @@
}
Init = llvm::Constant::getNullValue(InitTy);
} else {
- Init = EmitConstantExpr(D->getInit());
+ Init = EmitConstantExpr(D->getInit(), D->getType());
if (!Init) {
ErrorUnsupported(D, "static initializer");
QualType T = D->getInit()->getType();
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=68593&r1=68592&r2=68593&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue Apr 7 23:48:15 2009
@@ -256,7 +256,8 @@
/// EmitConstantExpr - Try to emit the given expression as a
/// constant; returns 0 if the expression cannot be emitted as a
/// constant.
- llvm::Constant *EmitConstantExpr(const Expr *E, CodeGenFunction *CGF = 0);
+ llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
+ CodeGenFunction *CGF = 0);
llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
const AnnotateAttr *AA, unsigned LineNo);
More information about the cfe-commits
mailing list