]> granicus.if.org Git - clang/commitdiff
L-value to r-value conversion is not ready for prime-time.
authorJohn McCall <rjmccall@apple.com>
Tue, 30 Nov 2010 17:58:55 +0000 (17:58 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 30 Nov 2010 17:58:55 +0000 (17:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120433 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
include/clang/AST/OperationKinds.h
lib/AST/Expr.cpp
lib/Checker/GRExprEngine.cpp
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGExprAgg.cpp
lib/CodeGen/CGExprScalar.cpp
lib/Sema/SemaExpr.cpp

index 4babbc476b20b1bf170d22bddd7b6725d2f4baf0..041446d6895da8de874889bccc3c6fee470be2ab 100644 (file)
@@ -2055,7 +2055,6 @@ private:
       // fallthrough to check for null base path
 
     case CK_Dependent:
-    case CK_LValueToRValue:
     case CK_NoOp:
     case CK_PointerToBoolean:
     case CK_IntegralToBoolean:
index 2ced0c9c719e00242021d9bba5b78c0daff8c314..cce351a770768c139ba448827595a6ceae61514c 100644 (file)
@@ -43,11 +43,6 @@ enum CastKind {
   /// reinterpret_casts of l-value expressions to reference types.
   ///    bool b; reinterpret_cast<char&>(b) = 'a';
   CK_LValueBitCast,
-  
-  /// CK_LValueToRValue - A conversion which causes the extraction of
-  /// an r-value from the operand gl-value.  The result of an r-value
-  /// conversion is always unqualified.
-  CK_LValueToRValue,
     
   /// CK_NoOp - A conversion which does not affect the type other than
   /// (possibly) adding qualifiers.
index 6e56603c53e63b6fdc4906823e5cdc8211c1804d..3a112a7e073ffba6ff311d48a2e65f515de5c793 100644 (file)
@@ -822,8 +822,6 @@ const char *CastExpr::getCastKindName() const {
     return "BitCast";
   case CK_LValueBitCast:
     return "LValueBitCast";
-  case CK_LValueToRValue:
-    return "LValueToRValue";
   case CK_NoOp:
     return "NoOp";
   case CK_BaseToDerived:
index fc0913bc2f729f293b22e127b9cd647259a2a84f..f541a7ece4aa6a3bbf509a01fd522c855aeb87b9 100644 (file)
@@ -2650,7 +2650,6 @@ void GRExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
       Dst.Add(*I);
     return;
 
-  case CK_LValueToRValue:
   case CK_NoOp:
   case CK_FunctionToPointerDecay:
     for (ExplodedNodeSet::iterator I = S2.begin(), E = S2.end(); I != E; ++I) {
index c28e405797ba0798dc18fefbb6cb2ed9f95a31c1..ce25b7ff2511427a5ee923d4606b429f5db3d575 100644 (file)
@@ -1789,7 +1789,8 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
     llvm_unreachable("dependent cast kind in IR gen!");
 
   case CK_NoOp:
-    if (!E->getSubExpr()->isRValue()) {
+    if (E->getSubExpr()->Classify(getContext()).getKind() 
+                                          != Expr::Classification::CL_PRValue) {
       LValue LV = EmitLValue(E->getSubExpr());
       if (LV.isPropertyRef() || LV.isKVCRef()) {
         QualType QT = E->getSubExpr()->getType();
@@ -1804,7 +1805,6 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
     }
     // Fall through to synthesize a temporary.
 
-  case CK_LValueToRValue:
   case CK_BitCast:
   case CK_ArrayToPointerDecay:
   case CK_FunctionToPointerDecay:
index bd1c43dff5886514998bdeaa7d98aa152434f7e2..308520aadd4c660bbd2a2205f8bebee91cc61c71 100644 (file)
@@ -250,6 +250,8 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
   }
 
   switch (E->getCastKind()) {
+  default: assert(0 && "Unhandled cast kind!");
+
   case CK_Dynamic: {
     assert(isa<CXXDynamicCastExpr>(E) && "CK_Dynamic without a dynamic_cast?");
     LValue LV = CGF.EmitCheckedLValue(E->getSubExpr());
@@ -284,7 +286,6 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
   }
 
   case CK_NoOp:
-  case CK_LValueToRValue:
   case CK_UserDefinedConversion:
   case CK_ConstructorConversion:
     assert(CGF.getContext().hasSameUnqualifiedType(E->getSubExpr()->getType(),
@@ -292,45 +293,10 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
            "Implicit cast types must be compatible");
     Visit(E->getSubExpr());
     break;
-      
+
   case CK_LValueBitCast:
-    llvm_unreachable("should not be emitting lvalue bitcast as rvalue");
+    llvm_unreachable("there are no lvalue bit-casts on aggregates");
     break;
-      
-  case CK_Dependent:
-  case CK_BitCast:
-  case CK_ArrayToPointerDecay:
-  case CK_FunctionToPointerDecay:
-  case CK_NullToPointer:
-  case CK_NullToMemberPointer:
-  case CK_BaseToDerivedMemberPointer:
-  case CK_DerivedToBaseMemberPointer:
-  case CK_MemberPointerToBoolean:
-  case CK_IntegralToPointer:
-  case CK_PointerToIntegral:
-  case CK_PointerToBoolean:
-  case CK_ToVoid:
-  case CK_VectorSplat:
-  case CK_IntegralCast:
-  case CK_IntegralToBoolean:
-  case CK_IntegralToFloating:
-  case CK_FloatingToIntegral:
-  case CK_FloatingToBoolean:
-  case CK_FloatingCast:
-  case CK_AnyPointerToObjCPointerCast:
-  case CK_AnyPointerToBlockPointerCast:
-  case CK_ObjCObjectLValueCast:
-  case CK_FloatingRealToComplex:
-  case CK_FloatingComplexToReal:
-  case CK_FloatingComplexToBoolean:
-  case CK_FloatingComplexCast:
-  case CK_FloatingComplexToIntegralComplex:
-  case CK_IntegralRealToComplex:
-  case CK_IntegralComplexToReal:
-  case CK_IntegralComplexToBoolean:
-  case CK_IntegralComplexCast:
-  case CK_IntegralComplexToFloatingComplex:
-    llvm_unreachable("cast kind invalid for aggregate types");
   }
 }
 
index a46afe6f658fee4ab8bfabf624750660b4da5f3a..e5ea26c24b61918be797a49091703e45da399547 100644 (file)
@@ -1101,10 +1101,6 @@ Value *ScalarExprEmitter::EmitCastExpr(CastExpr *CE) {
   case CK_ToUnion:
     llvm_unreachable("scalar cast to non-scalar value");
     break;
-      
-  case CK_LValueToRValue:
-    assert(CGF.getContext().hasSameUnqualifiedType(E->getType(), DestTy));
-    return Visit(const_cast<Expr*>(E));
 
   case CK_IntegralToPointer: {
     Value *Src = Visit(const_cast<Expr*>(E));
index c115061164dea8c3da633d7f0a18ef520c53ae1d..08941505d596f1c299780670148eb85df79f398d 100644 (file)
@@ -246,28 +246,22 @@ void Sema::DefaultFunctionArrayConversion(Expr *&E) {
 
 void Sema::DefaultFunctionArrayLvalueConversion(Expr *&E) {
   DefaultFunctionArrayConversion(E);
-  
-  // C++ [conv.lval]p1:
-  //   A glvalue of a non-function, non-array type T can be
-  //   converted to a prvalue.
-  if (E->isGLValue()) {
+
+  QualType Ty = E->getType();
+  assert(!Ty.isNull() && "DefaultFunctionArrayLvalueConversion - missing type");
+  if (!Ty->isDependentType() && Ty.hasQualifiers() &&
+      (!getLangOptions().CPlusPlus || !Ty->isRecordType()) &&
+      E->isLValue()) {
     // C++ [conv.lval]p1:
-    //   [...] If T is a non-class type, the type of the prvalue is the
+    //   [...] If T is a non-class type, the type of the rvalue is the
     //   cv-unqualified version of T. Otherwise, the type of the
-    //   rvalue is T.
+    //   rvalue is T
     //
     // C99 6.3.2.1p2:
     //   If the lvalue has qualified type, the value has the unqualified
     //   version of the type of the lvalue; otherwise, the value has the
     //   type of the lvalue.
-    QualType T = E->getType();
-    assert(!T.isNull() && "r-value conversion on typeless expression?");
-    
-    if (T.hasQualifiers() && !T->isDependentType() &&
-        (!getLangOptions().CPlusPlus || !T->isRecordType()))
-      T = T.getUnqualifiedType();
-    
-    ImpCastExprToType(E, T, CK_LValueToRValue);
+    ImpCastExprToType(E, Ty.getUnqualifiedType(), CK_NoOp);
   }
 }
 
@@ -277,43 +271,36 @@ void Sema::DefaultFunctionArrayLvalueConversion(Expr *&E) {
 /// sometimes surpressed. For example, the array->pointer conversion doesn't
 /// apply if the array is an argument to the sizeof or address (&) operators.
 /// In these instances, this routine should *not* be called.
-Expr *Sema::UsualUnaryConversions(Expr *&E) {
-  // First, convert to an r-value.
-  DefaultFunctionArrayLvalueConversion(E);
-  
-  QualType Ty = E->getType();
+Expr *Sema::UsualUnaryConversions(Expr *&Expr) {
+  QualType Ty = Expr->getType();
   assert(!Ty.isNull() && "UsualUnaryConversions - missing type");
-  
-  // Try to perform integral promotions if the object has a theoretically
-  // promotable type.
-  if (Ty->isIntegralOrUnscopedEnumerationType()) {
-    // C99 6.3.1.1p2:
-    //
-    //   The following may be used in an expression wherever an int or
-    //   unsigned int may be used:
-    //     - an object or expression with an integer type whose integer
-    //       conversion rank is less than or equal to the rank of int
-    //       and unsigned int.
-    //     - A bit-field of type _Bool, int, signed int, or unsigned int.
-    //
-    //   If an int can represent all values of the original type, the
-    //   value is converted to an int; otherwise, it is converted to an
-    //   unsigned int. These are called the integer promotions. All
-    //   other types are unchanged by the integer promotions.
-  
-    QualType PTy = Context.isPromotableBitField(E);
-    if (!PTy.isNull()) {
-      ImpCastExprToType(E, PTy, CK_IntegralCast);
-      return E;
-    }
-    if (Ty->isPromotableIntegerType()) {
-      QualType PT = Context.getPromotedIntegerType(Ty);
-      ImpCastExprToType(E, PT, CK_IntegralCast);
-      return E;
-    }
-  }
 
-  return E;
+  // C99 6.3.1.1p2:
+  //
+  //   The following may be used in an expression wherever an int or
+  //   unsigned int may be used:
+  //     - an object or expression with an integer type whose integer
+  //       conversion rank is less than or equal to the rank of int
+  //       and unsigned int.
+  //     - A bit-field of type _Bool, int, signed int, or unsigned int.
+  //
+  //   If an int can represent all values of the original type, the
+  //   value is converted to an int; otherwise, it is converted to an
+  //   unsigned int. These are called the integer promotions. All
+  //   other types are unchanged by the integer promotions.
+  QualType PTy = Context.isPromotableBitField(Expr);
+  if (!PTy.isNull()) {
+    ImpCastExprToType(Expr, PTy, CK_IntegralCast);
+    return Expr;
+  }
+  if (Ty->isPromotableIntegerType()) {
+    QualType PT = Context.getPromotedIntegerType(Ty);
+    ImpCastExprToType(Expr, PT, CK_IntegralCast);
+    return Expr;
+  }
+
+  DefaultFunctionArrayLvalueConversion(Expr);
+  return Expr;
 }
 
 /// DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that