[cfe-commits] r118994 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/AST/OperationKinds.h include/clang/AST/Stmt.h lib/AST/Expr.cpp lib/AST/ExprConstant.cpp lib/Checker/GRExprEngine.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprComplex.cpp lib/CodeGen/CGExprScalar.cpp lib/Sema/SemaExpr.cpp

John McCall rjmccall at apple.com
Sat Nov 13 01:02:35 PST 2010


Author: rjmccall
Date: Sat Nov 13 03:02:35 2010
New Revision: 118994

URL: http://llvm.org/viewvc/llvm-project?rev=118994&view=rev
Log:
Introduce five new cast kinds for various conversions into and
between complex types.


Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/AST/OperationKinds.h
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/lib/Checker/GRExprEngine.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprComplex.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Nov 13 03:02:35 2010
@@ -1997,6 +1997,11 @@
     case CK_AnyPointerToObjCPointerCast:
     case CK_AnyPointerToBlockPointerCast:
     case CK_ObjCObjectLValueCast:
+    case CK_FloatingRealToComplex:
+    case CK_FloatingComplexCast:
+    case CK_IntegralRealToComplex:
+    case CK_IntegralComplexCast:
+    case CK_IntegralToFloatingComplex:
       assert(path_empty() && "Cast kind should not have a base path!");
       break;
     }

Modified: cfe/trunk/include/clang/AST/OperationKinds.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OperationKinds.h?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/OperationKinds.h (original)
+++ cfe/trunk/include/clang/AST/OperationKinds.h Sat Nov 13 03:02:35 2010
@@ -118,7 +118,22 @@
   /// \brief Converting between two Objective-C object types, which
   /// can occur when performing reference binding to an Objective-C
   /// object.
-  CK_ObjCObjectLValueCast
+  CK_ObjCObjectLValueCast,
+
+  /// \brief Floating point real to floating point complex
+  CK_FloatingRealToComplex,
+
+  /// \brief Casting between floating point complex types of different size
+  CK_FloatingComplexCast,
+
+  /// \brief Integral real to integral complex
+  CK_IntegralRealToComplex,
+
+  /// \brief Casting between integral complex types of different size
+  CK_IntegralComplexCast,
+
+  /// \brief Casting from an integral complex to a floating complex.
+  CK_IntegralToFloatingComplex
 };
 
 

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Sat Nov 13 03:02:35 2010
@@ -156,8 +156,8 @@
     friend class CastExpr;
     unsigned : NumExprBits;
 
-    unsigned Kind : 5;
-    unsigned BasePathSize : 32 - NumExprBits - 5;
+    unsigned Kind : 6;
+    unsigned BasePathSize : 32 - 6 - NumExprBits;
   };
 
   union {

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sat Nov 13 03:02:35 2010
@@ -798,9 +798,19 @@
     return "AnyPointerToBlockPointerCast";
   case CK_ObjCObjectLValueCast:
     return "ObjCObjectLValueCast";
+  case CK_FloatingRealToComplex:
+    return "FloatingRealToComplex";
+  case CK_FloatingComplexCast:
+    return "FloatingComplexCast";
+  case CK_IntegralRealToComplex:
+    return "IntegralRealToComplex";
+  case CK_IntegralComplexCast:
+    return "IntegralComplexCast";
+  case CK_IntegralToFloatingComplex:
+    return "IntegralToFloatingComplex";
   }
 
-  assert(0 && "Unhandled cast kind!");
+  llvm_unreachable("Unhandled cast kind!");
   return 0;
 }
 

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Nov 13 03:02:35 2010
@@ -2165,6 +2165,8 @@
   QualType EltType = E->getType()->getAs<ComplexType>()->getElementType();
   QualType SubType = SubExpr->getType();
 
