[clang] 5c63bf3 - [OpenCL] Add NULL to standards prior to v2.0.

Anastasia Stulova via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 23 03:55:03 PDT 2021


Author: Anastasia Stulova
Date: 2021-07-23T11:54:36+01:00
New Revision: 5c63bf3abdc74b02c58c21cb0571eb4ba12b5235

URL: https://github.com/llvm/llvm-project/commit/5c63bf3abdc74b02c58c21cb0571eb4ba12b5235
DIFF: https://github.com/llvm/llvm-project/commit/5c63bf3abdc74b02c58c21cb0571eb4ba12b5235.diff

LOG: [OpenCL] Add NULL to standards prior to v2.0.

NULL was undefined in OpenCL prior to version 2.0. However, the
language specification states that "macro names defined by the C99
specification but not currently supported by OpenCL are reserved
for future use". Therefore, application developers cannot redefine
NULL.

The change is supposed to resolve inconsistency between language
versions. Currently there is no apparent reason why NULL should
be kept undefined.

Patch by Topotuna (Justas Janickas)!

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

Added: 
    

Modified: 
    clang/lib/Headers/opencl-c-base.h
    clang/test/SemaOpenCL/null_literal.cl

Removed: 
    


################################################################################
diff  --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h
index 1dc52ec75e03..7c724bc2e7a9 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -169,9 +169,7 @@ typedef double double8 __attribute__((ext_vector_type(8)));
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define NULL ((void*)0)
-#endif
 
 /**
  * Value of maximum non-infinite single-precision floating-point

diff  --git a/clang/test/SemaOpenCL/null_literal.cl b/clang/test/SemaOpenCL/null_literal.cl
index e84228a06fc4..f4d55d70aaf8 100644
--- a/clang/test/SemaOpenCL/null_literal.cl
+++ b/clang/test/SemaOpenCL/null_literal.cl
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -verify %s
-
-#define NULL ((void*)0)
+// RUN: %clang_cc1 -cl-std=CL1.0 -fdeclare-opencl-builtins -finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL1.1 -fdeclare-opencl-builtins -finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header -verify %s
 
 void foo(){
 


        


More information about the cfe-commits mailing list