[cfe-commits] r132116 - /cfe/trunk/lib/Sema/SemaExpr.cpp

Chandler Carruth chandlerc at gmail.com
Thu May 26 01:53:12 PDT 2011


Author: chandlerc
Date: Thu May 26 03:53:12 2011
New Revision: 132116

URL: http://llvm.org/viewvc/llvm-project?rev=132116&view=rev
Log:
Extract the vec_step trait operand checking to a stand alone function.
It has little overlap with other traits' requirements, so the resulting
code is actually simpler.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=132116&r1=132115&r2=132116&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 26 03:53:12 2011
@@ -3054,6 +3054,24 @@
   return Owned(new (Context) ParenExpr(L, R, E));
 }
 
+static bool CheckVecStepTraitOperandType(Sema &S, QualType T,
+                                         SourceLocation Loc,
+                                         SourceRange ArgRange) {
+  // [OpenCL 1.1 6.11.12] "The vec_step built-in function takes a built-in
+  // scalar or vector data type argument..."
+  // Every built-in scalar type (OpenCL 1.1 6.1.1) is either an arithmetic
+  // type (C99 6.2.5p18) or void.
+  if (!(T->isArithmeticType() || T->isVoidType() || T->isVectorType())) {
+    S.Diag(Loc, diag::err_vecstep_non_scalar_vector_type)
+      << T << ArgRange;
+    return true;
+  }
+
+  assert((T->isVoidType() || !T->isIncompleteType()) &&
+         "Scalar types should always be complete");
+  return false;
+}
+
 /// \brief Check the constrains on expression operands to unary type expression
 /// and type traits.
 ///
@@ -3096,18 +3114,8 @@
   if (const ReferenceType *Ref = exprType->getAs<ReferenceType>())
     exprType = Ref->getPointeeType();
 
-  // [OpenCL 1.1 6.11.12] "The vec_step built-in function takes a built-in
-  // scalar or vector data type argument..."
-  // Every built-in scalar type (OpenCL 1.1 6.1.1) is either an arithmetic
-  // type (C99 6.2.5p18) or void.
-  if (ExprKind == UETT_VecStep) {
-    if (!(exprType->isArithmeticType() || exprType->isVoidType() ||
-          exprType->isVectorType())) {
-      Diag(OpLoc, diag::err_vecstep_non_scalar_vector_type)
-        << exprType << ExprRange;
-      return true;
-    }
-  }
+  if (ExprKind == UETT_VecStep)
+    return CheckVecStepTraitOperandType(*this, exprType, OpLoc, ExprRange);
 
   // C99 6.5.3.4p1:
   if (exprType->isFunctionType()) {
@@ -3121,9 +3129,7 @@
   // Allow sizeof(void)/alignof(void) as an extension.  vec_step(void) is not
   // an extension, as void is a built-in scalar type (OpenCL 1.1 6.1.1).
   if (exprType->isVoidType()) {
-    if (ExprKind != UETT_VecStep)
-      Diag(OpLoc, diag::ext_sizeof_void_type)
-        << ExprKind << ExprRange;
+    Diag(OpLoc, diag::ext_sizeof_void_type) << ExprKind << ExprRange;
     return false;
   }
 





More information about the cfe-commits mailing list