]> granicus.if.org Git - clang/commitdiff
OpenCL allows the (pre/post)-(increment/decrement) operator on integer vector types,
authorDavid Tweed <david.tweed@arm.com>
Fri, 6 Sep 2013 09:58:08 +0000 (09:58 +0000)
committerDavid Tweed <david.tweed@arm.com>
Fri, 6 Sep 2013 09:58:08 +0000 (09:58 +0000)
so allow that case and add appropriate tests.

Patch by Ruiling Song!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190129 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaOpenCL/vector_inc_dec_ops.cl [new file with mode: 0644]

index 5339c23c03de394fa9a8653c7f6d519b5f742db3..da834cc2519af0f00326754aa93dfd9db62567e9 100644 (file)
@@ -8413,6 +8413,9 @@ static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op,
                                           IsInc, IsPrefix);
   } else if (S.getLangOpts().AltiVec && ResType->isVectorType()) {
     // OK! ( C/C++ Language Extensions for CBEA(Version 2.6) 10.3 )
+  } else if(S.getLangOpts().OpenCL && ResType->isVectorType() &&
+            ResType->getAs<VectorType>()->getElementType()->isIntegerType()) {
+    // OpenCL V1.2 6.3 says dec/inc ops operate on integer vector types.
   } else {
     S.Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement)
       << ResType << int(IsInc) << Op->getSourceRange();
diff --git a/test/SemaOpenCL/vector_inc_dec_ops.cl b/test/SemaOpenCL/vector_inc_dec_ops.cl
new file mode 100644 (file)
index 0000000..c65bbcb
--- /dev/null
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// expected-no-diagnostics
+
+typedef __attribute__((ext_vector_type(2)))  char char2;
+typedef __attribute__((ext_vector_type(4)))  unsigned int uint4;
+typedef __attribute__((ext_vector_type(8)))  long long8;
+
+void vectorIncrementDecrementOps()
+{
+  char2 A = (char2)(1);
+  uint4 B = (uint4)(1);
+  long8 C = (long8)(1);
+
+  A++;
+  --A;
+  B--;
+  ++B;
+  C++;
+}