diff options
author | Anders Carlsson <andersca@mac.com> | 2009-09-16 19:19:43 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-09-16 19:19:43 +0000 |
commit | 0de51bc6122f6cee0e8081d65dfcc7d500da1c6f (patch) | |
tree | cd38cabe5e28301bf8b6b1e204d355a017f14581 /lib/Sema/SemaCXXCast.cpp | |
parent | aad826b3877ed096119989a21e0acec6ff7d70bd (diff) |
Improve handling of vector casts in C++.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82072 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaCXXCast.cpp')
-rw-r--r-- | lib/Sema/SemaCXXCast.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index dbd6c6fde5..f0ae9a1330 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -956,6 +956,32 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr, return TC_Success; } + bool destIsVector = DestType->isVectorType(); + bool srcIsVector = SrcType->isVectorType(); + if (srcIsVector || destIsVector) { + bool srcIsScalar = SrcType->isIntegralType() && !SrcType->isEnumeralType(); + bool destIsScalar = + DestType->isIntegralType() && !DestType->isEnumeralType(); + + // Check if this is a cast between a vector and something else. + if (!(srcIsScalar && destIsVector) && !(srcIsVector && destIsScalar) && + !(srcIsVector && destIsVector)) + return TC_NotApplicable; + + // If both types have the same size, we can successfully cast. + if (Self.Context.getTypeSize(SrcType) == Self.Context.getTypeSize(DestType)) + return TC_Success; + + if (destIsScalar) + msg = diag::err_bad_cxx_cast_vector_to_scalar_different_size; + else if (srcIsScalar) + msg = diag::err_bad_cxx_cast_scalar_to_vector_different_size; + else + msg = diag::err_bad_cxx_cast_vector_to_vector_different_size; + + return TC_Failed; + } + bool destIsPtr = DestType->isPointerType(); bool srcIsPtr = SrcType->isPointerType(); if (!destIsPtr && !srcIsPtr) { |