diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-18 04:02:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-18 04:02:57 +0000 |
commit | c3953a61f7e2a9919ce18d418f8b26a8612e87f2 (patch) | |
tree | 9e2ac5ddcca270b2a3eadc69d7479cfe79cd7d23 | |
parent | 99c7622d1f673e8929196cc6eec7825a42622d5f (diff) |
teach codegen to handle noop casts as lvalues.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67164 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 13 | ||||
-rw-r--r-- | test/CodeGen/exprs.c | 8 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 3ab8568675..b3cf921bc5 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -179,6 +179,19 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) { return EmitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E)); case Expr::ChooseExprClass: return EmitLValue(cast<ChooseExpr>(E)->getChosenSubExpr(getContext())); + case Expr::ImplicitCastExprClass: + case Expr::CStyleCastExprClass: + case Expr::CXXFunctionalCastExprClass: + case Expr::CXXStaticCastExprClass: + case Expr::CXXDynamicCastExprClass: + case Expr::CXXReinterpretCastExprClass: + case Expr::CXXConstCastExprClass: + // Casts are only lvalues when the source and destination types are the + // same. + assert(getContext().hasSameUnqualifiedType(E->getType(), + cast<CastExpr>(E)->getSubExpr()->getType()) && + "Type changing cast is not an lvalue"); + return EmitLValue(cast<CastExpr>(E)->getSubExpr()); } } diff --git a/test/CodeGen/exprs.c b/test/CodeGen/exprs.c index 81742673c2..db60b5a330 100644 --- a/test/CodeGen/exprs.c +++ b/test/CodeGen/exprs.c @@ -58,4 +58,12 @@ void f0(void (*fp)(void), void (*fp2)(void)) { int x = fp - fp2; } +// noop casts as lvalues. +struct X { + int Y; +}; +struct X foo(); +int bar() { + return ((struct X)foo()).Y + 1; +} |