diff options
author | Abramo Bagnara <abramo.bagnara@gmail.com> | 2011-01-04 09:50:03 +0000 |
---|---|---|
committer | Abramo Bagnara <abramo.bagnara@gmail.com> | 2011-01-04 09:50:03 +0000 |
commit | bb03f5dbc23fb9aa1dfdf6a1dfdb192aa56b6b1c (patch) | |
tree | 53154abad5625feb69a4446293fab8c74c74eaa2 /lib/Sema/SemaExpr.cpp | |
parent | 9f7a6eeee441bcbb1b17208cb3abd65a0017525a (diff) |
Prefer getAs<ComplexType> rather than cast<ComplexType> on canonical type. Suggestion by Douglas Gregor!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122807 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 1e82432ba1..9be04e5fb6 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4503,15 +4503,14 @@ static CastKind PrepareScalarCast(Sema &S, Expr *&Src, QualType DestTy) { // Also, callers should have filtered out the invalid cases with // pointers. Everything else should be possible. - QualType SrcTy = S.Context.getCanonicalType(Src->getType()); - DestTy = S.Context.getCanonicalType(DestTy); + QualType SrcTy = Src->getType(); if (S.Context.hasSameUnqualifiedType(SrcTy, DestTy)) return CK_NoOp; switch (SrcTy->getScalarTypeKind()) { case Type::STK_MemberPointer: llvm_unreachable("member pointer type in C"); - + case Type::STK_Pointer: switch (DestTy->getScalarTypeKind()) { case Type::STK_Pointer: @@ -4544,11 +4543,11 @@ static CastKind PrepareScalarCast(Sema &S, Expr *&Src, QualType DestTy) { case Type::STK_Floating: return CK_IntegralToFloating; case Type::STK_IntegralComplex: - S.ImpCastExprToType(Src, cast<ComplexType>(DestTy)->getElementType(), + S.ImpCastExprToType(Src, DestTy->getAs<ComplexType>()->getElementType(), CK_IntegralCast); return CK_IntegralRealToComplex; case Type::STK_FloatingComplex: - S.ImpCastExprToType(Src, cast<ComplexType>(DestTy)->getElementType(), + S.ImpCastExprToType(Src, DestTy->getAs<ComplexType>()->getElementType(), CK_IntegralToFloating); return CK_FloatingRealToComplex; case Type::STK_MemberPointer: @@ -4565,11 +4564,11 @@ static CastKind PrepareScalarCast(Sema &S, Expr *&Src, QualType DestTy) { case Type::STK_Integral: return CK_FloatingToIntegral; case Type::STK_FloatingComplex: - S.ImpCastExprToType(Src, cast<ComplexType>(DestTy)->getElementType(), + S.ImpCastExprToType(Src, DestTy->getAs<ComplexType>()->getElementType(), CK_FloatingCast); return CK_FloatingRealToComplex; case Type::STK_IntegralComplex: - S.ImpCastExprToType(Src, cast<ComplexType>(DestTy)->getElementType(), + S.ImpCastExprToType(Src, DestTy->getAs<ComplexType>()->getElementType(), CK_FloatingToIntegral); return CK_IntegralRealToComplex; case Type::STK_Pointer: @@ -4586,7 +4585,7 @@ static CastKind PrepareScalarCast(Sema &S, Expr *&Src, QualType DestTy) { case Type::STK_IntegralComplex: return CK_FloatingComplexToIntegralComplex; case Type::STK_Floating: { - QualType ET = cast<ComplexType>(SrcTy)->getElementType(); + QualType ET = SrcTy->getAs<ComplexType>()->getElementType(); if (S.Context.hasSameType(ET, DestTy)) return CK_FloatingComplexToReal; S.ImpCastExprToType(Src, ET, CK_FloatingComplexToReal); @@ -4595,7 +4594,7 @@ static CastKind PrepareScalarCast(Sema &S, Expr *&Src, QualType DestTy) { case Type::STK_Bool: return CK_FloatingComplexToBoolean; case Type::STK_Integral: - S.ImpCastExprToType(Src, cast<ComplexType>(SrcTy)->getElementType(), + S.ImpCastExprToType(Src, SrcTy->getAs<ComplexType>()->getElementType(), CK_FloatingComplexToReal); return CK_FloatingToIntegral; case Type::STK_Pointer: @@ -4612,7 +4611,7 @@ static CastKind PrepareScalarCast(Sema &S, Expr *&Src, QualType DestTy) { case Type::STK_IntegralComplex: return CK_IntegralComplexCast; case Type::STK_Integral: { - QualType ET = cast<ComplexType>(SrcTy)->getElementType(); + QualType ET = SrcTy->getAs<ComplexType>()->getElementType(); if (S.Context.hasSameType(ET, DestTy)) return CK_IntegralComplexToReal; S.ImpCastExprToType(Src, ET, CK_IntegralComplexToReal); @@ -4621,7 +4620,7 @@ static CastKind PrepareScalarCast(Sema &S, Expr *&Src, QualType DestTy) { case Type::STK_Bool: return CK_IntegralComplexToBoolean; case Type::STK_Floating: - S.ImpCastExprToType(Src, cast<ComplexType>(SrcTy)->getElementType(), + S.ImpCastExprToType(Src, SrcTy->getAs<ComplexType>()->getElementType(), CK_IntegralComplexToReal); return CK_IntegralToFloating; case Type::STK_Pointer: |