Reject operations between vectors and enum types.
authorErich Keane <erich.keane@intel.com>
Mon, 4 May 2020 20:09:28 +0000 (13:09 -0700)
committerErich Keane <erich.keane@intel.com>
Mon, 4 May 2020 20:11:24 +0000 (13:11 -0700)
There are some lookup oddities with these as reported in PR45780, and
GCC doesn't support these behaviors at all.  To be more consistent with
GCC and prevent the crashes caused by our lookup issues, nip the problem
in the bud and prohibit enums here.

clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/vector-conditional.cpp
clang/test/SemaCXX/vector.cpp

index 7e8446c..871f370 100644 (file)
@@ -1483,7 +1483,7 @@ QualType Sema::UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
     return LHSType;
 
   // ExtInt types aren't subject to conversions between them or normal integers,
-  // so this fails. 
+  // so this fails.
   if(LHSType->isExtIntType() || RHSType->isExtIntType())
     return QualType();
 
@@ -9621,7 +9621,8 @@ static bool tryGCCVectorConvertAndSplat(Sema &S, ExprResult *Scalar,
       ScalarCast = CK_IntegralToFloating;
     } else
       return true;
-  }
+  } else if (ScalarTy->isEnumeralType())
+    return true;
 
   // Adjust scalar if desired.
   if (Scalar) {
index 5676d7a..1b360e4 100644 (file)
@@ -97,7 +97,7 @@ void Operands() {
 
   // When there is a vector and a scalar, conversions must be legal.
   (void)(four_ints ? four_floats : 3); // should work, ints can convert to floats.
-  (void)(four_ints ? four_uints : e);  // should work, non-scoped enum can convert to uint.
+  (void)(four_ints ? four_uints : e);  // expected-error {{cannot convert between scalar type 'E' and vector type 'FourUInts'}}
   (void)(four_ints ? four_uints : se); // expected-error {{cannot convert between vector and non-scalar values ('FourUInts' (vector of 4 'unsigned int' values) and 'SE'}}
   // GCC permits this, but our conversion rules reject this for truncation.
   (void)(two_ints ? two_ints : us);        // expected-error {{cannot convert between scalar type 'unsigned int' and vector type 'TwoInts'}}
index 0c143ba..724ccec 100644 (file)
@@ -484,3 +484,15 @@ template <class T> void f() {
   second_type st;
 }
 }
+
+namespace PR45780 {
+enum E { Value = 15 };
+void use(char16 c) {
+  E e;
+  c &Value;   // expected-error{{cannot convert between scalar type 'PR45780::E' and vector type 'char16'}}
+  c == Value; // expected-error{{cannot convert between scalar type 'PR45780::E' and vector type 'char16'}}
+  e | c;      // expected-error{{cannot convert between scalar type 'PR45780::E' and vector type 'char16'}}
+  e != c;     // expected-error{{cannot convert between scalar type 'PR45780::E' and vector type 'char16'}}
+}
+
+} // namespace PR45780