From c28b55e4394cdd9a82b05f9b1546cb7e4e06d2ee Mon Sep 17 00:00:00 2001 From: Anastasia Stulova Date: Tue, 7 Feb 2017 16:09:41 +0000 Subject: [PATCH] [OpenCL] Accept logical NOT for pointer types in CL1.1 Fix for bug 30217 - incorrect error given for logical NOT operation with a pointer type: corrected sema check and improved related tests. Review: D29038 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@294313 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 2 +- test/SemaOpenCL/invalid-logical-ops-1.1.cl | 57 ------------------ ...alid-logical-ops-1.2.cl => logical-ops.cl} | 59 +++++++++++++++++++ 3 files changed, 60 insertions(+), 58 deletions(-) delete mode 100644 test/SemaOpenCL/invalid-logical-ops-1.1.cl rename test/SemaOpenCL/{invalid-logical-ops-1.2.cl => logical-ops.cl} (59%) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 95b4b72842..299684d7ab 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -11686,7 +11686,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc, Context.getLangOpts().OpenCLVersion < 120) { // OpenCL v1.1 6.3.h: The logical operator not (!) does not // operate on scalar float types. - if (!resultType->isIntegerType()) + if (!resultType->isIntegerType() && !resultType->isPointerType()) return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) << resultType << Input.get()->getSourceRange()); } diff --git a/test/SemaOpenCL/invalid-logical-ops-1.1.cl b/test/SemaOpenCL/invalid-logical-ops-1.1.cl deleted file mode 100644 index 2269dd322b..0000000000 --- a/test/SemaOpenCL/invalid-logical-ops-1.1.cl +++ /dev/null @@ -1,57 +0,0 @@ -// RUN: %clang_cc1 %s -verify -cl-std=CL1.1 -triple x86_64-unknown-linux-gnu - -#pragma OPENCL EXTENSION cl_khr_fp64 : enable -typedef __attribute__((ext_vector_type(4))) float float4; -typedef __attribute__((ext_vector_type(4))) double double4; -typedef __attribute__((ext_vector_type(4))) int int4; -typedef __attribute__((ext_vector_type(4))) long long4; - -kernel void float_ops() { - int flaf = 0.0f && 0.0f; // expected-error {{invalid operands}} - int flof = 0.0f || 0.0f; // expected-error {{invalid operands}} - float fbaf = 0.0f & 0.0f; // expected-error {{invalid operands}} - float fbof = 0.0f | 0.0f; // expected-error {{invalid operands}} - float fbxf = 0.0f ^ 0.0f; // expected-error {{invalid operands}} - int flai = 0.0f && 0; // expected-error {{invalid operands}} - int floi = 0.0f || 0; // expected-error {{invalid operands}} - float ibaf = 0 & 0.0f; // expected-error {{invalid operands}} - float ibof = 0 | 0.0f; // expected-error {{invalid operands}} - float bnf = ~0.0f; // expected-error {{invalid argument type}} - float lnf = !0.0f; // expected-error {{invalid argument type}} -} - -kernel void vec_float_ops() { - float4 f4 = (float4)(0, 0, 0, 0); - int4 f4laf = f4 && 0.0f; // expected-error {{invalid operands}} - int4 f4lof = f4 || 0.0f; // expected-error {{invalid operands}} - float4 f4baf = f4 & 0.0f; // expected-error {{invalid operands}} - float4 f4bof = f4 | 0.0f; // expected-error {{invalid operands}} - float4 f4bxf = f4 ^ 0.0f; // expected-error {{invalid operands}} - float bnf4 = ~f4; // expected-error {{invalid argument type}} - int4 lnf4 = !f4; // expected-error {{invalid argument type}} -} - -kernel void double_ops() { - int flaf = 0.0 && 0.0; // expected-error {{invalid operands}} - int flof = 0.0 || 0.0; // expected-error {{invalid operands}} - double fbaf = 0.0 & 0.0; // expected-error {{invalid operands}} - double fbof = 0.0 | 0.0; // expected-error {{invalid operands}} - double fbxf = 0.0 ^ 0.0; // expected-error {{invalid operands}} - int flai = 0.0 && 0; // expected-error {{invalid operands}} - int floi = 0.0 || 0; // expected-error {{invalid operands}} - double ibaf = 0 & 0.0; // expected-error {{invalid operands}} - double ibof = 0 | 0.0; // expected-error {{invalid operands}} - double bnf = ~0.0; // expected-error {{invalid argument type}} - double lnf = !0.0; // expected-error {{invalid argument type}} -} - -kernel void vec_double_ops() { - double4 f4 = (double4)(0, 0, 0, 0); - long4 f4laf = f4 && 0.0; // expected-error {{invalid operands}} - long4 f4lof = f4 || 0.0; // expected-error {{invalid operands}} - double4 f4baf = f4 & 0.0; // expected-error {{invalid operands}} - double4 f4bof = f4 | 0.0; // expected-error {{invalid operands}} - double4 f4bxf = f4 ^ 0.0; // expected-error {{invalid operands}} - double bnf4 = ~f4; // expected-error {{invalid argument type}} - long4 lnf4 = !f4; // expected-error {{invalid argument type}} -} diff --git a/test/SemaOpenCL/invalid-logical-ops-1.2.cl b/test/SemaOpenCL/logical-ops.cl similarity index 59% rename from test/SemaOpenCL/invalid-logical-ops-1.2.cl rename to test/SemaOpenCL/logical-ops.cl index bee52396cc..42501b1441 100644 --- a/test/SemaOpenCL/invalid-logical-ops-1.2.cl +++ b/test/SemaOpenCL/logical-ops.cl @@ -1,4 +1,6 @@ +// RUN: %clang_cc1 %s -verify -cl-std=CL1.1 -triple x86_64-unknown-linux-gnu // RUN: %clang_cc1 %s -verify -cl-std=CL1.2 -triple x86_64-unknown-linux-gnu +// RUN: %clang_cc1 %s -verify -cl-std=CL2.0 -triple x86_64-unknown-linux-gnu #pragma OPENCL EXTENSION cl_khr_fp64 : enable @@ -9,50 +11,107 @@ typedef __attribute__((ext_vector_type(4))) long long4; kernel void float_ops() { int flaf = 0.0f && 0.0f; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif int flof = 0.0f || 0.0f; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif float fbaf = 0.0f & 0.0f; // expected-error {{invalid operands}} float fbof = 0.0f | 0.0f; // expected-error {{invalid operands}} float fbxf = 0.0f ^ 0.0f; // expected-error {{invalid operands}} int flai = 0.0f && 0; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif int floi = 0.0f || 0; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif float ibaf = 0 & 0.0f; // expected-error {{invalid operands}} float ibof = 0 | 0.0f; // expected-error {{invalid operands}} float bnf = ~0.0f;// expected-error {{invalid argument type}} float lnf = !0.0f; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid argument type}} +#endif } kernel void vec_float_ops() { float4 f4 = (float4)(0, 0, 0, 0); int4 f4laf = f4 && 0.0f; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif int4 f4lof = f4 || 0.0f; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif float4 f4baf = f4 & 0.0f; // expected-error {{invalid operands}} float4 f4bof = f4 | 0.0f; // expected-error {{invalid operands}} float4 f4bxf = f4 ^ 0.0f; // expected-error {{invalid operands}} float bnf4 = ~f4; // expected-error {{invalid argument type}} int4 lnf4 = !f4; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid argument type}} +#endif } kernel void double_ops() { int flaf = 0.0 && 0.0; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif int flof = 0.0 || 0.0; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif double fbaf = 0.0 & 0.0; // expected-error {{invalid operands}} double fbof = 0.0 | 0.0; // expected-error {{invalid operands}} double fbxf = 0.0 ^ 0.0; // expected-error {{invalid operands}} int flai = 0.0 && 0; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif int floi = 0.0 || 0; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif double ibaf = 0 & 0.0; // expected-error {{invalid operands}} double ibof = 0 | 0.0; // expected-error {{invalid operands}} double bnf = ~0.0; // expected-error {{invalid argument type}} double lnf = !0.0; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid argument type}} +#endif } kernel void vec_double_ops() { double4 f4 = (double4)(0, 0, 0, 0); long4 f4laf = f4 && 0.0; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif long4 f4lof = f4 || 0.0; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid operands}} +#endif double4 f4baf = f4 & 0.0; // expected-error {{invalid operands}} double4 f4bof = f4 | 0.0; // expected-error {{invalid operands}} double4 f4bxf = f4 ^ 0.0; // expected-error {{invalid operands}} double bnf4 = ~f4; // expected-error {{invalid argument type}} long4 lnf4 = !f4; +#if __OPENCL_C_VERSION__ < 120 +// expected-error@-2{{invalid argument type}} +#endif +} + +kernel void pointer_ops(){ + global int* p; + bool b = !p; + b = p==0; + int i; + b = !&i; + b = &i==(int *)1; } -- 2.40.0