+  // TODO: just trust CastKind
+
   if (SubType->isRealFloatingType()) {
     APFloat &Real = Result.FloatReal;
     if (!EvaluateFloat(SubExpr, Real, Info))

Modified: cfe/trunk/lib/Checker/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRExprEngine.cpp?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Checker/GRExprEngine.cpp Sat Nov 13 03:02:35 2010
@@ -2524,6 +2524,11 @@
   case CK_IntegralToFloating:
   case CK_FloatingToIntegral:
   case CK_FloatingCast:
+  case CK_FloatingRealToComplex:
+  case CK_FloatingComplexCast:
+  case CK_IntegralRealToComplex:
+  case CK_IntegralComplexCast:
+  case CK_IntegralToFloatingComplex:
   case CK_AnyPointerToObjCPointerCast:
   case CK_AnyPointerToBlockPointerCast:
   case CK_DerivedToBase:

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat Nov 13 03:02:35 2010
@@ -1814,6 +1814,11 @@
   case CK_IntegralToFloating:
   case CK_FloatingToIntegral:
   case CK_FloatingCast:
+  case CK_FloatingRealToComplex:
+  case CK_FloatingComplexCast:
+  case CK_IntegralRealToComplex:
+  case CK_IntegralComplexCast:
+  case CK_IntegralToFloatingComplex:
   case CK_DerivedToBaseMemberPointer:
   case CK_BaseToDerivedMemberPointer:
   case CK_MemberPointerToBoolean:

Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprComplex.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprComplex.cpp Sat Nov 13 03:02:35 2010
@@ -350,6 +350,8 @@
 
 ComplexPairTy ComplexExprEmitter::EmitCast(CastExpr::CastKind CK, Expr *Op, 
                                            QualType DestTy) {
+  // FIXME: this should be based off of the CastKind.
+
   // Two cases here: cast from (complex to complex) and (scalar to complex).
   if (Op->getType()->isAnyComplexType())
     return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy);

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Nov 13 03:02:35 2010
@@ -1079,7 +1079,11 @@
     return CGF.CGM.getCXXABI().EmitMemberPointerConversion(CGF, CE, Src);
   }
   
-
+  case CK_FloatingRealToComplex:
+  case CK_FloatingComplexCast:
+  case CK_IntegralRealToComplex:
+  case CK_IntegralComplexCast:
+  case CK_IntegralToFloatingComplex:
   case CK_ConstructorConversion:
     assert(0 && "Should be unreachable!");
     break;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=118994&r1=118993&r2=118994&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Nov 13 03:02:35 2010
