r362087 - [OpenCL] Support logical vector operators in C++ mode

Sven van Haastregt via cfe-commits cfe-commits at lists.llvm.org
Thu May 30 05:35:19 PDT 2019


Author: svenvh
Date: Thu May 30 05:35:19 2019
New Revision: 362087

URL: http://llvm.org/viewvc/llvm-project?rev=362087&view=rev
Log:
[OpenCL] Support logical vector operators in C++ mode

Support logical operators on vectors in C++ for OpenCL mode, to
preserve backwards compatibility with OpenCL C.

Differential Revision: https://reviews.llvm.org/D62588

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/CodeGenOpenCL/logical-ops.cl

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=362087&r1=362086&r2=362087&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 30 05:35:19 2019
@@ -10902,7 +10902,7 @@ QualType Sema::CheckVectorLogicalOperand
   if (vType.isNull())
     return InvalidOperands(Loc, LHS, RHS);
   if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion < 120 &&
-      vType->hasFloatingRepresentation())
+      !getLangOpts().OpenCLCPlusPlus && vType->hasFloatingRepresentation())
     return InvalidOperands(Loc, LHS, RHS);
   // FIXME: The check for C++ here is for GCC compatibility. GCC rejects the
   //        usage of the logical operators && and || with vectors in C. This
@@ -13165,7 +13165,8 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
       }
     } else if (resultType->isExtVectorType()) {
       if (Context.getLangOpts().OpenCL &&
-          Context.getLangOpts().OpenCLVersion < 120) {
+          Context.getLangOpts().OpenCLVersion < 120 &&
+          !Context.getLangOpts().OpenCLCPlusPlus) {
         // OpenCL v1.1 6.3.h: The logical operator not (!) does not
         // operate on vector float types.
         QualType T = resultType->getAs<ExtVectorType>()->getElementType();

Modified: cfe/trunk/test/CodeGenOpenCL/logical-ops.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/logical-ops.cl?rev=362087&r1=362086&r2=362087&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/logical-ops.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/logical-ops.cl Thu May 30 05:35:19 2019
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O1 -triple x86_64-unknown-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=c++ -O1 -triple x86_64-unknown-linux-gnu | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 




More information about the cfe-commits mailing list