[cfe-commits] r119331 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/AST/OperationKinds.h lib/AST/Expr.cpp lib/AST/ExprConstant.cpp lib/Checker/GRExprEngine.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGExprScalar.cpp lib/Sema/SemaCXXCast.cpp lib/Sema/SemaChecking.cpp
John McCall
rjmccall at apple.com
Mon Nov 15 21:46:29 PST 2010
Author: rjmccall
Date: Mon Nov 15 23:46:29 2010
New Revision: 119331
URL: http://llvm.org/viewvc/llvm-project?rev=119331&view=rev
Log:
Kill CK_Unknown and flesh out the documentation for the existing CastKinds.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/OperationKinds.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/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Nov 15 23:46:29 2010
@@ -2004,7 +2004,6 @@
// fallthrough to check for null base path
case CK_Dependent:
- case CK_Unknown:
case CK_NoOp:
case CK_PointerToBoolean:
case CK_IntegralToBoolean:
Modified: cfe/trunk/include/clang/AST/OperationKinds.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OperationKinds.h?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/OperationKinds.h (original)
+++ cfe/trunk/include/clang/AST/OperationKinds.h Mon Nov 15 23:46:29 2010
@@ -17,116 +17,169 @@
namespace clang {
-/// CastKind - the kind of cast this represents.
+/// CastKind - The kind of operation required for a conversion.
enum CastKind {
- /// CK_Unknown - Unknown cast kind.
- /// FIXME: The goal is to get rid of this and make all casts have a
- /// kind so that the AST client doesn't have to try to figure out what's
- /// going on.
- CK_Unknown,
-
- /// CK_Dependent - This explicit cast cannot yet be analyzed because
- /// the type or expression is dependent.
+ /// CK_Dependent - A conversion which cannot yet be analyzed because
+ /// either the expression or target type is dependent. These are
+ /// created only for explicit casts; dependent ASTs aren't required
+ /// to even approximately type-check.
+ /// (T*) malloc(sizeof(T))
+ /// reinterpret_cast<intptr_t>(A<T>::alloc());
CK_Dependent,
- /// CK_BitCast - Used for reinterpret_cast.
+ /// CK_BitCast - A conversion which causes a bit pattern of one type
+ /// to be reinterpreted as a bit pattern of another type. Generally
+ /// the operands must have equivalent size and unrelated types.
+ ///
+ /// The pointer conversion char* -> int* is a bitcast. Many other
+ /// pointer conversions which are "physically" bitcasts are given
+ /// special cast kinds.
+ ///
+ /// Vector coercions are bitcasts.
CK_BitCast,
- /// CK_LValueBitCast - Used for reinterpret_cast of expressions to
- /// a reference type.
+ /// CK_LValueBitCast - A conversion which reinterprets the address of
+ /// an l-value as an l-value of a different kind. Used for
+ /// reinterpret_casts of l-value expressions to reference types.
+ /// bool b; reinterpret_cast<char&>(b) = 'a';
CK_LValueBitCast,
- /// CK_NoOp - Used for const_cast.
+ /// CK_NoOp - A conversion which does not affect the type other than
+ /// (possibly) adding qualifiers.
+ /// int -> int
+ /// char** -> const char * const *
CK_NoOp,
- /// CK_BaseToDerived - Base to derived class casts.
+ /// CK_BaseToDerived - A conversion from a C++ class pointer/reference
+ /// to a derived class pointer/reference.
+ /// B *b = static_cast<B*>(a);
CK_BaseToDerived,
- /// CK_DerivedToBase - Derived to base class casts.
+ /// CK_DerivedToBase - A conversion from a C++ class pointer
+ /// to a base class pointer.
+ /// A *a = new B();
CK_DerivedToBase,
- /// CK_UncheckedDerivedToBase - Derived to base class casts that
- /// assume that the derived pointer is not null.
+ /// CK_UncheckedDerivedToBase - A conversion from a C++ class
+ /// pointer/reference to a base class that can assume that the
+ /// derived pointer is not null.
+ /// const A &a = B();
+ /// b->method_from_a();
CK_UncheckedDerivedToBase,
- /// CK_Dynamic - Dynamic cast.
+ /// CK_Dynamic - A C++ dynamic_cast.
CK_Dynamic,
- /// CK_ToUnion - Cast to union (GCC extension).
+ /// CK_ToUnion - The GCC cast-to-union extension.
+ /// int -> union { int x; float y; }
+ /// float -> union { int x; float y; }
CK_ToUnion,
/// CK_ArrayToPointerDecay - Array to pointer decay.
+ /// int[10] -> int*
+ /// char[5][6] -> char(*)[6]
CK_ArrayToPointerDecay,
/// CK_FunctionToPointerDecay - Function to pointer decay.
+ /// void(int) -> void(*)(int)
CK_FunctionToPointerDecay,
- /// CK_NullToPointer - Null pointer to pointer.
+ /// CK_NullToPointer - Null pointer constant to pointer, ObjC
+ /// pointer, or block pointer.
+ /// (void*) 0
+ /// void (^block)() = 0;
CK_NullToPointer,
- /// CK_NullToMemberPointer - Null pointer to member pointer.
+ /// CK_NullToMemberPointer - Null pointer constant to member pointer.
+ /// int A::*mptr = 0;
+ /// int (A::*fptr)(int) = nullptr;
CK_NullToMemberPointer,
/// CK_BaseToDerivedMemberPointer - Member pointer in base class to
/// member pointer in derived class.
+ /// int B::*mptr = &A::member;
CK_BaseToDerivedMemberPointer,
/// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
/// member pointer in base class.
+ /// int A::*mptr = static_cast<int A::*>(&B::member);
CK_DerivedToBaseMemberPointer,
+ /// CK_MemberPointerToBoolean - Member pointer to boolean. A check
+ /// against the null member pointer.
+ CK_MemberPointerToBoolean,
+
/// CK_UserDefinedConversion - Conversion using a user defined type
/// conversion function.
+ /// struct A { operator int(); }; int i = int(A());
CK_UserDefinedConversion,
- /// CK_ConstructorConversion - Conversion by constructor
+ /// CK_ConstructorConversion - Conversion by constructor.
+ /// struct A { A(int); }; A a = A(10);
CK_ConstructorConversion,
- /// CK_IntegralToPointer - Integral to pointer
+ /// CK_IntegralToPointer - Integral to pointer. A special kind of
+ /// reinterpreting conversion. Applies to normal, ObjC, and block
+ /// pointers.
+ /// (char*) 0x1001aab0
+ /// reinterpret_cast<int*>(0)
CK_IntegralToPointer,
- /// CK_PointerToIntegral - Pointer to integral
+ /// CK_PointerToIntegral - Pointer to integral. A special kind of
+ /// reinterpreting conversion. Applies to normal, ObjC, and block
+ /// pointers.
+ /// (intptr_t) "help!"
CK_PointerToIntegral,
- /// CK_PointerToBoolean - Pointer to boolean (i.e. is not null)
+ /// CK_PointerToBoolean - Pointer to boolean conversion. A check
+ /// against null. Applies to normal, ObjC, and block pointers.
CK_PointerToBoolean,
- /// CK_ToVoid - Cast to void.
+ /// CK_ToVoid - Cast to void, discarding the computed value.
+ /// (void) malloc(2048)
CK_ToVoid,
- /// CK_VectorSplat - Casting from an integer/floating type to an extended
- /// vector type with the same element type as the src type. Splats the
- /// src expression into the destination expression.
+ /// CK_VectorSplat - A conversion from an arithmetic type to a
+ /// vector of that element type. Fills all elements ("splats") with
+ /// the source value.
+ /// __attribute__((ext_vector_type(4))) int v = 5;
CK_VectorSplat,
- /// CK_IntegralCast - A truncating or extending cast between integral
- /// types of different size.
+ /// CK_IntegralCast - A cast between integral types (other than to
+ /// boolean). Variously a bitcast, a truncation, a sign-extension,
+ /// or a zero-extension.
+ /// long l = 5;
+ /// (unsigned) i
CK_IntegralCast,
- /// CK_IntegralToBoolean - Integral to boolean.
+ /// CK_IntegralToBoolean - Integral to boolean. A check against zero.
+ /// (bool) i
CK_IntegralToBoolean,
/// CK_IntegralToFloating - Integral to floating point.
+ /// float f = i;
CK_IntegralToFloating,
- /// CK_FloatingToIntegral - Floating point to integral.
+ /// CK_FloatingToIntegral - Floating point to integral. Rounds
+ /// towards zero, discarding any fractional component.
+ /// (int) f
CK_FloatingToIntegral,
/// CK_FloatingToBoolean - Floating point to boolean.
+ /// (bool) f
CK_FloatingToBoolean,
/// CK_FloatingCast - Casting between floating types of different size.
+ /// (double) f
+ /// (float) ld
CK_FloatingCast,
- /// CK_MemberPointerToBoolean - Member pointer to boolean
- CK_MemberPointerToBoolean,
-
- /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c
- /// pointer
+ /// CK_AnyPointerToObjCPointerCast - Casting any other pointer kind
+ /// to an Objective-C pointer.
CK_AnyPointerToObjCPointerCast,
- /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block
- /// pointer
+ /// CK_AnyPointerToBlockPointerCast - Casting any other pointer kind
+ /// to a block pointer.
CK_AnyPointerToBlockPointerCast,
/// \brief Converting between two Objective-C object types, which
@@ -134,34 +187,52 @@
/// object.
CK_ObjCObjectLValueCast,
- /// \brief Floating point real to floating point complex
+ /// \brief A conversion of a floating point real to a floating point
+ /// complex of the original type. Injects the value as the real
+ /// component with a zero imaginary component.
+ /// float -> _Complex float
CK_FloatingRealToComplex,
- /// \brief Floating pointer complex to floating point real
+ /// \brief Converts a floating point complex to floating point real
+ /// of the source's element type. Just discards the imaginary
+ /// component.
+ /// _Complex long double -> long double
CK_FloatingComplexToReal,
- /// \brief Converting a floating complex to bool
+ /// \brief Converts a floating point complex to bool by comparing
+ /// against 0+0i.
CK_FloatingComplexToBoolean,
- /// \brief Casting between floating point complex types of different size
+ /// \brief Converts between different floating point complex types.
+ /// _Complex float -> _Complex double
CK_FloatingComplexCast,
- /// \brief Casting from a floating complex to an integral complex
+ /// \brief Converts from a floating complex to an integral complex.
+ /// _Complex float -> _Complex int
CK_FloatingComplexToIntegralComplex,
- /// \brief Integral real to integral complex
+ /// \brief Converts from an integral real to an integral complex
+ /// whose element type matches the source. Injects the value as
+ /// the real component with a zero imaginary component.
+ /// long -> _Complex long
CK_IntegralRealToComplex,
- /// \brief Integral complex to integral real
+ /// \brief Converts an integral complex to an integral real of the
+ /// source's element type by discarding the imaginary component.
+ /// _Complex short -> short
CK_IntegralComplexToReal,
- /// \brief Converting an integral complex to bool
+ /// \brief Converts an integral complex to bool by comparing against
+ /// 0+0i.
CK_IntegralComplexToBoolean,
- /// \brief Casting between integral complex types of different size
+ /// \brief Converts between different integral complex types.
+ /// _Complex char -> _Complex long long
+ /// _Complex unsigned int -> _Complex signed int
CK_IntegralComplexCast,
- /// \brief Casting from an integral complex to a floating complex
+ /// \brief Converts from an integral complex to a floating complex.
+ /// _Complex unsigned -> _Complex float
CK_IntegralComplexToFloatingComplex
};
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Nov 15 23:46:29 2010
@@ -740,8 +740,6 @@
const char *CastExpr::getCastKindName() const {
switch (getCastKind()) {
- case CK_Unknown:
- return "Unknown";
case CK_Dependent:
return "Dependent";
case CK_BitCast:
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Nov 15 23:46:29 2010
@@ -532,35 +532,6 @@
default:
break;
- case CK_Unknown: {
- // FIXME: The handling for CK_Unknown is ugly/shouldn't be necessary!
-
- // Check for pointer->pointer cast
- if (SubExpr->getType()->isPointerType() ||
- SubExpr->getType()->isObjCObjectPointerType() ||
- SubExpr->getType()->isNullPtrType() ||
- SubExpr->getType()->isBlockPointerType())
- return Visit(SubExpr);
-
- if (SubExpr->getType()->isIntegralOrEnumerationType()) {
- APValue Value;
- if (!EvaluateIntegerOrLValue(SubExpr, Value, Info))
- break;
-
- if (Value.isInt()) {
- Value.getInt().extOrTrunc((unsigned)Info.Ctx.getTypeSize(E->getType()));
- Result.Base = 0;
- Result.Offset = CharUnits::fromQuantity(Value.getInt().getZExtValue());
- return true;
- } else {
- Result.Base = Value.getLValueBase();
- Result.Offset = Value.getLValueOffset();
- return true;
- }
- }
- break;
- }
-
case CK_NoOp:
case CK_BitCast:
case CK_LValueBitCast:
Modified: cfe/trunk/lib/Checker/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRExprEngine.cpp?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Checker/GRExprEngine.cpp Mon Nov 15 23:46:29 2010
@@ -2541,7 +2541,6 @@
}
return;
- case CK_Unknown:
case CK_Dependent:
case CK_ArrayToPointerDecay:
case CK_BitCast:
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Nov 15 23:46:29 2010
@@ -1804,7 +1804,6 @@
}
// Fall through to synthesize a temporary.
- case CK_Unknown:
case CK_BitCast:
case CK_ArrayToPointerDecay:
case CK_FunctionToPointerDecay:
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Mon Nov 15 23:46:29 2010
@@ -285,8 +285,6 @@
break;
}
- // FIXME: Remove the CK_Unknown check here.
- case CK_Unknown:
case CK_NoOp:
case CK_UserDefinedConversion:
case CK_ConstructorConversion:
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Mon Nov 15 23:46:29 2010
@@ -999,11 +999,6 @@
switch (Kind) {
case CK_Dependent: llvm_unreachable("dependent cast kind in IR gen!");
- case CK_Unknown:
- // FIXME: All casts should have a known kind!
- //assert(0 && "Unknown cast kind!");
- break;
-
case CK_LValueBitCast:
case CK_ObjCObjectLValueCast: {
Value *V = EmitLValue(E).getAddress();
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Mon Nov 15 23:46:29 2010
@@ -526,7 +526,7 @@
Self.Diag(OpRange.getBegin(), msg) << CT_Static
<< SrcExpr->getType() << DestType << OpRange;
}
- else if (Kind == CK_Unknown || Kind == CK_BitCast)
+ else if (Kind == CK_BitCast)
Self.CheckCastAlign(SrcExpr, DestType, OpRange);
}
@@ -1413,7 +1413,7 @@
<< CastExpr->getType() << CastTy << R;
}
}
- else if (Kind == CK_Unknown || Kind == CK_BitCast)
+ else if (Kind == CK_BitCast)
CheckCastAlign(CastExpr, CastTy, R);
return tcr != TC_Success;
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=119331&r1=119330&r2=119331&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Nov 15 23:46:29 2010
@@ -2280,8 +2280,6 @@
IntRange OutputTypeRange = IntRange::forValueOfType(C, CE->getType());
bool isIntegerCast = (CE->getCastKind() == CK_IntegralCast);
- if (!isIntegerCast && CE->getCastKind() == CK_Unknown)
- isIntegerCast = CE->getSubExpr()->getType()->isIntegerType();
// Assume that non-integer casts can span the full range of the type.
if (!isIntegerCast)
More information about the cfe-commits
mailing list