[cfe-commits] r112122 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/ext_vector_casts.c test/SemaCXX/vector-no-lax.cpp test/SemaCXX/vector.cpp
Eric Christopher
echristo at apple.com
Wed Aug 25 17:42:16 PDT 2010
Author: echristo
Date: Wed Aug 25 19:42:16 2010
New Revision: 112122
URL: http://llvm.org/viewvc/llvm-project?rev=112122&view=rev
Log:
With lax vector conversions (the default) make sure we convert between two
vectors that are the same size. Fix up testcases accordingly and add a new one
to make sure we still error if lax vector conversions are disabled.
Fixes rdar://8328190
Added:
cfe/trunk/test/SemaCXX/vector-no-lax.cpp
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/ext_vector_casts.c
cfe/trunk/test/SemaCXX/vector.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=112122&r1=112121&r2=112122&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Aug 25 19:42:16 2010
@@ -5005,7 +5005,6 @@
// Handle the case of a vector & extvector type of the same size and element
// type. It would be nice if we only had one vector type someday.
if (getLangOptions().LaxVectorConversions) {
- // FIXME: Should we warn here?
if (const VectorType *LV = lhsType->getAs<VectorType>()) {
if (const VectorType *RV = rhsType->getAs<VectorType>())
if (LV->getElementType() == RV->getElementType() &&
@@ -5017,8 +5016,14 @@
ImpCastExprToType(lex, rhsType, CK_BitCast);
return rhsType;
+ } else if (Context.getTypeSize(lhsType) ==Context.getTypeSize(rhsType)){
+ // If we are allowing lax vector conversions, and LHS and RHS are both
+ // vectors, the total size only needs to be the same. This is a
+ // bitcast; no bits are changed but the result type is different.
+ ImpCastExprToType(rex, lhsType, CK_BitCast);
+ return lhsType;
}
- }
+ }
}
// Handle the case of equivalent AltiVec and GCC vector types
Modified: cfe/trunk/test/Sema/ext_vector_casts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ext_vector_casts.c?rev=112122&r1=112121&r2=112122&view=diff
==============================================================================
--- cfe/trunk/test/Sema/ext_vector_casts.c (original)
+++ cfe/trunk/test/Sema/ext_vector_casts.c Wed Aug 25 19:42:16 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fno-lax-vector-conversions %s
typedef __attribute__(( ext_vector_type(2) )) float float2;
typedef __attribute__(( ext_vector_type(4) )) int int4;
Added: cfe/trunk/test/SemaCXX/vector-no-lax.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vector-no-lax.cpp?rev=112122&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/vector-no-lax.cpp (added)
+++ cfe/trunk/test/SemaCXX/vector-no-lax.cpp Wed Aug 25 19:42:16 2010
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -fno-lax-vector-conversions -verify %s
+typedef unsigned int __attribute__((vector_size (16))) vUInt32;
+typedef int __attribute__((vector_size (16))) vSInt32;
+
+vSInt32 foo (vUInt32 a) {
+ vSInt32 b = { 0, 0, 0, 0 };
+ b += a; // expected-error{{can't convert between vector values}}
+ return b;
+}
Modified: cfe/trunk/test/SemaCXX/vector.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vector.cpp?rev=112122&r1=112121&r2=112122&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/vector.cpp (original)
+++ cfe/trunk/test/SemaCXX/vector.cpp Wed Aug 25 19:42:16 2010
@@ -51,10 +51,10 @@
__typeof__(Cond? ll16 : ll16e) *ll16ep2 = &ll16e;
__typeof__(Cond? ll16e : ll16) *ll16ep3 = &ll16e;
- // Conditional operators with incompatible types.
- (void)(Cond? c16 : ll16); // expected-error{{can't convert between vector values}}
- (void)(Cond? ll16e : c16e); // expected-error{{can't convert between vector values}}
- (void)(Cond? ll16e : c16); // expected-error{{can't convert between vector values}}
+ // Conditional operators with compatible types under -flax-vector-conversions (default)
+ (void)(Cond? c16 : ll16);
+ (void)(Cond? ll16e : c16e);
+ (void)(Cond? ll16e : c16);
}
// Test C++ cast'ing of vector types.
@@ -183,8 +183,10 @@
(void)(Cond? to_c16 : to_c16e);
(void)(Cond? to_ll16e : to_ll16);
- (void)(Cond? to_c16 : to_ll16); // expected-error{{can't convert between vector values of different size}}
- (void)(Cond? to_c16e : to_ll16e); // expected-error{{can't convert between vector values of different size}}
+
+ // These 2 are convertable with -flax-vector-conversions (default)
+ (void)(Cond? to_c16 : to_ll16);
+ (void)(Cond? to_c16e : to_ll16e);
}
typedef float fltx2 __attribute__((__vector_size__(8)));
More information about the cfe-commits
mailing list