[cfe-commits] r106551 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaCXX/vector.cpp
Douglas Gregor
dgregor at apple.com
Tue Jun 22 09:52:27 PDT 2010
Author: dgregor
Date: Tue Jun 22 11:52:27 2010
New Revision: 106551
URL: http://llvm.org/viewvc/llvm-project?rev=106551&view=rev
Log:
Don't allow vector conversions to sneak in under the guise of
floating-point conversions or floating-integral conversions. We
really, really, really need to make isFloatingType() and friends not
apply to vector types.
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/vector.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=106551&r1=106550&r2=106551&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Jun 22 11:52:27 2010
@@ -1015,14 +1015,18 @@
// Complex-real conversions (C99 6.3.1.7)
SCS.Second = ICK_Complex_Real;
FromType = ToType.getUnqualifiedType();
- } else if (FromType->isFloatingType() && ToType->isFloatingType()) {
+ } else if (FromType->isFloatingType() && ToType->isFloatingType() &&
+ /*FIXME*/!FromType->isVectorType() &&
+ /*FIXME*/!ToType->isVectorType()) {
// Floating point conversions (C++ 4.8).
SCS.Second = ICK_Floating_Conversion;
FromType = ToType.getUnqualifiedType();
- } else if ((FromType->isFloatingType() &&
+ } else if ((FromType->isFloatingType() &&
+ /*FIXME*/!FromType->isVectorType() &&
ToType->isIntegralType(Context) && !ToType->isBooleanType()) ||
(FromType->isIntegralOrEnumerationType() &&
- ToType->isFloatingType())) {
+ ToType->isFloatingType() &&
+ /*FIXME*/!FromType->isVectorType())) {
// Floating-integral conversions (C++ 4.9).
SCS.Second = ICK_Floating_Integral;
FromType = ToType.getUnqualifiedType();
@@ -1041,7 +1045,8 @@
FromType->isAnyPointerType() ||
FromType->isBlockPointerType() ||
FromType->isMemberPointerType() ||
- FromType->isNullPtrType())) {
+ FromType->isNullPtrType()) &&
+ /*FIXME*/!FromType->isVectorType()) {
// Boolean conversions (C++ 4.12).
SCS.Second = ICK_Boolean_Conversion;
FromType = Context.BoolTy;
Modified: cfe/trunk/test/SemaCXX/vector.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vector.cpp?rev=106551&r1=106550&r2=106551&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/vector.cpp (original)
+++ cfe/trunk/test/SemaCXX/vector.cpp Tue Jun 22 11:52:27 2010
@@ -186,3 +186,33 @@
(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}}
}
+
+typedef float fltx2 __attribute__((__vector_size__(8)));
+typedef float fltx4 __attribute__((__vector_size__(16)));
+typedef double dblx2 __attribute__((__vector_size__(16)));
+typedef double dblx4 __attribute__((__vector_size__(32)));
+
+void accept_fltx2(fltx2); // expected-note{{candidate function not viable: no known conversion from 'double' to 'fltx2' for 1st argument}}
+void accept_fltx4(fltx4);
+void accept_dblx2(dblx2);
+void accept_dblx4(dblx4);
+void accept_bool(bool); // expected-note{{candidate function not viable: no known conversion from 'fltx2' to 'bool' for 1st argument}}
+
+void test(fltx2 fltx2_val, fltx4 fltx4_val, dblx2 dblx2_val, dblx4 dblx4_val) {
+ // Exact matches
+ accept_fltx2(fltx2_val);
+ accept_fltx4(fltx4_val);
+ accept_dblx2(dblx2_val);
+ accept_dblx4(dblx4_val);
+
+ // Same-size conversions
+ // FIXME: G++ rejects these conversions, we accept them. Revisit this!
+ accept_fltx4(dblx2_val);
+ accept_dblx2(fltx4_val);
+
+ // Conversion to bool.
+ accept_bool(fltx2_val); // expected-error{{no matching function for call to 'accept_bool'}}
+
+ // Scalar-to-vector conversions.
+ accept_fltx2(1.0); // expected-error{{no matching function for call to 'accept_fltx2'}}
+}
More information about the cfe-commits
mailing list