]> granicus.if.org Git - clang/commitdiff
Clean up CodeGenFunction::EmitCastLValue to use the cast kind. Error
authorEli Friedman <eli.friedman@gmail.com>
Thu, 27 Aug 2009 21:19:33 +0000 (21:19 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 27 Aug 2009 21:19:33 +0000 (21:19 +0000)
out for user-defined conversions instead of crashing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80282 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp

index 75fc107d20e6d1ce76ac63c1891d08e6fd707624..0d45ce91853b004df66bb5fc831c5b06011a7bec 100644 (file)
@@ -1174,12 +1174,22 @@ LValue CodeGenFunction::EmitConditionalOperator(const ConditionalOperator* E) {
 LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
   // If this is an aggregate-to-aggregate cast, just use the input's address as
   // the lvalue.
-  if (getContext().hasSameUnqualifiedType(E->getType(),
-                                          E->getSubExpr()->getType()))
+  if (E->getCastKind() == CastExpr::CK_NoOp)
     return EmitLValue(E->getSubExpr());
 
+  // If this is an lvalue cast, treat it as a no-op.
+  // FIXME: We shouldn't need to check for this explicitly!
+  if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
+    if (ICE->isLvalueCast())
+      return EmitLValue(E->getSubExpr());
+
+  // FIXME: Implement this properly!
+  if (E->getCastKind() == CastExpr::CK_UserDefinedConversion)
+    return EmitUnsupportedLValue(E, "user-defined conversion");
+
   // Otherwise, we must have a cast from scalar to union.
-  assert(E->getType()->isUnionType() && "Expected scalar-to-union cast");
+  assert(E->getCastKind() == CastExpr::CK_ToUnion &&
+         "Expected scalar-to-union cast");
   
   // Casts are only lvalues when the source and destination types are the same.
   llvm::Value *Temp = CreateTempAlloca(ConvertType(E->getType()));