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 | 63d06ab65a9b6f3f2dced57345848adf289bdeb7 (patch) | |
tree | 1560f9d4ba2057cffd6d5a82b11c09d9ccfc2d60 | |
parent | dc78bd9f79960a9ef0589a7831248880305d826e (diff) | |
download | bcm5719-llvm-63d06ab65a9b6f3f2dced57345848adf289bdeb7.tar.gz bcm5719-llvm-63d06ab65a9b6f3f2dced57345848adf289bdeb7.zip |
teach codegen to handle noop casts as lvalues.
llvm-svn: 67164
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 13 | ||||
-rw-r--r-- | clang/test/CodeGen/exprs.c | 8 |
2 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 3ab85686752..b3cf921bc57 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/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/clang/test/CodeGen/exprs.c b/clang/test/CodeGen/exprs.c index 81742673c2a..db60b5a3301 100644 --- a/clang/test/CodeGen/exprs.c +++ b/clang/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; +} |