]> granicus.if.org Git - clang/commitdiff
teach codegen to handle noop casts as lvalues.
authorChris Lattner <sabre@nondot.org>
Wed, 18 Mar 2009 04:02:57 +0000 (04:02 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 18 Mar 2009 04:02:57 +0000 (04:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67164 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/CodeGen/exprs.c

index 3ab85686752cbd3ef9b864af179d5ca0be726f5b..b3cf921bc57e36d9be2d53381c25533ee06fdc49 100644 (file)
@@ -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());
   }
 }
 
index 81742673c2aafe26c9ea7ba1cf70a7af0c313f35..db60b5a3301d8875c7d23326fa2a2a958b2c7b47 100644 (file)
@@ -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;
+}