@@ -399,18 +399,30 @@
   if (LHSComplexFloat || RHSComplexFloat) {
     // if we have an integer operand, the result is the complex type.
 
-    if (LHSComplexFloat &&
-        (rhs->isIntegerType() || rhs->isComplexIntegerType())) {
-      // convert the rhs to the lhs complex type.
-      ImpCastExprToType(rhsExpr, lhs, CK_Unknown);
+    if (!RHSComplexFloat && !rhs->isRealFloatingType()) {
+      if (rhs->isIntegerType()) {
+        QualType fp = cast<ComplexType>(lhs)->getElementType();
+        ImpCastExprToType(rhsExpr, fp, CK_IntegralToFloating);
+        ImpCastExprToType(rhsExpr, lhs, CK_FloatingRealToComplex);
+      } else {
+        assert(rhs->isComplexIntegerType());
+        ImpCastExprToType(rhsExpr, lhs, CK_IntegralToFloatingComplex);
+      }
       return lhs;
     }
 
-    if (!LHSComplexFloat && RHSComplexFloat &&
-        (lhs->isIntegerType() || lhs->isComplexIntegerType())) {
-      // convert the lhs to the rhs complex type.
-      if (!isCompAssign)
-        ImpCastExprToType(lhsExpr, rhs, CK_Unknown);
+    if (!LHSComplexFloat && !lhs->isRealFloatingType()) {
+      if (!isCompAssign) {
+        // int -> float -> _Complex float
+        if (lhs->isIntegerType()) {
+          QualType fp = cast<ComplexType>(rhs)->getElementType();
+          ImpCastExprToType(lhsExpr, fp, CK_IntegralToFloating);
+          ImpCastExprToType(lhsExpr, rhs, CK_FloatingRealToComplex);
+        } else {
+          assert(lhs->isComplexIntegerType());
+          ImpCastExprToType(lhsExpr, rhs, CK_IntegralToFloatingComplex);
+        }
+      }
       return rhs;
     }
 
@@ -430,13 +442,13 @@
     if (LHSComplexFloat && RHSComplexFloat) {
       if (order > 0) {
         // _Complex float -> _Complex double
-        ImpCastExprToType(rhsExpr, lhs, CK_Unknown);
+        ImpCastExprToType(rhsExpr, lhs, CK_FloatingComplexCast);
         return lhs;
 
       } else if (order < 0) {
         // _Complex float -> _Complex double
         if (!isCompAssign)
-          ImpCastExprToType(lhsExpr, rhs, CK_Unknown);
+          ImpCastExprToType(lhsExpr, rhs, CK_FloatingComplexCast);
         return rhs;
       }
       return lhs;
@@ -447,7 +459,9 @@
     if (LHSComplexFloat) {
       if (order > 0) { // LHS is wider
         // float -> _Complex double
-        ImpCastExprToType(rhsExpr, lhs, CK_Unknown);
+        QualType fp = cast<ComplexType>(lhs)->getElementType();
+        ImpCastExprToType(rhsExpr, fp, CK_FloatingCast);
+        ImpCastExprToType(rhsExpr, lhs, CK_FloatingRealToComplex);
         return lhs;        
       }
 
@@ -455,11 +469,11 @@
       QualType result = (order == 0 ? lhs : Context.getComplexType(rhs));
 
       // double -> _Complex double
-      ImpCastExprToType(rhsExpr, result, CK_Unknown);
+      ImpCastExprToType(rhsExpr, result, CK_FloatingRealToComplex);
 
       // _Complex float -> _Complex double
       if (!isCompAssign && order < 0)
-        ImpCastExprToType(lhsExpr, result, CK_Unknown);
+        ImpCastExprToType(lhsExpr, result, CK_FloatingComplexCast);
 
       return result;
     }
@@ -470,8 +484,10 @@
 
     if (order < 0) { // RHS is wider
       // float -> _Complex double
-      if (!isCompAssign)
-        ImpCastExprToType(lhsExpr, rhs, CK_Unknown);
+      if (!isCompAssign) {
+        ImpCastExprToType(lhsExpr, rhs, CK_FloatingCast);
+        ImpCastExprToType(lhsExpr, rhs, CK_FloatingRealToComplex);
+      }
       return rhs;
     }
 
@@ -480,11 +496,11 @@
 
     // double -> _Complex double
     if (!isCompAssign)
-      ImpCastExprToType(lhsExpr, result, CK_Unknown);
+      ImpCastExprToType(lhsExpr, result, CK_FloatingRealToComplex);
 
     // _Complex float -> _Complex double
     if (order > 0)
-      ImpCastExprToType(rhsExpr, result, CK_Unknown);
+      ImpCastExprToType(rhsExpr, result, CK_FloatingComplexCast);
 
     return result;
   }
@@ -521,11 +537,11 @@
       QualType result = Context.getComplexType(lhs);
 
       // _Complex int -> _Complex float
-      ImpCastExprToType(rhsExpr, result, CK_Unknown);
+      ImpCastExprToType(rhsExpr, result, CK_IntegralToFloatingComplex);
 
       // float -> _Complex float
       if (!isCompAssign)
-        ImpCastExprToType(lhsExpr, result, CK_Unknown);
+        ImpCastExprToType(lhsExpr, result, CK_FloatingRealToComplex);
 
       return result;
     }
@@ -544,10 +560,10 @@
 
     // _Complex int -> _Complex float
     if (!isCompAssign)
-      ImpCastExprToType(lhsExpr, result, CK_Unknown);
+      ImpCastExprToType(lhsExpr, result, CK_IntegralToFloatingComplex);
 
     // float -> _Complex float
-    ImpCastExprToType(rhsExpr, result, CK_Unknown);
+    ImpCastExprToType(rhsExpr, result, CK_FloatingRealToComplex);
 
     return result;
   }
@@ -563,21 +579,21 @@
     assert(order && "inequal types with equal element ordering");
     if (order > 0) {
       // _Complex int -> _Complex long
-      ImpCastExprToType(rhsExpr, lhs, CK_Unknown);
+      ImpCastExprToType(rhsExpr, lhs, CK_IntegralComplexCast);
       return lhs;
     }
 
     if (!isCompAssign)
-      ImpCastExprToType(lhsExpr, rhs, CK_Unknown);
+      ImpCastExprToType(lhsExpr, rhs, CK_IntegralComplexCast);
     return rhs;
   } else if (lhsComplexInt) {
     // int -> _Complex int
-    ImpCastExprToType(rhsExpr, lhs, CK_Unknown);
+    ImpCastExprToType(rhsExpr, lhs, CK_IntegralRealToComplex);
     return lhs;
   } else if (rhsComplexInt) {
     // int -> _Complex int
     if (!isCompAssign)
-      ImpCastExprToType(lhsExpr, rhs, CK_Unknown);
+      ImpCastExprToType(lhsExpr, rhs, CK_IntegralRealToComplex);
     return rhs;
   }
 





More information about the cfe-commits mailing list