[cfe-commits] r94964 - in /cfe/trunk/lib: CodeGen/CGCall.cpp CodeGen/CGDecl.cpp CodeGen/CGExpr.cpp CodeGen/CodeGenFunction.h Sema/SemaInit.cpp
Anders Carlsson
andersca at mac.com
Sun Jan 31 10:34:53 PST 2010
Author: andersca
Date: Sun Jan 31 12:34:51 2010
New Revision: 94964
URL: http://llvm.org/viewvc/llvm-project?rev=94964&view=rev
Log:
Start creating CXXBindReferenceExpr nodes when binding complex types to references.
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaInit.cpp
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=94964&r1=94963&r2=94964&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Sun Jan 31 12:34:51 2010
@@ -802,6 +802,9 @@
}
RValue CodeGenFunction::EmitCallArg(const Expr *E, QualType ArgType) {
+ if (const CXXBindReferenceExpr *BE = dyn_cast<CXXBindReferenceExpr>(E))
+ return RValue::get(EmitCXXBindReferenceExpr(BE));
+
if (ArgType->isReferenceType())
return EmitReferenceBindingToExpr(E, ArgType);
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=94964&r1=94963&r2=94964&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sun Jan 31 12:34:51 2010
@@ -507,6 +507,10 @@
Builder.CreateCall4(CGM.getMemCpyFn(), Loc, SrcPtr, SizeVal, AlignVal);
}
+ } else if (const CXXBindReferenceExpr *BE =
+ dyn_cast<CXXBindReferenceExpr>(Init)) {
+ llvm::Value *V = EmitCXXBindReferenceExpr(BE);
+ EmitStoreOfScalar(V, Loc, /*Volatile=*/false, Ty);
} else if (Ty->isReferenceType()) {
RValue RV = EmitReferenceBindingToExpr(Init, Ty, /*IsInitializer=*/true);
EmitStoreOfScalar(RV.getScalarVal(), Loc, false, Ty);
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=94964&r1=94963&r2=94964&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sun Jan 31 12:34:51 2010
@@ -92,9 +92,31 @@
IsInitializer);
}
+llvm::Value *
+CodeGenFunction::EmitCXXBindReferenceExpr(const CXXBindReferenceExpr *E) {
+ QualType T = E->getType();
+ assert(T->isAnyComplexType() && "FIXME: Unhandled bind expression!");
+
+ const Expr *SubExpr = E->getSubExpr();
+
+ if (!E->requiresTemporaryCopy())
+ return EmitLValue(SubExpr).getAddress();
+
+ llvm::Value *Value = CreateTempAlloca(ConvertTypeForMem(T), "reftmp");
+
+ if (T->isAnyComplexType())
+ EmitComplexExprIntoAddr(SubExpr, Value, /*DestIsVolatile=*/false);
+ else
+ assert(false && "Unhandled bind expression");
+
+ return Value;
+}
+
RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
QualType DestType,
bool IsInitializer) {
+ assert(!E->getType()->isAnyComplexType() &&
+ "Should not use this function for complex types!");
bool ShouldDestroyTemporaries = false;
unsigned OldNumLiveTemporaries = 0;
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=94964&r1=94963&r2=94964&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sun Jan 31 12:34:51 2010
@@ -1116,6 +1116,8 @@
RValue EmitReferenceBindingToExpr(const Expr* E, QualType DestType,
bool IsInitializer = false);
+ llvm::Value *EmitCXXBindReferenceExpr(const CXXBindReferenceExpr *E);
+
//===--------------------------------------------------------------------===//
// Expression Emission
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=94964&r1=94963&r2=94964&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sun Jan 31 12:34:51 2010
@@ -3297,15 +3297,31 @@
// Check exception specifications
if (S.CheckExceptionSpecCompatibility(CurInitExpr, DestType))
return S.ExprError();
+
+ // FIXME: We should do this for all types.
+ if (DestType->isAnyComplexType()) {
+ CurInit =
+ S.Owned(CXXBindReferenceExpr::Create(S.Context,
+ CurInit.takeAs<Expr>(),
+ /*ExtendsLifetime=*/false,
+ /*RequiresTemporaryCopy=*/false));
+ }
+
break;
-
+
case SK_BindReferenceToTemporary:
// Check exception specifications
if (S.CheckExceptionSpecCompatibility(CurInitExpr, DestType))
return S.ExprError();
- // FIXME: At present, we have no AST to describe when we need to make a
- // temporary to bind a reference to. We should.
+ // FIXME: We should do this for all types.
+ if (DestType->isAnyComplexType()) {
+ CurInit =
+ S.Owned(CXXBindReferenceExpr::Create(S.Context,
+ CurInit.takeAs<Expr>(),
+ /*ExtendsLifetime=*/false,
+ /*RequiresTemporaryCopy=*/true));
+ }
break;
case SK_UserConversion: {
More information about the cfe-commits
mailing list