[cfe-commits] r67164 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGen/exprs.c

Chris Lattner sabre at nondot.org
Tue Mar 17 21:03:01 PDT 2009


Author: lattner
Date: Tue Mar 17 23:02:57 2009
New Revision: 67164

URL: http://llvm.org/viewvc/llvm-project?rev=67164&view=rev
Log:
teach codegen to handle noop casts as lvalues.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGen/exprs.c

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=67164&r1=67163&r2=67164&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Mar 17 23:02:57 2009
@@ -179,6 +179,19 @@
     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());
   }
 }
 

Modified: cfe/trunk/test/CodeGen/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exprs.c?rev=67164&r1=67163&r2=67164&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/exprs.c (original)
+++ cfe/trunk/test/CodeGen/exprs.c Tue Mar 17 23:02:57 2009
@@ -58,4 +58,12 @@
   int x = fp - fp2;
 }
 
+// noop casts as lvalues.
+struct X {
+  int Y;
+};
+struct X foo();
+int bar() {
+  return ((struct X)foo()).Y + 1;
+}
 





More information about the cfe-commits mailing list