[cfe-commits] r143182 - in /cfe/trunk: lib/Sema/Sema.cpp lib/Sema/SemaExpr.cpp test/SemaCXX/vector.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Oct 27 20:31:48 PDT 2011


Author: rsmith
Date: Thu Oct 27 22:31:48 2011
New Revision: 143182

URL: http://llvm.org/viewvc/llvm-project?rev=143182&view=rev
Log:
Add (hopefully) the last missing lvalue-to-rvalue conversion. Add an assertion
to catch some future implicit lvalue-to-rvalue casts of inappropriate kinds.

Modified:
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/vector.cpp

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=143182&r1=143181&r2=143182&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Thu Oct 27 22:31:48 2011
@@ -240,6 +240,20 @@
                                    CastKind Kind, ExprValueKind VK,
                                    const CXXCastPath *BasePath,
                                    CheckedConversionKind CCK) {
+#ifndef NDEBUG
+  if (VK == VK_RValue && !E->isRValue()) {
+    switch (Kind) {
+    default:
+      assert(0 && "can't implicitly cast lvalue to rvalue with this cast kind");
+    case CK_LValueToRValue:
+    case CK_ArrayToPointerDecay:
+    case CK_FunctionToPointerDecay:
+    case CK_ToVoid:
+      break;
+    }
+  }
+#endif
+
   QualType ExprTy = Context.getCanonicalType(E->getType());
   QualType TypeTy = Context.getCanonicalType(Ty);
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=143182&r1=143181&r2=143182&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct 27 22:31:48 2011
@@ -5722,6 +5722,15 @@
 
 QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
                                    SourceLocation Loc, bool IsCompAssign) {
+  if (!IsCompAssign) {
+    LHS = DefaultFunctionArrayLvalueConversion(LHS.take());
+    if (LHS.isInvalid())
+      return QualType();
+  }
+  RHS = DefaultFunctionArrayLvalueConversion(RHS.take());
+  if (RHS.isInvalid())
+    return QualType();
+
   // For conversion purposes, we ignore any qualifiers.
   // For example, "const float" and "float" are equivalent.
   QualType LHSType =
@@ -6819,8 +6828,10 @@
   // x == x, x != x, x < x, etc.  These always evaluate to a constant, and
   // often indicate logic errors in the program.
   if (!LHSType->hasFloatingRepresentation()) {
-    if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(LHS.get()->IgnoreParens()))
-      if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(RHS.get()->IgnoreParens()))
+    if (DeclRefExpr* DRL
+          = dyn_cast<DeclRefExpr>(LHS.get()->IgnoreParenImpCasts()))
+      if (DeclRefExpr* DRR
+            = dyn_cast<DeclRefExpr>(RHS.get()->IgnoreParenImpCasts()))
         if (DRL->getDecl() == DRR->getDecl())
           DiagRuntimeBehavior(Loc, 0,
                               PDiag(diag::warn_comparison_always)

Modified: cfe/trunk/test/SemaCXX/vector.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vector.cpp?rev=143182&r1=143181&r2=143182&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/vector.cpp (original)
+++ cfe/trunk/test/SemaCXX/vector.cpp Thu Oct 27 22:31:48 2011
@@ -218,3 +218,52 @@
   // Scalar-to-vector conversions.
   accept_fltx2(1.0); // expected-error{{no matching function for call to 'accept_fltx2'}}
 }
+
+typedef int intx4 __attribute__((__vector_size__(16)));
+typedef int inte4 __attribute__((__ext_vector_type__(4)));
+typedef int flte4 __attribute__((__ext_vector_type__(4)));
+
+void test_mixed_vector_types(fltx4 f, intx4 n, flte4 g, flte4 m) {
+  (void)(f == g);
+  (void)(g != f);
+  (void)(f <= g);
+  (void)(g >= f);
+  (void)(f < g);
+  (void)(g > f);
+
+  (void)(+g);
+  (void)(-g);
+
+  (void)(f + g);
+  (void)(f - g);
+  (void)(f * g);
+  (void)(f / g);
+  (void)(f = g);
+  (void)(f += g);
+  (void)(f -= g);
+  (void)(f *= g);
+  (void)(f /= g);
+
+
+  (void)(n == m);
+  (void)(m != n);
+  (void)(n <= m);
+  (void)(m >= n);
+  (void)(n < m);
+  (void)(m > n);
+
+  (void)(+m);
+  (void)(-m);
+  (void)(~m);
+
+  (void)(n + m);
+  (void)(n - m);
+  (void)(n * m);
+  (void)(n / m);
+  (void)(n % m);
+  (void)(n = m);
+  (void)(n += m);
+  (void)(n -= m);
+  (void)(n *= m);
+  (void)(n /= m);
+}





More information about the cfe-commits mailing list