/// @c reinterpret_cast<int>(VoidPtr).
class CXXReinterpretCastExpr : public CXXNamedCastExpr {
public:
- CXXReinterpretCastExpr(QualType ty, Expr *op, QualType writtenTy,
- SourceLocation l)
- : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, CK_BitCast, op,
+ CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op,
+ QualType writtenTy, SourceLocation l)
+ : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op,
writtenTy, l) {}
static bool classof(const Stmt *T) {
switch (Kind) {
default:
+ // FIXME: Assert here.
+ // assert(0 && "Unhandled cast kind!");
+ break;
+ case CastExpr::CK_Unknown:
+ // FIXME: We should really assert here - Unknown casts should never get
+ // as far as to codegen.
break;
case CastExpr::CK_BitCast: {
Value *Src = Visit(const_cast<Expr*>(E));
NullCheckValue);
}
+ case CastExpr::CK_IntegralToPointer: {
+ Value *Src = Visit(const_cast<Expr*>(E));
+ return Builder.CreateIntToPtr(Src, ConvertType(DestTy));
+ }
+
+ case CastExpr::CK_PointerToIntegral: {
+ Value *Src = Visit(const_cast<Expr*>(E));
+ return Builder.CreatePtrToInt(Src, ConvertType(DestTy));
+ }
+
}
// Handle cases where the source is an non-complex type.
const SourceRange &DestRange);
static void CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
const SourceRange &OpRange,
- const SourceRange &DestRange);
+ const SourceRange &DestRange,
+ CastExpr::CastKind &Kind);
static void CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
const SourceRange &OpRange,
CastExpr::CastKind &Kind,
return Owned(new (Context)CXXDynamicCastExpr(DestType.getNonReferenceType(),
Kind, Ex, DestType, OpLoc));
}
- case tok::kw_reinterpret_cast:
+ case tok::kw_reinterpret_cast: {
+ CastExpr::CastKind Kind = CastExpr::CK_Unknown;
if (!TypeDependent)
- CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange);
+ CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange, Kind);
return Owned(new (Context) CXXReinterpretCastExpr(
DestType.getNonReferenceType(),
- Ex, DestType, OpLoc));
-
+ Kind, Ex, DestType, OpLoc));
+ }
case tok::kw_static_cast: {
CastExpr::CastKind Kind = CastExpr::CK_Unknown;
if (!TypeDependent) {
/// char *bytes = reinterpret_cast\<char*\>(int_ptr);
void
CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
- const SourceRange &OpRange, const SourceRange &DestRange) {
+ const SourceRange &OpRange, const SourceRange &DestRange,
+ CastExpr::CastKind &Kind) {
if (!DestType->isLValueReferenceType())
Self.DefaultFunctionArrayConversion(SrcExpr);
- CastExpr::CastKind Kind = CastExpr::CK_Unknown;
unsigned msg = diag::err_bad_cxx_cast_generic;
if (TryReinterpretCast(Self, SrcExpr, DestType, /*CStyle*/false, Kind,
OpRange, msg)
msg = diag::err_bad_reinterpret_cast_small_int;
return TC_Failed;
}
+ Kind = CastExpr::CK_PointerToIntegral;
return TC_Success;
}
msg = diag::err_bad_reinterpret_cast_small_int;
return TC_Failed;
}
+ Kind = CastExpr::CK_PointerToIntegral;
return TC_Success;
}
assert(destIsPtr && "One type must be a pointer");
// C++ 5.2.10p5: A value of integral or enumeration type can be explicitly
// converted to a pointer.
+ Kind = CastExpr::CK_IntegralToPointer;
return TC_Success;
}