[cfe-commits] r55758 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h test/CodeGen/struct.c
Daniel Dunbar
daniel at zuster.org
Wed Sep 3 20:20:17 PDT 2008
Author: ddunbar
Date: Wed Sep 3 22:20:13 2008
New Revision: 55758
URL: http://llvm.org/viewvc/llvm-project?rev=55758&view=rev
Log:
Implement codegen of aggregates as lvalues in binary expressions,
e.g. "(a = b).somefield".
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGen/struct.c
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=55758&r1=55757&r2=55758&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Sep 3 22:20:13 2008
@@ -99,6 +99,8 @@
switch (E->getStmtClass()) {
default: return EmitUnsupportedLValue(E, "l-value expression");
+ case Expr::BinaryOperatorClass:
+ return EmitBinaryOperatorLValue(cast<BinaryOperator>(E));
case Expr::CallExprClass: return EmitCallExprLValue(cast<CallExpr>(E));
case Expr::DeclRefExprClass: return EmitDeclRefLValue(cast<DeclRefExpr>(E));
case Expr::ParenExprClass:return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
@@ -738,7 +740,7 @@
dyn_cast<const FunctionDecl>(DRExpr->getDecl()))
if (unsigned builtinID = FDecl->getIdentifier()->getBuiltinID())
return EmitBuiltinExpr(builtinID, E);
-
+
llvm::Value *Callee = EmitScalarExpr(E->getCallee());
return EmitCallExpr(Callee, E->getCallee()->getType(),
E->arg_begin(), E->arg_end());
@@ -752,6 +754,18 @@
return EmitCallExpr(Callee, FnExpr->getType(), ArgBeg, ArgEnd);
}
+LValue CodeGenFunction::EmitBinaryOperatorLValue(const BinaryOperator *E) {
+ // Can only get l-value for binary operator expressions which are a
+ // simple assignment of aggregate type.
+ if (E->getOpcode() != BinaryOperator::Assign)
+ return EmitUnsupportedLValue(E, "binary l-value expression");
+
+ llvm::Value *Temp = CreateTempAlloca(ConvertType(E->getType()));
+ EmitAggExpr(E, Temp, false);
+ // FIXME: Are these qualifiers correct?
+ return LValue::MakeAddr(Temp, E->getType().getCVRQualifiers());
+}
+
LValue CodeGenFunction::EmitCallExprLValue(const CallExpr *E) {
// Can only get l-value for call expression returning aggregate type
RValue RV = EmitCallExpr(E);
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=55758&r1=55757&r2=55758&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Sep 3 22:20:13 2008
@@ -282,6 +282,8 @@
void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty);
// Note: only availabe for agg return types
+ LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
+ // Note: only availabe for agg return types
LValue EmitCallExprLValue(const CallExpr *E);
LValue EmitDeclRefLValue(const DeclRefExpr *E);
Modified: cfe/trunk/test/CodeGen/struct.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/struct.c?rev=55758&r1=55757&r2=55758&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/struct.c (original)
+++ cfe/trunk/test/CodeGen/struct.c Wed Sep 3 22:20:13 2008
@@ -69,7 +69,6 @@
int location;
int length;
} range;
-
extern range f6();
void f7()
{
@@ -166,3 +165,27 @@
struct __attribute__((packed)) SS { long double a; char b; } SS;
+
+/* As lvalue */
+
+int f15() {
+ extern range f15_ext();
+ return f15_ext().location;
+}
+
+range f16() {
+ extern rangepair f16_ext();
+ return f16_ext().range1;
+}
+
+int f17() {
+ extern range f17_ext();
+ range r;
+ return (r = f17_ext()).location;
+}
+
+range f18() {
+ extern rangepair f18_ext();
+ rangepair rp;
+ return (rp = f18_ext()).range1;
+}
More information about the cfe-commits
mailing list