[clang] [OpenCL] Fix BIenqueue_kernel fallthrough (PR #83238)

2024-04-01 Thread Anastasia Stulova via cfe-commits

https://github.com/AnastasiaStulova approved this pull request.

Makes sense, LGTM! Thanks

https://github.com/llvm/llvm-project/pull/83238
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 380a038 - Updated contact email address.

2022-11-10 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-11-10T19:50:19Z
New Revision: 380a038d147454afb16b97fd9739f4c3d7307401

URL: 
https://github.com/llvm/llvm-project/commit/380a038d147454afb16b97fd9739f4c3d7307401
DIFF: 
https://github.com/llvm/llvm-project/commit/380a038d147454afb16b97fd9739f4c3d7307401.diff

LOG: Updated contact email address.

Added: 


Modified: 
clang/CodeOwners.rst

Removed: 




diff  --git a/clang/CodeOwners.rst b/clang/CodeOwners.rst
index 70662a6a580d..25c8521b2e06 100644
--- a/clang/CodeOwners.rst
+++ b/clang/CodeOwners.rst
@@ -229,7 +229,7 @@ OpenMP conformance
 OpenCL conformance
 ~~
 | Anastasia Stulova
-| anastasia.stulova\@arm.com (email), Anastasia (Phabricator), 
AnastasiaStulova (GitHub)
+| anastasia\@compiler-experts.com (email), Anastasia (Phabricator), 
AnastasiaStulova (GitHub)
 
 
 SYCL conformance



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 790cbaa - [OpenCL] Fix diagnostics with templates in kernel args.

2022-11-10 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-11-10T18:55:12Z
New Revision: 790cbaafc9e276aa740373c00849951338056174

URL: 
https://github.com/llvm/llvm-project/commit/790cbaafc9e276aa740373c00849951338056174
DIFF: 
https://github.com/llvm/llvm-project/commit/790cbaafc9e276aa740373c00849951338056174.diff

LOG: [OpenCL] Fix diagnostics with templates in kernel args.

Improve checking for the standard layout type when diagnosing
the kernel argument with templated types. The check doesn't work
correctly for references or pointers due to the lazy template
instantiation.

Current fix only improves cases where nested types in the templates
do not depend on the template parameters.

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaOpenCLCXX/invalid-kernel.clcpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3bec6b0f65e7b..bac87c0127236 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9234,10 +9234,23 @@ static OpenCLParamType 
getOpenCLKernelParameterType(Sema , QualType PT) {
 // reference if an implementation supports them in kernel parameters.
 if (S.getLangOpts().OpenCLCPlusPlus &&
 !S.getOpenCLOptions().isAvailableOption(
-"__cl_clang_non_portable_kernel_param_types", S.getLangOpts()) &&
-!PointeeType->isAtomicType() && !PointeeType->isVoidType() &&
-!PointeeType->isStandardLayoutType())
+"__cl_clang_non_portable_kernel_param_types", S.getLangOpts())) {
+ auto CXXRec = PointeeType.getCanonicalType()->getAsCXXRecordDecl();
+ bool IsStandardLayoutType = true;
+ if (CXXRec) {
+   // If template type is not ODR-used its definition is only available
+   // in the template definition not its instantiation.
+   // FIXME: This logic doesn't work for types that depend on template
+   // parameter (PR58590).
+   if (!CXXRec->hasDefinition())
+ CXXRec = CXXRec->getTemplateInstantiationPattern();
+   if (!CXXRec || !CXXRec->hasDefinition() || !CXXRec->isStandardLayout())
+ IsStandardLayoutType = false;
+ }
+ if (!PointeeType->isAtomicType() && !PointeeType->isVoidType() &&
+!IsStandardLayoutType)
   return InvalidKernelParam;
+}
 
 return PtrKernelParam;
   }

diff  --git a/clang/test/SemaOpenCLCXX/invalid-kernel.clcpp 
b/clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
index 9bd147364483c..8795fd7173018 100644
--- a/clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
+++ b/clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
@@ -93,3 +93,24 @@ kernel void trivial_r(__global Trivial ) {}
 #ifndef UNSAFEKERNELPARAMETER
 //expected-error@-2{{'__global Trivial &__private' cannot be used as the type 
of a kernel parameter}}
 #endif
+
+// Nested types and templates
+struct Outer {
+  struct Inner{
+int i;
+  };
+};
+template
+struct OuterTempl {
+  struct Inner{
+int i;
+  };
+};
+// FIXME: (PR58590) Use of template parameter dependent types doesn't
+// work yet due to lazy instantiation of reference types.
+//template
+//struct Templ {
+//T i;
+//};
+
+extern kernel void nested(constant Outer::Inner& r1, constant 
OuterTempl::Inner& r2/*, constant Templ& r3*/);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] db664a6 - [Doc][OpenCL] Fixed typos in code examples

2022-09-22 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-09-22T17:46:47+01:00
New Revision: db664a666c2c0cc144c7827dbdad1b893a63408c

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

LOG: [Doc][OpenCL] Fixed typos in code examples

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 17b2f8a00297b..bbaf31cc9792e 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2136,7 +2136,7 @@ between the host and device is known to be compatible.
   struct OnlySL {
 int a;
 int b;
-NotPod() : a(0), b(0) {}
+OnlySL() : a(0), b(0) {}
   };
 
   // Not standard layout type because of two 
diff erent access controls.
@@ -2144,16 +2144,17 @@ between the host and device is known to be compatible.
 int a;
   private:
 int b;
-  }
+  };
 
+  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable
   kernel void kernel_main(
 Pod a,
-  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable
+
 OnlySL b,
 global NotSL *c,
-  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : disable
-global OnlySL *d,
+global OnlySL *d
   );
+  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : disable
 
 Remove address space builtin function
 -



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6b1a045 - [OpenCL][SPIR-V] Test extern functions with a pointer arg.

2022-09-01 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-09-01T10:22:47+01:00
New Revision: 6b1a04529c8fba4019b3a7f56fe6e4938f3a188a

URL: 
https://github.com/llvm/llvm-project/commit/6b1a04529c8fba4019b3a7f56fe6e4938f3a188a
DIFF: 
https://github.com/llvm/llvm-project/commit/6b1a04529c8fba4019b3a7f56fe6e4938f3a188a.diff

LOG: [OpenCL][SPIR-V] Test extern functions with a pointer arg.

Added a test case that enhances coverage of opaque pointers
particularly for the problematic case with extern functions
for which there is no solution found for type recovery.

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

Added: 
clang/test/CodeGenOpenCL/opaque-ptr-spirv.cl

Modified: 


Removed: 




diff  --git a/clang/test/CodeGenOpenCL/opaque-ptr-spirv.cl 
b/clang/test/CodeGenOpenCL/opaque-ptr-spirv.cl
new file mode 100644
index ..93220ef98f18
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/opaque-ptr-spirv.cl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -o - -triple spirv64 %s | 
FileCheck %s
+
+// Check that we have a way to recover pointer
+// types for extern function prototypes (see PR56660).
+extern void foo(global int * ptr);
+kernel void k(global int * ptr) {
+  foo(ptr);
+}
+//CHECK: define spir_kernel void @k(i32 {{.*}}*
+//CHECK: declare spir_func void @foo(i32 {{.*}}*



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7df2597 - [Doc][OpenCL] Misc wording improvements for SPIR-V

2022-05-27 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-05-27T11:13:06+01:00
New Revision: 7df25978ef7882a3d793eecee854ec5d961c02d2

URL: 
https://github.com/llvm/llvm-project/commit/7df25978ef7882a3d793eecee854ec5d961c02d2
DIFF: 
https://github.com/llvm/llvm-project/commit/7df25978ef7882a3d793eecee854ec5d961c02d2.diff

LOG: [Doc][OpenCL] Misc wording improvements for SPIR-V

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
llvm/docs/SPIRVUsage.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index bcd55f6cc841..3fa0c774f5bc 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -25,7 +25,7 @@ Clang also supports :ref:`the C++ for OpenCL kernel language 
`
 available.
 
-
+Details about usage of clang for OpenCL can be found in :doc:`UsersManual`.
 
 Missing features or with limited support
 

diff  --git a/llvm/docs/SPIRVUsage.rst b/llvm/docs/SPIRVUsage.rst
index 7529b5d3b586..0f75e001e661 100644
--- a/llvm/docs/SPIRVUsage.rst
+++ b/llvm/docs/SPIRVUsage.rst
@@ -36,17 +36,17 @@ to specify the target triple:
 
   .. table:: SPIR-V Subarchitectures
 
-  
==
- Architecture Description
-  
==
- ** SPIR-V version deduced by tools based on the compiled input.
- ``v1.0``  SPIR-V version 1.0.
- ``v1.1``  SPIR-V version 1.1.
- ``v1.2``  SPIR-V version 1.2.
- ``v1.3``  SPIR-V version 1.3.
- ``v1.4``  SPIR-V version 1.4.
- ``v1.5``  SPIR-V version 1.5.
-  
==
+ === 
==
+ Subarchitecture Description
+ === 
==
+ **SPIR-V version deduced by tools based on the compiled 
input.
+ ``v1.0`` SPIR-V version 1.0.
+ ``v1.1`` SPIR-V version 1.1.
+ ``v1.2`` SPIR-V version 1.2.
+ ``v1.3`` SPIR-V version 1.3.
+ ``v1.4`` SPIR-V version 1.4.
+ ``v1.5`` SPIR-V version 1.5.
+ === 
==
 
   .. table:: SPIR-V Vendors
 
@@ -71,3 +71,7 @@ to specify the target triple:
  = 
==
  **/``unknown``  Defaults to the OpenCL environment.
  = 
==
+
+Example:
+
+``-target spirv64v1.0`` can be used to compile for SPIR-V version 1.0 with 
64-bit pointer width.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3087afb - [OpenCL][Doc] Misc improvements related to SPIR-V support.

2022-05-26 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-05-26T15:54:33+01:00
New Revision: 3087afb421bf4ca4450d8981a1410e1a09f3794a

URL: 
https://github.com/llvm/llvm-project/commit/3087afb421bf4ca4450d8981a1410e1a09f3794a
DIFF: 
https://github.com/llvm/llvm-project/commit/3087afb421bf4ca4450d8981a1410e1a09f3794a.diff

LOG: [OpenCL][Doc] Misc improvements related to SPIR-V support.

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 6b05b5df1d0b..bcd55f6cc841 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -25,9 +25,19 @@ Clang also supports :ref:`the C++ for OpenCL kernel language 
`
 available.
 
-For general issues and bugs with OpenCL in clang refer to `the GitHub issue
-list
-`__.
+
+
+Missing features or with limited support
+
+
+- For general issues and bugs with OpenCL in clang refer to `the GitHub issue
+  list
+  
`__.
+
+- Command-line flag :ref:`-cl-ext ` (used to override 
extensions/
+  features supported by a target) is missing support of some functionality 
i.e. that is
+  implemented fully through libraries (see :ref:`library-based features and
+  extensions `).
 
 Internals Manual
 
@@ -213,18 +223,22 @@ indicating the presence of the extension should be added 
to clang.
 
 The default flow for adding a new extension into the frontend is to
 modify `OpenCLExtensions.def
-`_
+`__,
+containing the list of all extensions and optional features supported by
+the frontend.
 
 This will add the macro automatically and also add a field in the target
 options ``clang::TargetOptions::OpenCLFeaturesMap`` to control the exposure
 of the new extension during the compilation.
 
-Note that by default targets like `SPIR` or `X86` expose all the OpenCL
+Note that by default targets like `SPIR-V`, `SPIR` or `X86` expose all the 
OpenCL
 extensions. For all other targets the configuration has to be made explicitly.
 
 Note that the target extension support performed by clang can be overridden
 with :ref:`-cl-ext ` command-line flags.
 
+.. _opencl_ext_libs:
+
 **Library functionality**
 
 If an extension adds functionality that does not modify standard language
@@ -239,7 +253,9 @@ for more details refer to
 :ref:`the section on the OpenCL Header `. The macros indicating
 the presence of such extensions can be added in the standard header files
 conditioned on target specific predefined macros or/and language version
-predefined macros.
+predefined macros (see `feature/extension preprocessor macros defined in
+opencl-c-base.h
+`__).
 
 **Pragmas**
 
@@ -336,8 +352,9 @@ user should specify both (extension and feature) in 
command-line flag:
 
.. code-block:: console
 
- $ clang -cc1 -cl-std=CL3.0 -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 ...
- $ clang -cc1 -cl-std=CL3.0 -cl-ext=-cl_khr_fp64,-__opencl_c_fp64 ...
+ $ clang -cl-std=CL3.0 -cl-ext=+cl_khr_fp64,+__opencl_c_fp64 ...
+ $ clang -cl-std=CL3.0 -cl-ext=-cl_khr_fp64,-__opencl_c_fp64 ...
+
 
 
 OpenCL C 3.0 Implementation Status

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 45de85d342c8..b8c468333a67 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3065,7 +3065,7 @@ Compiling to bitcode can be done as follows:
 This will produce a file `test.bc` that can be used in vendor toolchains
 to perform machine code generation.
 
-Note that if compiled to bitcode for generic targets such as SPIR,
+Note that if compiled to bitcode for generic targets such as SPIR/SPIR-V,
 portable IR is produced that can be used with various vendor
 tools as well as open source tools such as `SPIRV-LLVM Translator
 `_
@@ -3073,15 +3073,18 @@ to produce SPIR-V binary. More details are provided in 
`the offline
 compilation from OpenCL kernel sources into SPIR-V using open source
 tools
 
`_.
+From clang 14 onwards SPIR-V can be generated directly as detailed in
+:ref:`the SPIR-V support section `.
 
 Clang currently supports OpenCL C language standards up to v2.0. Clang mainly
 supports full profile. There is only very limited support of the embedded
 profile.
-Starting from clang 9 a C++ mode is available for OpenCL (see
+From clang 9 a C++ mode is available for 

[clang] 730dc4e - [Clang] Added options for integrated backend.

2022-05-25 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-05-25T12:07:33+01:00
New Revision: 730dc4e9bce8189c037a32e520d18b141250d265

URL: 
https://github.com/llvm/llvm-project/commit/730dc4e9bce8189c037a32e520d18b141250d265
DIFF: 
https://github.com/llvm/llvm-project/commit/730dc4e9bce8189c037a32e520d18b141250d265.diff

LOG: [Clang] Added options for integrated backend.

Following the new flow for external object code emission,
provide flags to switch between integrated and external
backend similar to the integrated assembler options.

SPIR-V target is the only user of this functionality at
this point.

This patch also updated SPIR-V documentation to clarify
that integrated object code emission for SPIR-V is an
experimental feature.

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

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/SPIRV.h
clang/test/Driver/clang_f_opts.c
clang/test/Driver/spirv-toolchain.cl

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index aaba6dffd2e5b..45de85d342c80 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3180,8 +3180,8 @@ Generic Targets
 
.. code-block:: console
 
-$ clang -target spirv32 test.cl
-$ clang -target spirv64 test.cl
+$ clang -target spirv32 -c test.cl
+$ clang -target spirv64 -c test.cl
 
   More details can be found in :ref:`the SPIR-V support section `.
 
@@ -3657,8 +3657,8 @@ Example usage for OpenCL kernel compilation:
 
.. code-block:: console
 
- $ clang -target spirv32 test.cl
- $ clang -target spirv64 test.cl
+ $ clang -target spirv32 -c test.cl
+ $ clang -target spirv64 -c test.cl
 
 Both invocations of Clang will result in the generation of a SPIR-V binary file
 `test.o` for 32 bit and 64 bit respectively. This file can be imported
@@ -3669,6 +3669,18 @@ Converting to SPIR-V produced with the optimization 
levels other than `-O0` is
 currently available as an experimental feature and it is not guaranteed to work
 in all cases.
 
+Clang also supports integrated generation of SPIR-V without use of 
``llvm-spirv``
+tool as an experimental feature when ``-fintegrated-objemitter`` flag is 
passed in
+the command line.
+
+   .. code-block:: console
+
+ $ clang -target spirv32 -fintegrated-objemitter -c test.cl
+
+Note that only very basic functionality is supported at this point and 
therefore
+it is not suitable for arbitrary use cases. This feature is only enabled when 
clang
+build is configured with ``-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=SPIRV`` option.
+
 Linking is done using ``spirv-link`` from `the SPIRV-Tools project
 `_. Similar to other 
external
 linkers, Clang will expect ``spirv-link`` to be installed separately and to be
@@ -3676,6 +3688,10 @@ present in the ``PATH`` environment variable. Please 
refer to `the build and
 installation instructions
 `_.
 
+   .. code-block:: console
+
+ $ clang -target spirv64 test1.cl test2.cl
+
 .. _clang-cl:
 
 clang-cl

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 55f4f0999c403..d34cec766a2e2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4170,6 +4170,13 @@ def fno_integrated_cc1 : Flag<["-"], 
"fno-integrated-cc1">,
  Flags<[CoreOption, NoXarchOption]>, Group,
  HelpText<"Spawn a separate process for each cc1">;
 
+def fintegrated_objemitter : Flag<["-"], "fintegrated-objemitter">,
+  Flags<[CoreOption, NoXarchOption]>, Group,
+  HelpText<"Use internal machine object code emitter.">;
+def fno_integrated_objemitter : Flag<["-"], "fno-integrated-objemitter">,
+  Flags<[CoreOption, NoXarchOption]>, Group,
+  HelpText<"Use external machine object code emitter.">;
+
 def : Flag<["-"], "integrated-as">, Alias, 
Flags<[NoXarchOption]>;
 def : Flag<["-"], "no-integrated-as">, Alias,
   Flags<[CC1Option, FlangOption, NoXarchOption]>;

diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 269b24dc83c39..0bc345a970dfb 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -385,11 +385,23 @@ class ToolChain {
   /// by default.
   virtual bool IsIntegratedAssemblerDefault() const { return false; }
 
+  /// IsIntegratedBackendDefault - Does this tool chain enable
+  /// -fintegrated-objemitter by default.
+  virtual bool IsIntegratedBackendDefault() const { return true; }
+
+  /// IsIntegratedBackendSupported - Does this tool chain support
+  /// -fintegrated-objemitter.
+  virtual bool IsIntegratedBackendSupported() const { 

[clang] d61ded1 - [OpenCL] Make -cl-ext a driver option.

2022-05-24 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-05-24T11:34:19+01:00
New Revision: d61ded1034bb9563c43d048ba0be4eff662e6144

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

LOG: [OpenCL] Make -cl-ext a driver option.

For generic targets such as SPIR-V clang sets all OpenCL
extensions/features as supported by default. However
concrete targets are unlikely to support all extensions
features, which creates a problem when such generic SPIR-V
binary is compiled for a specific target later on.

To allow compile time diagnostics for unsupported features
this flag is now being exposed in the clang driver.

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/opencl.cl

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 0a4f81cf5ca11..6b05b5df1d0b4 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -68,31 +68,6 @@ All the options in this section are frontend-only and 
therefore if used
 with regular clang driver they require frontend forwarding, e.g. ``-cc1``
 or ``-Xclang``.
 
-.. _opencl_cl_ext:
-
-.. option:: -cl-ext
-
-Disables support of OpenCL extensions. All OpenCL targets provide a list
-of extensions that they support. Clang allows to amend this using the 
``-cl-ext``
-flag with a comma-separated list of extensions prefixed with ``'+'`` or 
``'-'``.
-The syntax: ``-cl-ext=<(['-'|'+'][,])+>``,  where extensions
-can be either one of `the OpenCL published extensions
-`_
-or any vendor extension. Alternatively, ``'all'`` can be used to enable
-or disable all known extensions.
-
-Example disabling double support for the 64-bit SPIR target:
-
-   .. code-block:: console
-
- $ clang -cc1 -triple spir64-unknown-unknown -cl-ext=-cl_khr_fp64 test.cl
-
-Enabling all extensions except double support in R600 AMD GPU can be done 
using:
-
-   .. code-block:: console
-
- $ clang -cc1 -triple r600-unknown-unknown -cl-ext=-all,+cl_khr_fp16 
test.cl
-
 .. _opencl_finclude_default_header:
 
 .. option:: -finclude-default-header

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 8eb676650ec61..aaba6dffd2e5b 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3120,6 +3120,34 @@ compile.
 More information about the standard types and functions is provided in 
:ref:`the
 section on the OpenCL Header `.
 
+.. _opencl_cl_ext:
+
+.. option:: -cl-ext
+
+Enables/Disables support of OpenCL extensions and optional features. All OpenCL
+targets set a list of extensions that they support. Clang allows to amend this 
using
+the ``-cl-ext`` flag with a comma-separated list of extensions prefixed with
+``'+'`` or ``'-'``. The syntax: ``-cl-ext=<(['-'|'+'][,])+>``,  
where
+extensions can be either one of `the OpenCL published extensions
+`_
+or any vendor extension. Alternatively, ``'all'`` can be used to enable
+or disable all known extensions.
+
+Example disabling double support for the 64-bit SPIR-V target:
+
+   .. code-block:: console
+
+ $ clang -target spirv64 -cl-ext=-cl_khr_fp64 test.cl
+
+Enabling all extensions except double support in R600 AMD GPU can be done 
using:
+
+   .. code-block:: console
+
+ $ clang -target r600 -cl-ext=-all,+cl_khr_fp16 test.cl
+
+Note that some generic targets e.g. SPIR/SPIR-V enable all extensions/features 
in
+clang by default.
+
 OpenCL Targets
 --
 
@@ -3167,9 +3195,8 @@ Generic Targets
 $ clang -target spir test.cl -emit-llvm -c
 $ clang -target spir64 test.cl -emit-llvm -c
 
-  All known OpenCL extensions are supported in the SPIR targets. Clang will
-  generate SPIR v1.2 compatible IR for OpenCL versions up to 2.0 and SPIR v2.0
-  for OpenCL v2.0 or C++ for OpenCL.
+  Clang will generate SPIR v1.2 compatible IR for OpenCL versions up to 2.0 and
+  SPIR v2.0 for OpenCL v2.0 or C++ for OpenCL.
 
 - x86 is used by some implementations that are x86 compatible and currently
   remains for backwards compatibility (with older implementations prior to
@@ -3183,6 +3210,12 @@ Generic Targets
   address space map can be added using the :ref:`-ffake-address-space-map
   ` flag.
 
+  All known OpenCL extensions and features are set to supported in the generic 
targets,
+  however :option:`-cl-ext` flag can be used to toggle individual extensions 
and
+  features.
+
+
+
 .. _opencl_header:
 
 OpenCL Header

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f19734172793a..9888144b7e944 100644
--- 

[clang] 481f681 - [AST] Fix typo in assert messages

2022-03-08 Thread Anastasia Stulova via cfe-commits

Author: Krystian Kuzniarek
Date: 2022-03-08T11:06:50Z
New Revision: 481f6818670aa86e426e326975aa6ea6035d72b3

URL: 
https://github.com/llvm/llvm-project/commit/481f6818670aa86e426e326975aa6ea6035d72b3
DIFF: 
https://github.com/llvm/llvm-project/commit/481f6818670aa86e426e326975aa6ea6035d72b3.diff

LOG: [AST] Fix typo in assert messages

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

Added: 


Modified: 
clang/lib/AST/ASTDiagnostic.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 9f5e5ef1e96e6..0c27c0d14519d 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -372,7 +372,7 @@ void clang::FormatASTNodeDiagnosticArgument(
 default: llvm_unreachable("unknown ArgumentKind");
 case DiagnosticsEngine::ak_addrspace: {
   assert(Modifier.empty() && Argument.empty() &&
- "Invalid modifier for Qualfiers argument");
+ "Invalid modifier for Qualifiers argument");
 
   auto S = Qualifiers::getAddrSpaceAsString(static_cast(Val));
   if (S.empty()) {
@@ -387,7 +387,7 @@ void clang::FormatASTNodeDiagnosticArgument(
 }
 case DiagnosticsEngine::ak_qual: {
   assert(Modifier.empty() && Argument.empty() &&
- "Invalid modifier for Qualfiers argument");
+ "Invalid modifier for Qualifiers argument");
 
   Qualifiers Q(Qualifiers::fromOpaqueValue(Val));
   auto S = Q.getAsString();



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fdd615d - [Docs][OpenCL] Update OpenCL 3.0 status in docs.

2022-02-16 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-02-16T12:32:20Z
New Revision: fdd615d4f91f7bbbf83e4ea6ca45dafb7abc2fa7

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

LOG: [Docs][OpenCL] Update OpenCL 3.0 status in docs.

Reflect the latest development in clang docs.

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 7303c2b4e645b..0a4f81cf5ca11 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -17,8 +17,8 @@
 OpenCL Support
 ==
 
-Clang has complete support of OpenCL C versions from 1.0 to 2.0.
-There is an ongoing work to support :ref:`OpenCL 3.0 `.
+Clang has complete support of OpenCL C versions from 1.0 to 3.0.
+Support for OpenCL 3.0 is in experimental phase (:ref:`OpenCL 3.0 
`).
 
 Clang also supports :ref:`the C++ for OpenCL kernel language 
`.
 
@@ -371,43 +371,43 @@ OpenCL C 3.0 Implementation Status
 The following table provides an overview of features in OpenCL C 3.0 and their
 implementation status.
 
-+--+-+-+--+--+
-| Category | Feature   
| Status   | Reviews
  |
-+==+=+=+==+==+
-| Command line interface   | New value for ``-cl-std`` flag
| :good:`done` | https://reviews.llvm.org/D88300
  |
-+--+-+-+--+--+
-| Predefined macros| New version macro 
| :good:`done` | https://reviews.llvm.org/D88300
  |
-+--+-+-+--+--+
-| Predefined macros| Feature macros
| :good:`done` | https://reviews.llvm.org/D95776
  |
-+--+-+-+--+--+
-| Feature optionality  | Generic address space 
| :good:`done` | https://reviews.llvm.org/D95778 
and https://reviews.llvm.org/D103401 |
-+--+-+-+--+--+
-| Feature optionality  | Builtin function overloads with generic 
address space | :good:`done` | 
https://reviews.llvm.org/D105526 and https://reviews.llvm.org/D107769   
 |
-+--+-+-+--+--+
-| Feature optionality  | Program scope variables in global memory  
| :good:`done` | https://reviews.llvm.org/D103191   
  |
-+--+-+-+--+--+
-| Feature optionality  | 3D image writes including builtin functions   
| :part:`worked on`| https://reviews.llvm.org/D106260 
(frontend)  |

[clang] 0eef650 - [SPIR-V] Remove unused variable

2022-01-11 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-01-11T13:45:59Z
New Revision: 0eef65028e8a2f3417fb19e2eb5b0cbf50600c7e

URL: 
https://github.com/llvm/llvm-project/commit/0eef65028e8a2f3417fb19e2eb5b0cbf50600c7e
DIFF: 
https://github.com/llvm/llvm-project/commit/0eef65028e8a2f3417fb19e2eb5b0cbf50600c7e.diff

LOG: [SPIR-V] Remove unused variable

Added: 


Modified: 
clang/lib/Driver/ToolChains/SPIRV.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index ce6ce5e8998e..27de69550853 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -80,7 +80,6 @@ void SPIRV::Linker::ConstructJob(Compilation , const 
JobAction ,
  const ArgList ,
  const char *LinkingOutput) const {
   const ToolChain  = getToolChain();
-  const Driver  = ToolChain.getDriver();
   std::string Linker = ToolChain.GetProgramPath(getShortName());
   ArgStringList CmdArgs;
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] dbb8d08 - [SPIR-V] Add linking using spirv-link.

2022-01-11 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-01-11T13:11:38Z
New Revision: dbb8d086377ba3a81e44c471840bdbd982c00a35

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

LOG: [SPIR-V] Add linking using spirv-link.

Add support of linking files compiled into SPIR-V objects
using spirv-link.

Command line inteface examples:

clang --target=spirv64 test1.cl test2.cl

clang  --target=spirv64 test1.cl -o test1.o
clang  --target=spirv64 test1.o test2.cl -o test_app.out

This works independently from the SPIR-V generation method
(via an external tool or an internal backend) and applies
to either approach that is being used.

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

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/SPIRV.cpp
clang/lib/Driver/ToolChains/SPIRV.h
clang/test/Driver/spirv-toolchain.cl

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 5f46322f19af2..bdb9705dac637 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3599,6 +3599,13 @@ Converting to SPIR-V produced with the optimization 
levels other than `-O0` is
 currently available as an experimental feature and it is not guaranteed to work
 in all cases.
 
+Linking is done using ``spirv-link`` from `the SPIRV-Tools project
+`_. Similar to other 
external
+linkers, Clang will expect ``spirv-link`` to be installed separately and to be
+present in the ``PATH`` environment variable. Please refer to `the build and
+installation instructions
+`_.
+
 .. _clang-cl:
 
 clang-cl

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index a7fd2f26478cf..3ea32a8876c91 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -116,10 +116,6 @@ def warn_drv_unsupported_option_for_target : Warning<
   "ignoring '%0' option as it is not currently supported for target '%1'">,
   InGroup;
 
-def warn_drv_spirv_linking_multiple_inputs_unsupported: Warning<
-  "Linking multiple input files is not supported for SPIR-V yet">,
-  InGroup;
-
 def err_drv_invalid_thread_model_for_target : Error<
   "invalid thread model '%0' in '%1' for this target">;
 def err_drv_invalid_linker_name : Error<

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 2c3b137554c0b..82d67a8b8b1ab 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3804,14 +3804,6 @@ void Driver::BuildActions(Compilation , DerivedArgList 
,
 }
   }
 
-  // FIXME: Linking separate translation units for SPIR-V is not supported yet.
-  // It can be done either by LLVM IR linking before conversion of the final
-  // linked module to SPIR-V or external SPIR-V linkers can be used e.g.
-  // spirv-link.
-  if (C.getDefaultToolChain().getTriple().isSPIRV() && Inputs.size() > 1) {
-Diag(clang::diag::warn_drv_spirv_linking_multiple_inputs_unsupported);
-  }
-
   handleArguments(C, Args, Inputs, Actions);
 
   // Builder to be used to build offloading actions.
@@ -3851,15 +3843,8 @@ void Driver::BuildActions(Compilation , DerivedArgList 
,
   // Queue linker inputs.
   if (Phase == phases::Link) {
 assert(Phase == PL.back() && "linking must be final compilation 
step.");
-// Compilation phases are setup per language, however for SPIR-V the
-// final linking phase is meaningless since the compilation phase
-// produces the final binary.
-// FIXME: OpenCL - we could strip linking phase out from OpenCL
-// compilation phases if we could verify it is not needed by any 
target.
-if (!C.getDefaultToolChain().getTriple().isSPIRV()) {
-  LinkerInputs.push_back(Current);
-  Current = nullptr;
-}
+LinkerInputs.push_back(Current);
+Current = nullptr;
 break;
   }
 

diff  --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 50d03e79bbb08..ce6ce5e8998e5 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -70,3 +70,25 @@ clang::driver::Tool 
*SPIRVToolChain::getTool(Action::ActionClass AC) const {
   }
   return ToolChain::getTool(AC);
 }
+clang::driver::Tool *SPIRVToolChain::buildLinker() const {
+  return new tools::SPIRV::Linker(*this);
+}
+
+void SPIRV::Linker::ConstructJob(Compilation , const JobAction ,
+ const InputInfo ,
+ const InputInfoList ,
+ 

[clang] 30ad174 - [Docs] Document C++ for OpenCL 2021 support in clang.

2022-01-04 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-01-04T11:18:15Z
New Revision: 30ad1742c08315498e5627fc4b01194564494cb3

URL: 
https://github.com/llvm/llvm-project/commit/30ad1742c08315498e5627fc4b01194564494cb3
DIFF: 
https://github.com/llvm/llvm-project/commit/30ad1742c08315498e5627fc4b01194564494cb3.diff

LOG: [Docs] Document C++ for OpenCL 2021 support in clang.

Along with the new language mode this commit contains misc
small updates for OpenCL 3 and GitHub issues for OpenCL.

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 7ac5707a9901d..c1202601d48d3 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -18,15 +18,16 @@ OpenCL Support
 ==
 
 Clang has complete support of OpenCL C versions from 1.0 to 2.0.
+There is an ongoing work to support :ref:`OpenCL 3.0 `.
 
 Clang also supports :ref:`the C++ for OpenCL kernel language 
`.
 
-There is an ongoing work to support :ref:`OpenCL 3.0 `.
-
-There are also other :ref:`new and experimental features ` 
available.
+There are also other :ref:`new and experimental features `
+available.
 
-For general issues and bugs with OpenCL in clang refer to `Bugzilla
-`__.
+For general issues and bugs with OpenCL in clang refer to `the GitHub issue
+list
+`__.
 
 Internals Manual
 
@@ -127,7 +128,7 @@ To enable modules for OpenCL:
 
.. code-block:: console
 
- $ clang -target spir-unknown-unknown -c -emit-llvm -Xclang 
-finclude-default-header -fmodules -fimplicit-module-maps -fm 
odules-cache-path= test.cl
+ $ clang -target spir-unknown-unknown -c -emit-llvm -Xclang 
-finclude-default-header -fmodules -fimplicit-module-maps 
-fmodules-cache-path= test.cl
 
 Another way to circumvent long parsing latency for the OpenCL builtin
 declarations is to use mechanism enabled by :ref:`-fdeclare-opencl-builtins
@@ -319,24 +320,32 @@ specified in the Clang's source code.
 C++ for OpenCL Implementation Status
 
 
-Clang implements language version 1.0 published in `the official
+Clang implements language versions 1.0 and 2021 published in `the official
 release of C++ for OpenCL Documentation
-`_.
+`_.
 
 Limited support of experimental C++ libraries is described in the 
:ref:`experimental features `.
 
-Bugzilla bugs for this functionality are typically prefixed
+GitHub issues for this functionality are typically prefixed
 with '[C++4OpenCL]' - click `here
-`__
+`__
 to view the full bug list.
 
 
 Missing features or with limited support
 
 
-- IR generation for global destructors is incomplete (See:
+- Support of C++ for OpenCL 2021 is currently in experimental phase. Refer to
+  :ref:`OpenCL 3.0 status ` for details of common missing
+  functionality from OpenCL 3.0.
+
+- IR generation for non-trivial global destructors is incomplete (See:
   `PR48047 `_).
 
+- Support of `destrutors with non-default address spaces
+  
`_
+  is incomplete (See: `D109609 `_).
+
 .. _opencl_300:
 
 OpenCL C 3.0 Usage
@@ -408,8 +417,8 @@ Experimental features
 Clang provides the following new WIP features for the developers to experiment
 and provide early feedback or contribute with further improvements.
 Feel free to contact us on `cfe-dev
-`_ or via `Bugzilla
-`__.
+`_ or file `a GitHub issue
+`_.
 
 .. _opencl_experimental_cxxlibs:
 

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 1173fd337841c..d83b7a27bb3bd 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -41,8 +41,8 @@ specific section:
variants depending on base language.
 -  :ref:`C++ Language `
 -  :ref:`Objective C++ Language `
--  :ref:`OpenCL Kernel Language `: OpenCL C v1.0, v1.1, v1.2, v2.0,
-   plus C++ for OpenCL.
+-  :ref:`OpenCL Kernel Language `: OpenCL C 1.0, 1.1, 1.2, 2.0, 3.0,
+   and C++ 

[clang] dc8f9fb - [Docs] Minor fix in clang user manual

2021-12-24 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-12-24T16:21:56Z
New Revision: dc8f9fb196dab8ca31361928bd6a361dc80d8ade

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

LOG: [Docs] Minor fix in clang user manual

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 3f9947afc29be..26da5a0ff2554 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3537,7 +3537,7 @@ should be built or installed. Please refer to `the 
following instructions
 `_
 for more details. Clang will expects the ``llvm-spirv`` executable to
 be present in the ``PATH`` environment variable. Clang uses ``llvm-spirv``
-with `the conformant assembly syntax package
+with `the widely adopted assembly syntax package
 
`_.
 
 `The versioning



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0045d01 - [SPIR-V] Add a toolchain for SPIR-V in clang

2021-12-23 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-12-23T15:10:09Z
New Revision: 0045d01af96ff56c5b62d133be076020a33867ff

URL: 
https://github.com/llvm/llvm-project/commit/0045d01af96ff56c5b62d133be076020a33867ff
DIFF: 
https://github.com/llvm/llvm-project/commit/0045d01af96ff56c5b62d133be076020a33867ff.diff

LOG: [SPIR-V] Add a toolchain for SPIR-V in clang

This patch adds a toolchain (TC) for SPIR-V along with the
following changes in Driver and base ToolChain and Tool.
This is required to provide a mechanism in clang to bypass
SPIR-V backend in LLVM for SPIR-V until it lands in LLVM and
matures.

The SPIR-V code is generated by the SPIRV-LLVM translator tool
named 'llvm-spirv' that is sought in 'PATH'.

The compilation phases/actions should be bound for SPIR-V in
the meantime as following:

compile -> tools::Clang
backend -> tools::SPIRV::Translator
assemble -> tools::SPIRV::Translator

However, Driver’s ToolSelector collapses compile-backend-assemble
and compile-backend sequences to tools::Clang. To prevent this,
added new {use,has}IntegratedBackend properties in ToolChain and
Tool to which the ToolSelector reacts on, and which SPIR-V TC
overrides.

Linking of multiple input files is currently not supported but
can be added separately.

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

Co-authored-by: Henry Linjamäki 

Added: 
clang/test/Driver/spirv-toolchain.cl

Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Tool.h
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Clang.h
clang/lib/Driver/ToolChains/SPIRV.cpp
clang/lib/Driver/ToolChains/SPIRV.h

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index ce66ef58fca62..3f9947afc29be 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3093,6 +3093,15 @@ There is a set of concrete HW architectures that OpenCL 
can be compiled for.
 Generic Targets
 ^^^
 
+- A SPIR-V binary can be produced for 32 or 64 bit targets.
+
+   .. code-block:: console
+
+$ clang -target spirv32 test.cl
+$ clang -target spirv64 test.cl
+
+  More details can be found in :ref:`the SPIR-V support section `.
+
 - SPIR is available as a generic target to allow portable bitcode to be 
produced
   that can be used across GPU toolchains. The implementation follows `the SPIR
   specification `_. There are two flavors
@@ -3510,6 +3519,51 @@ Clang expects the GCC executable "gcc.exe" compiled for
 `Some tests might fail `_ on
 ``x86_64-w64-mingw32``.
 
+.. _spir-v:
+
+SPIR-V support
+--
+
+Clang supports generation of SPIR-V conformant to `the OpenCL Environment
+Specification
+`_.
+
+To generate SPIR-V binaries, Clang uses the external ``llvm-spirv`` tool from 
the
+`SPIRV-LLVM-Translator repo
+`_.
+
+Prior to the generation of SPIR-V binary with Clang, ``llvm-spirv``
+should be built or installed. Please refer to `the following instructions
+`_
+for more details. Clang will expects the ``llvm-spirv`` executable to
+be present in the ``PATH`` environment variable. Clang uses ``llvm-spirv``
+with `the conformant assembly syntax package
+`_.
+
+`The versioning
+`_ of
+``llvm-spirv`` is aligned with Clang major releases. The same applies to the
+main development branch. It is therefore important to ensure the ``llvm-spirv``
+version is in alignment with the Clang version. For troubleshooting purposes
+``llvm-spirv`` can be `tested in isolation
+`_.
+
+Example usage for OpenCL kernel compilation:
+
+   .. code-block:: console
+
+ $ clang -target spirv32 test.cl
+ $ clang -target spirv64 test.cl
+
+Both invocations of Clang will result in the generation of a SPIR-V binary file
+`test.o` for 32 bit and 64 bit respectively. This file can be imported
+by an OpenCL driver that support SPIR-V consumption or it can be compiled
+further by offline SPIR-V consumer tools.
+
+Converting to SPIR-V produced with the optimization levels other than `-O0` is
+currently available as an experimental feature and it is not guaranteed to work
+in all cases.
+
 .. _clang-cl:
 
 clang-cl

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 

[clang] f4d3cb4 - [HIPSPV] Add CUDA->SPIR-V address space mapping

2021-12-02 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-12-02T13:34:27Z
New Revision: f4d3cb4ca833d0b165d199e78ed8f1d59a8032eb

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

LOG: [HIPSPV] Add CUDA->SPIR-V address space mapping

Add mapping for CUDA address spaces for HIP to SPIR-V
translation. This change allows HIP device code to be
emitted as valid SPIR-V by mapping unqualified pointers
to generic address space and by mapping __device__ and
__shared__ AS to their equivalent AS in SPIR-V
(CrossWorkgroup and Workgroup, respectively).

Cuda's __constant__ AS is handled specially. In HIP
unqualified pointers (aka "flat" pointers) can point to
__constant__ objects. Mapping this AS to ConstantMemory
would produce to illegal address space casts to
generic AS. Therefore, __constant__ AS is mapped to
CrossWorkgroup.

Patch by linjamaki (Henry Linjamäki)!

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

Added: 
clang/test/CodeGenHIP/hipspv-addr-spaces.cpp

Modified: 
clang/lib/Basic/Targets/SPIR.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index 704b1843dfedb..8cf18b6c20f12 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -56,9 +56,14 @@ static const unsigned SPIRDefIsGenMap[] = {
 0, // opencl_generic
 0, // opencl_global_device
 0, // opencl_global_host
-0, // cuda_device
-0, // cuda_constant
-0, // cuda_shared
+// cuda_* address space mapping is intended for HIPSPV (HIP to SPIR-V
+// translation). This mapping is enabled when the language mode is HIP.
+1, // cuda_device
+// cuda_constant pointer can be casted to default/"flat" pointer, but in
+// SPIR-V casts between constant and generic pointers are not allowed. For
+// this reason cuda_constant is mapped to SPIR-V CrossWorkgroup.
+1, // cuda_constant
+3, // cuda_shared
 1, // sycl_global
 5, // sycl_global_device
 6, // sycl_global_host
@@ -74,6 +79,8 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRTargetInfo : public 
TargetInfo {
 protected:
   BaseSPIRTargetInfo(const llvm::Triple , const TargetOptions &)
   : TargetInfo(Triple) {
+assert((Triple.isSPIR() || Triple.isSPIRV()) &&
+   "Invalid architecture for SPIR or SPIR-V.");
 assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
"SPIR(-V) target must use unknown OS");
 assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
@@ -137,11 +144,16 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRTargetInfo : public 
TargetInfo {
 // FIXME: SYCL specification considers unannotated pointers and references
 // to be pointing to the generic address space. See section 5.9.3 of
 // SYCL 2020 specification.
-// Currently, there is no way of representing SYCL's default address space
-// language semantic along with the semantics of embedded C's default
-// address space in the same address space map. Hence the map needs to be
-// reset to allow mapping to the desired value of 'Default' entry for SYCL.
-setAddressSpaceMap(/*DefaultIsGeneric=*/Opts.SYCLIsDevice);
+// Currently, there is no way of representing SYCL's and HIP's default
+// address space language semantic along with the semantics of embedded C's
+// default address space in the same address space map. Hence the map needs
+// to be reset to allow mapping to the desired value of 'Default' entry for
+// SYCL and HIP.
+setAddressSpaceMap(
+/*DefaultIsGeneric=*/Opts.SYCLIsDevice ||
+// The address mapping from HIP language for device code is only 
defined
+// for SPIR-V.
+(getTriple().isSPIRV() && Opts.HIP && Opts.CUDAIsDevice));
   }
 
   void setSupportedOpenCLOpts() override {
@@ -159,6 +171,7 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public 
BaseSPIRTargetInfo {
 public:
   SPIRTargetInfo(const llvm::Triple , const TargetOptions )
   : BaseSPIRTargetInfo(Triple, Opts) {
+assert(Triple.isSPIR() && "Invalid architecture for SPIR.");
 assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
"SPIR target must use unknown OS");
 assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
@@ -177,6 +190,8 @@ class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public 
SPIRTargetInfo {
 public:
   SPIR32TargetInfo(const llvm::Triple , const TargetOptions )
   : SPIRTargetInfo(Triple, Opts) {
+assert(Triple.getArch() == llvm::Triple::spir &&
+   "Invalid architecture for 32-bit SPIR.");
 PointerWidth = PointerAlign = 32;
 SizeType = TargetInfo::UnsignedInt;
 PtrDiffType = IntPtrType = TargetInfo::SignedInt;
@@ -192,6 +207,8 @@ class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public 

[clang] a10a69f - [SPIR-V] Add SPIR-V triple and clang target info.

2021-11-08 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-11-08T13:34:10Z
New Revision: a10a69fe9c74bef3630795d9f2f516d7b84e1cd3

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

LOG: [SPIR-V] Add SPIR-V triple and clang target info.

Add new triple and target info for ‘spirv32’ and ‘spirv64’ and,
thus, enabling clang (LLVM IR) code emission to SPIR-V target.

The target for SPIR-V is mostly reused from SPIR by derivation
from a common base class since IR output for SPIR-V is mostly
the same as SPIR. Some refactoring are made accordingly.

Added and updated tests for parts that are different between
SPIR and SPIR-V.

Patch by linjamaki (Henry Linjamäki)!

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

Added: 
clang/test/CodeGenOpenCL/spirv_target.cl

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/lib/Basic/Targets.cpp
clang/lib/Basic/Targets/SPIR.cpp
clang/lib/Basic/Targets/SPIR.h
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h
clang/test/Headers/opencl-c-header.cl
clang/test/Preprocessor/predefined-macros.c
llvm/include/llvm/ADT/Triple.h
llvm/lib/Support/Triple.cpp
llvm/unittests/ADT/TripleTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0d8c2cb5b67d..60d417fd5770 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1264,8 +1264,9 @@ def OptionIgnored : DiagGroup<"option-ignored">;
 def UnknownArgument : DiagGroup<"unknown-argument">;
 
 // A warning group for warnings about code that clang accepts when
-// compiling OpenCL C/C++ but which is not compatible with the SPIR spec.
+// compiling OpenCL C/C++ but which is not compatible with the SPIR(-V) spec.
 def SpirCompat : DiagGroup<"spir-compat">;
+def : DiagGroup<"spirv-compat", [SpirCompat]>; // Alias.
 
 // Warning for the GlobalISel options.
 def GlobalISel : DiagGroup<"global-isel">;

diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 273eecbd09bf..994a491cddf2 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -606,6 +606,18 @@ TargetInfo *AllocateTarget(const llvm::Triple ,
   return nullptr;
 return new SPIR64TargetInfo(Triple, Opts);
   }
+  case llvm::Triple::spirv32: {
+if (os != llvm::Triple::UnknownOS ||
+Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
+  return nullptr;
+return new SPIRV32TargetInfo(Triple, Opts);
+  }
+  case llvm::Triple::spirv64: {
+if (os != llvm::Triple::UnknownOS ||
+Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
+  return nullptr;
+return new SPIRV64TargetInfo(Triple, Opts);
+  }
   case llvm::Triple::wasm32:
 if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
 Triple.getVendor() != llvm::Triple::UnknownVendor ||

diff  --git a/clang/lib/Basic/Targets/SPIR.cpp 
b/clang/lib/Basic/Targets/SPIR.cpp
index 9b7aab85314a..09d482a8b9ef 100644
--- a/clang/lib/Basic/Targets/SPIR.cpp
+++ b/clang/lib/Basic/Targets/SPIR.cpp
@@ -1,4 +1,4 @@
-//===--- SPIR.cpp - Implement SPIR target feature support 
-===//
+//===--- SPIR.cpp - Implement SPIR and SPIR-V target feature support 
--===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 
//===--===//
 //
-// This file implements SPIR TargetInfo objects.
+// This file implements SPIR and SPIR-V TargetInfo objects.
 //
 
//===--===//
 
@@ -32,3 +32,20 @@ void SPIR64TargetInfo::getTargetDefines(const LangOptions 
,
   SPIRTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIR64", Opts);
 }
+
+void SPIRVTargetInfo::getTargetDefines(const LangOptions ,
+   MacroBuilder ) const {
+  DefineStd(Builder, "SPIRV", Opts);
+}
+
+void SPIRV32TargetInfo::getTargetDefines(const LangOptions ,
+ MacroBuilder ) const {
+  SPIRVTargetInfo::getTargetDefines(Opts, Builder);
+  DefineStd(Builder, "SPIRV32", Opts);
+}
+
+void SPIRV64TargetInfo::getTargetDefines(const LangOptions ,
+ MacroBuilder ) const {
+  SPIRVTargetInfo::getTargetDefines(Opts, Builder);
+  DefineStd(Builder, "SPIRV64", Opts);
+}

diff  --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index 

[clang] fbe00c6 - [OpenCL][Docs] Update OpenCL 3.0 status info.

2021-09-10 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-09-10T13:07:07+01:00
New Revision: fbe00c6874f1f0c496d64933a1a899448b2a

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

LOG: [OpenCL][Docs] Update OpenCL 3.0 status info.

Update info on OpenCLSupport page to reflect changes
committed after release 13 branched.

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 0d7ebca899f7..7bfb471cc381 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -385,9 +385,9 @@ implementation status.
 
+--+-+-+--+--+
 | Feature optionality  | Blocks and Device-side kernel enqueue 
including builtin functions | :none:`unclaimed`|
  |
 
+--+-+-+--+--+
-| Feature optionality  | Pipes including builtin functions 
| :part:`worked on`| https://reviews.llvm.org/D107154 
(frontend) and https://reviews.llvm.org/D105858 (functions) |
+| Feature optionality  | Pipes including builtin functions 
| :good:`done` | https://reviews.llvm.org/D107154 
(frontend) and https://reviews.llvm.org/D105858 (functions) |
 
+--+-+-+--+--+
-| Feature optionality  | Work group collective builtin functions   
| :part:`worked on`| https://reviews.llvm.org/D105858   
  |
+| Feature optionality  | Work group collective builtin functions   
| :good:`done` | https://reviews.llvm.org/D105858   
  |
 
+--+-+-+--+--+
 | Feature optionality  | Image types and builtin functions 
| :good:`done` | https://reviews.llvm.org/D103911 
(frontend) and https://reviews.llvm.org/D107539 (functions) |
 
+--+-+-+--+--+



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9685631 - [OpenCL][Docs] Added ref to libclcxx

2021-09-10 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-09-10T12:29:11+01:00
New Revision: 9685631cbeb85592b713206dd660312dcb7bd9cb

URL: 
https://github.com/llvm/llvm-project/commit/9685631cbeb85592b713206dd660312dcb7bd9cb
DIFF: 
https://github.com/llvm/llvm-project/commit/9685631cbeb85592b713206dd660312dcb7bd9cb.diff

LOG: [OpenCL][Docs] Added ref to libclcxx

Linked libclcxx GitHub project page in C++ libraries
for OpenCL section on OpenCLSupport page.

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index d9309df89a26..0d7ebca899f7 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -458,3 +458,7 @@ The possible clang invocation to compile the example is as 
follows:
 Note that `type_traits` is a header only library and therefore no extra
 linking step against the standard libraries is required. See full example
 in `Compiler Explorer `_.
+
+More OpenCL specific C++ library implementations built on top of libcxx
+are available in `libclcxx `_
+project.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] cff03d5 - [OpenCL][Docs] Update OpenCL 3.0 implementation status.

2021-09-10 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-09-10T12:17:11+01:00
New Revision: cff03d5fc48700b73ae863d4f25e780e74dff33e

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

LOG: [OpenCL][Docs] Update OpenCL 3.0 implementation status.

Update a section of OpenCLSupport page to reflect the latest
development in OpenCL 3.0 support for release 13.

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 2067596954916..d9309df89a266 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -362,41 +362,43 @@ OpenCL C 3.0 Implementation Status
 The following table provides an overview of features in OpenCL C 3.0 and their
 implementation status.
 
-+--+--+--+---+
-| Category | Feature   
   | Status   | Reviews 
  |
-+==+==+==+===+
-| Command line interface   | New value for ``-cl-std`` flag
   | :good:`done` | https://reviews.llvm.org/D88300 
  |
-+--+--+--+---+
-| Predefined macros| New version macro 
   | :good:`done` | https://reviews.llvm.org/D88300 
  |
-+--+--+--+---+
-| Predefined macros| Feature macros
   | :good:`done` | https://reviews.llvm.org/D95776 
  |
-+--+--+--+---+
-| Feature optionality  | Generic address space 
   | :none:`worked on`| https://reviews.llvm.org/D95778 
(partial frontend)|
-+--+--+--+---+
-| Feature optionality  | Builtin function overloads with generic 
address space| :part:`worked on`| https://reviews.llvm.org/D92004   
|
-+--+--+--+---+
-| Feature optionality  | Program scope variables in global memory  
   | :none:`unclaimed`| 
  |
-+--+--+--+---+
-| Feature optionality  | 3D image writes including builtin functions   
   | :none:`unclaimed`| 
  |
-+--+--+--+---+
-| Feature optionality  | read_write images including builtin functions 
   | :none:`unclaimed`| 
  |
-+--+--+--+---+
-| Feature optionality  | C11 atomics memory scopes, ordering and 
builtin function | :part:`worked on`| https://reviews.llvm.org/D92004 
(functions only)  |

[clang] 577220e - [OpenCL] Add std flag aliases clc++1.0 and CLC++1.0

2021-07-30 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-07-30T09:19:26+01:00
New Revision: 577220e89866608e0706e3a2b9f8f48215e4e811

URL: 
https://github.com/llvm/llvm-project/commit/577220e89866608e0706e3a2b9f8f48215e4e811
DIFF: 
https://github.com/llvm/llvm-project/commit/577220e89866608e0706e3a2b9f8f48215e4e811.diff

LOG: [OpenCL] Add std flag aliases clc++1.0 and CLC++1.0

Renamed language standard from openclcpp to openclcpp10.
Added new std values i.e. '-cl-std=clc++1.0' and
'-cl-std=CLC++1.0'.

Patch by Topotuna (Justas Janickas)!

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

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/LangStandards.def
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/autocomplete.c
clang/test/Driver/unknown-std.cl
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 63056e09ac574..838669794ea87 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3297,8 +3297,9 @@ or in `the official release
 
`_.
 
 To enable the C++ for OpenCL mode, pass one of following command line options 
when
-compiling ``.cl`` file ``-cl-std=clc++``, ``-cl-std=CLC++``, ``-std=clc++`` or
-``-std=CLC++``.
+compiling ``.cl`` file ``-cl-std=clc++``, ``-cl-std=CLC++``, 
``-cl-std=clc++1.0``,
+``-cl-std=CLC++1.0``, ``-std=clc++``, ``-std=CLC++``, ``-std=clc++1.0`` or
+``-std=CLC++1.0``.
 
.. code-block:: c++
 

diff  --git a/clang/include/clang/Basic/LangStandards.def 
b/clang/include/clang/Basic/LangStandards.def
index 2cfeb68e56d62..160dc3f2405a7 100644
--- a/clang/include/clang/Basic/LangStandards.def
+++ b/clang/include/clang/Basic/LangStandards.def
@@ -180,17 +180,19 @@ LANGSTANDARD(opencl20, "cl2.0",
 LANGSTANDARD(opencl30, "cl3.0",
  OpenCL, "OpenCL 3.0",
  LineComment | C99 | Digraphs | HexFloat | OpenCL)
-LANGSTANDARD(openclcpp, "clc++",
- OpenCL, "C++ for OpenCL",
+LANGSTANDARD(openclcpp10, "clc++1.0",
+ OpenCL, "C++ for OpenCL 1.0",
  LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 
|
  Digraphs | HexFloat | OpenCL)
+LANGSTANDARD_ALIAS(openclcpp10, "clc++")
 
 LANGSTANDARD_ALIAS_DEPR(opencl10, "CL")
 LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1")
 LANGSTANDARD_ALIAS_DEPR(opencl12, "CL1.2")
 LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0")
 LANGSTANDARD_ALIAS_DEPR(opencl30, "CL3.0")
-LANGSTANDARD_ALIAS_DEPR(openclcpp, "CLC++")
+LANGSTANDARD_ALIAS_DEPR(openclcpp10, "CLC++")
+LANGSTANDARD_ALIAS_DEPR(openclcpp10, "CLC++1.0")
 
 // CUDA
 LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)",

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7e2397c4192f5..819beaffbf9f3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -843,7 +843,8 @@ def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, 
Group,
   HelpText<"OpenCL only. Allow use of less precise no signed zeros 
computations in the generated binary.">,
   MarshallingInfoFlag>;
 def cl_std_EQ : Joined<["-"], "cl-std=">, Group, 
Flags<[CC1Option]>,
-  HelpText<"OpenCL language standard to compile for.">, 
Values<"cl,CL,cl1.0,CL1.0,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,cl3.0,CL3.0,clc++,CLC++">;
+  HelpText<"OpenCL language standard to compile for.">,
+  
Values<"cl,CL,cl1.0,CL1.0,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,cl3.0,CL3.0,clc++,CLC++,clc++1.0,CLC++1.0">;
 def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, 
Group,
   HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;
 def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], 
"cl-fp32-correctly-rounded-divide-sqrt">, Group, 
Flags<[CC1Option]>,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 63436b7aebe1a..ae5c5d43318be 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3091,7 +3091,7 @@ void CompilerInvocation::setLangDefaults(LangOptions 
, InputKind IK,
   LangStd = LangStandard::lang_opencl12;
   break;
 case Language::OpenCLCXX:
-  LangStd = LangStandard::lang_openclcpp;
+  LangStd = LangStandard::lang_openclcpp10;
   break;
 case Language::CUDA:
   LangStd = LangStandard::lang_cuda;
@@ -3164,7 +3164,7 @@ void CompilerInvocation::setLangDefaults(LangOptions 
, InputKind IK,
 Opts.OpenCLVersion = 200;
   else if (LangStd == LangStandard::lang_opencl30)
 Opts.OpenCLVersion = 300;
-  else if (LangStd == LangStandard::lang_openclcpp)
+  else if (LangStd == LangStandard::lang_openclcpp10)
 Opts.OpenCLCPlusPlusVersion = 100;
 
   // OpenCL has some additional 

[clang] e5f47ee - [OpenCL] NULL redefined as nullptr in C++ mode.

2021-07-27 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-07-27T16:33:50+01:00
New Revision: e5f47eedeb02595247e433ad756607e6c1397ae3

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

LOG: [OpenCL] NULL redefined as nullptr in C++ mode.

Redefines NULL as nullptr instead of ((void*)0)
in C++ for OpenCL.

Such internal representation of NULL provides
compatibility with C++11 and later language
standards.

Patch by Topotuna (Justas Janickas)!

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

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 b5029a254b7a8..3c5e2c9739368 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -169,7 +169,11 @@ typedef double double8 __attribute__((ext_vector_type(8)));
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
+#if defined(__OPENCL_CPP_VERSION__)
+#define NULL nullptr
+#elif defined(__OPENCL_C_VERSION__)
 #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 f4d55d70aaf89..b641c6bd7c6dd 100644
--- a/clang/test/SemaOpenCL/null_literal.cl
+++ b/clang/test/SemaOpenCL/null_literal.cl
@@ -2,27 +2,46 @@
 // 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
+// RUN: %clang_cc1 -cl-std=clc++ -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
 
 void foo(){
 
 global int* ptr1 = NULL;
 
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+2{{cannot initialize a variable of type '__global int 
*__private' with an rvalue of type '__global void *'}}
+#endif
 global int* ptr2 = (global void*)0;
 
 constant int* ptr3 = NULL;
 
-constant int* ptr4 = (global void*)0; // expected-error{{initializing 
'__constant int *__private' with an expression of type '__global void *' 
changes address space of pointer}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{cannot initialize a variable of type '__constant int 
*__private' with an rvalue of type '__global void *'}}
+#else
+// expected-error@+2{{initializing '__constant int *__private' with an 
expression of type '__global void *' changes address space of pointer}}
+#endif
+constant int* ptr4 = (global void*)0;
 
 #if __OPENCL_C_VERSION__ == CL_VERSION_2_0
 // Accept explicitly pointer to generic address space in OpenCL v2.0.
 global int* ptr5 = (generic void*)0;
 #endif
 
-global int* ptr6 = (local void*)0; // expected-error{{initializing '__global 
int *__private' with an expression of type '__local void *' changes address 
space of pointer}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{cannot initialize a variable of type '__global int 
*__private' with an rvalue of type '__local void *'}}
+#else
+// expected-error@+2{{initializing '__global int *__private' with an 
expression of type '__local void *' changes address space of pointer}}
+#endif
+global int* ptr6 = (local void*)0;
 
 bool cmp = ptr1 == NULL;
 
-cmp = ptr1 == (local void*)0; // expected-error{{comparison between  
('__global int *' and '__local void *') which are pointers to non-overlapping 
address spaces}}
+#if defined(__OPENCL_CPP_VERSION__)
+// expected-error@+4{{comparison of distinct pointer types ('__global int *' 
and '__local void *')}}
+#else
+// expected-error@+2{{comparison between  ('__global int *' and '__local void 
*') which are pointers to non-overlapping address spaces}}
+#endif
+cmp = ptr1 == (local void*)0;
 
 cmp = ptr3 == NULL;
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8160016 - [OpenCL] Change default standard version to CL1.2

2021-07-26 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-07-26T15:04:34+01:00
New Revision: 81600160b3f926746d02c52003d81180941fe9d0

URL: 
https://github.com/llvm/llvm-project/commit/81600160b3f926746d02c52003d81180941fe9d0
DIFF: 
https://github.com/llvm/llvm-project/commit/81600160b3f926746d02c52003d81180941fe9d0.diff

LOG: [OpenCL] Change default standard version to CL1.2

Set default version for OpenCL C to 1.2. This means that the
absence of any standard flag will be equivalent to passing
'-cl-std=CL1.2'.

Note that this patch also fixes incorrect version check for
the pointer to pointer kernel arguments diagnostic and
atomic test.

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

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenOpenCL/spir_version.cl
clang/test/Parser/opencl-atomics-cl20.cl
clang/test/Parser/opencl-cl20.cl
clang/test/Parser/opencl-storage-class.cl
clang/test/Preprocessor/predefined-macros.c
clang/test/SemaOpenCL/fp64-fp16-options.cl
clang/test/SemaOpenCL/func.cl

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index a8f25fa7c11c4..d545e9358f048 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3088,7 +3088,7 @@ void CompilerInvocation::setLangDefaults(LangOptions 
, InputKind IK,
 case Language::LLVM_IR:
   llvm_unreachable("Invalid input kind!");
 case Language::OpenCL:
-  LangStd = LangStandard::lang_opencl10;
+  LangStd = LangStandard::lang_opencl12;
   break;
 case Language::OpenCLCXX:
   LangStd = LangStandard::lang_openclcpp;

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b25c3650b1607..205f580003029 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8819,7 +8819,7 @@ static void checkIsValidOpenCLKernelParameter(
 // OpenCL v3.0 s6.11.a:
 // A kernel function argument cannot be declared as a pointer to a pointer
 // type. [...] This restriction only applies to OpenCL C 1.2 or below.
-if (S.getLangOpts().OpenCLVersion < 120 &&
+if (S.getLangOpts().OpenCLVersion <= 120 &&
 !S.getLangOpts().OpenCLCPlusPlus) {
   S.Diag(Param->getLocation(), diag::err_opencl_ptrptr_kernel_param);
   D.setInvalidType();

diff  --git a/clang/test/CodeGenOpenCL/spir_version.cl 
b/clang/test/CodeGenOpenCL/spir_version.cl
index 39893de0f56d0..b0fa0c2355af9 100644
--- a/clang/test/CodeGenOpenCL/spir_version.cl
+++ b/clang/test/CodeGenOpenCL/spir_version.cl
@@ -1,14 +1,13 @@
-// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-SPIR-CL10
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.0 | FileCheck %s --check-prefix=CHECK-SPIR-CL10
 // RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.2 | FileCheck %s --check-prefix=CHECK-SPIR-CL12
 // RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CHECK-SPIR-CL20
-// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - | 
FileCheck %s --check-prefix=CHECK-SPIR-CL10
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.0 | FileCheck %s --check-prefix=CHECK-SPIR-CL10
 // RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.2 | FileCheck %s --check-prefix=CHECK-SPIR-CL12
 // RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CHECK-SPIR-CL20
 
-
 // RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=clc++ | FileCheck %s --check-prefix=CHECK-SPIR-CL20
 
-// RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - | FileCheck %s 
--check-prefix=CHECK-AMDGCN-CL10
+// RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -cl-std=CL1.0 | 
FileCheck %s --check-prefix=CHECK-AMDGCN-CL10
 // RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -cl-std=CL1.2 | 
FileCheck %s --check-prefix=CHECK-AMDGCN-CL12
 // RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -cl-std=CL2.0 | 
FileCheck %s --check-prefix=CHECK-AMDGCN-CL20
 

diff  --git a/clang/test/Parser/opencl-atomics-cl20.cl 
b/clang/test/Parser/opencl-atomics-cl20.cl
index c3f86b6a44c49..50866dd61591e 100644
--- a/clang/test/Parser/opencl-atomics-cl20.cl
+++ b/clang/test/Parser/opencl-atomics-cl20.cl
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 %s -triple spir64-unknown-unknown -verify -fsyntax-only 
-cl-std=CLC++
 // RUN: %clang_cc1 %s -triple spir64-unknown-unknown -verify -fsyntax-only 
-cl-std=CL2.0 -cl-ext=-cl_khr_int64_base_atomics
 
-#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#if defined(__OPENCL_CPP_VERSION__) || 

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

2021-07-23 Thread Anastasia Stulova via cfe-commits

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(){
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b510e01 - [OpenCL][NFC] Refactors lang version check in test.

2021-07-22 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-07-22T16:47:38+01:00
New Revision: b510e0127da38d47b9224b082842e827c04947a8

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

LOG: [OpenCL][NFC] Refactors lang version check in test.

Fixed test to use predefined version marco instead
of passing extra macro in the command line.

Patch by Topotuna (Justas Janickas)!

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

Added: 


Modified: 
clang/test/SemaOpenCL/null_literal.cl

Removed: 




diff  --git a/clang/test/SemaOpenCL/null_literal.cl 
b/clang/test/SemaOpenCL/null_literal.cl
index fb0f938d5952a..e84228a06fc41 100644
--- a/clang/test/SemaOpenCL/null_literal.cl
+++ b/clang/test/SemaOpenCL/null_literal.cl
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -DCL20 -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -verify %s
 
 #define NULL ((void*)0)
 
@@ -13,7 +13,7 @@ constant int* ptr3 = NULL;
 
 constant int* ptr4 = (global void*)0; // expected-error{{initializing 
'__constant int *__private' with an expression of type '__global void *' 
changes address space of pointer}}
 
-#ifdef CL20
+#if __OPENCL_C_VERSION__ == CL_VERSION_2_0
 // Accept explicitly pointer to generic address space in OpenCL v2.0.
 global int* ptr5 = (generic void*)0;
 #endif



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5ccc79d - [OpenCL][Docs] Minor update to OpenCL 3.0

2021-05-24 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-24T14:19:22+01:00
New Revision: 5ccc79dc38b2df18cca5a9b4d66dcd4603f948e9

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

LOG: [OpenCL][Docs] Minor update to OpenCL 3.0

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index dbfb67f90ae1..2a6b9a0b7346 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -340,7 +340,7 @@ Missing features or with limited support
 .. _opencl_300:
 
 OpenCL C 3.0 Usage
-
+==
 
 OpenCL C 3.0 language standard makes most OpenCL C 2.0 features optional. 
Optional
 functionality in OpenCL C 3.0 is indicated with the presence of feature-test 
macros
@@ -357,7 +357,7 @@ user should specify both (extension and feature) in 
command-line flag:
 
 
 OpenCL C 3.0 Implementation Status
-
+--
 
 The following table provides an overview of features in OpenCL C 3.0 and their
 implementation status.
@@ -371,7 +371,7 @@ implementation status.
 
+--+--+--+---+
 | Predefined macros| Feature macros
   | :good:`done` | https://reviews.llvm.org/D95776 
  |
 
+--+--+--+---+
-| Feature optionality  | Generic address space 
   | :none:`unclaimed`| 
  |
+| Feature optionality  | Generic address space 
   | :none:`worked on`| https://reviews.llvm.org/D95778 
(partial frontend)|
 
+--+--+--+---+
 | Feature optionality  | Builtin function overloads with generic 
address space| :part:`worked on`| https://reviews.llvm.org/D92004   
|
 
+--+--+--+---+
@@ -389,6 +389,8 @@ implementation status.
 
+--+--+--+---+
 | Feature optionality  | Work group collective functions   
   | :part:`worked on`| https://reviews.llvm.org/D92004 
  |
 
+--+--+--+---+
+| Feature optionality  | Image types   
   | :part:`unclaimed`| 
  |
++--+--+--+---+
 | New functionality| RGBA vector components
   | :good:`done` | https://reviews.llvm.org/D99969 
  |
 
+--+--+--+---+
 | New functionality| Subgroup functions
   | :part:`worked on`| https://reviews.llvm.org/D92004 
  |



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 626e964 - [OpenCL] Fix test by adding SPIR triple

2021-05-24 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-24T13:03:50+01:00
New Revision: 626e9641a2f5fde638b86d4e043f82fc58b908f8

URL: 
https://github.com/llvm/llvm-project/commit/626e9641a2f5fde638b86d4e043f82fc58b908f8
DIFF: 
https://github.com/llvm/llvm-project/commit/626e9641a2f5fde638b86d4e043f82fc58b908f8.diff

LOG: [OpenCL] Fix test by adding SPIR triple

Added: 


Modified: 
clang/test/SemaOpenCL/unsupported.cl

Removed: 




diff  --git a/clang/test/SemaOpenCL/unsupported.cl 
b/clang/test/SemaOpenCL/unsupported.cl
index 36f60259f8a7..75175c88fe26 100644
--- a/clang/test/SemaOpenCL/unsupported.cl
+++ b/clang/test/SemaOpenCL/unsupported.cl
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -verify %s -DBITFIELDS_EXT
+// RUN: %clang_cc1 -verify %s -DBITFIELDS_EXT -triple spir
 
 #ifdef BITFIELDS_EXT
 #pragma OPENCL EXTENSION __cl_clang_bitfields : enable



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 237c692 - [OpenCL] Add clang extension for bit-fields.

2021-05-24 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-24T12:42:17+01:00
New Revision: 237c6924bd46ec0e33da71f9616caf9bf9965b23

URL: 
https://github.com/llvm/llvm-project/commit/237c6924bd46ec0e33da71f9616caf9bf9965b23
DIFF: 
https://github.com/llvm/llvm-project/commit/237c6924bd46ec0e33da71f9616caf9bf9965b23.diff

LOG: [OpenCL] Add clang extension for bit-fields.

Allow use of bit-fields as a clang extension
in OpenCL. The extension can be enabled using
pragma directives.

This fixes PR45339!

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/OpenCLExtensions.def
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Sema/SemaDecl.cpp
clang/test/Misc/amdgcn.languageOptsOpenCL.cl
clang/test/Misc/nvptx.languageOptsOpenCL.cl
clang/test/Misc/r600.languageOptsOpenCL.cl
clang/test/SemaOpenCL/unsupported.cl

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 235bcac8f00f4..eb9fe0c0ac0d7 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1741,6 +1741,34 @@ OpenCL Features
 
 Clang supports internal OpenCL extensions documented below.
 
+``__cl_clang_bitfields``
+
+
+With this extension it is possible to enable bitfields in structs
+or unions using the OpenCL extension pragma mechanism detailed in
+`the OpenCL Extension Specification, section 1.2
+`_.
+
+Use of bitfields in OpenCL kernels can result in reduced portability as struct
+layout is not guaranteed to be consistent when compiled by 
diff erent compilers.
+If structs with bitfields are used as kernel function parameters, it can result
+in incorrect functionality when the layout is 
diff erent between the host and
+device code.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  #pragma OPENCL EXTENSION __cl_clang_bitfields : enable
+  struct with_bitfield {
+unsigned int i : 5; // compiled - no diagnostic generated
+  };
+
+  #pragma OPENCL EXTENSION __cl_clang_bitfields : disable
+  struct without_bitfield {
+unsigned int i : 5; // error - bitfields are not supported
+  };
+
 ``__cl_clang_function_pointers``
 
 

diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index a0f01a2af9c37..a053a0e9adb59 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -88,6 +88,7 @@ OPENCL_EXTENSION(cl_clang_storage_class_specifiers, true, 100)
 OPENCL_EXTENSION(__cl_clang_function_pointers, true, 100)
 OPENCL_EXTENSION(__cl_clang_variadic_functions, true, 100)
 OPENCL_EXTENSION(__cl_clang_non_portable_kernel_param_types, true, 100)
+OPENCL_EXTENSION(__cl_clang_bitfields, true, 100)
 
 // AMD OpenCL extensions
 OPENCL_EXTENSION(cl_amd_media_ops, true, 100)

diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 2729c515bb650..fe5c61c6ba2bb 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -288,6 +288,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
 Opts["__cl_clang_variadic_functions"] = true;
 Opts["__cl_clang_function_pointers"] = true;
 Opts["__cl_clang_non_portable_kernel_param_types"] = true;
+Opts["__cl_clang_bitfields"] = true;
 
 bool IsAMDGCN = isAMDGCN(getTriple());
 

diff  --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h
index c429d5501337a..c7db3cdaaf10a 100644
--- a/clang/lib/Basic/Targets/NVPTX.h
+++ b/clang/lib/Basic/Targets/NVPTX.h
@@ -136,6 +136,7 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public 
TargetInfo {
 Opts["__cl_clang_function_pointers"] = true;
 Opts["__cl_clang_variadic_functions"] = true;
 Opts["__cl_clang_non_portable_kernel_param_types"] = true;
+Opts["__cl_clang_bitfields"] = true;
 
 Opts["cl_khr_fp64"] = true;
 Opts["__opencl_c_fp64"] = true;

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6d6b8b5e797da..601f4f2502f0a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16815,8 +16815,10 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, 
QualType T,
   Record->setInvalidDecl();
   InvalidDecl = true;
 }
-// OpenCL v1.2 s6.9.c: bitfields are not supported.
-if (BitWidth) {
+// OpenCL v1.2 s6.9.c: bitfields are not supported, unless Clang extension
+// is enabled.
+if (BitWidth && !getOpenCLOptions().isAvailableOption(
+"__cl_clang_bitfields", LangOpts)) {
   Diag(Loc, diag::err_opencl_bitfields);
   InvalidDecl = true;
 }

diff  --git 

[clang] 3549466 - [OpenCL] Drop pragma handling for extension types/decls.

2021-05-17 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-17T12:09:43+01:00
New Revision: 3549466ac05eda57c9ce13abd7cb6dd365f6d8d6

URL: 
https://github.com/llvm/llvm-project/commit/3549466ac05eda57c9ce13abd7cb6dd365f6d8d6
DIFF: 
https://github.com/llvm/llvm-project/commit/3549466ac05eda57c9ce13abd7cb6dd365f6d8d6.diff

LOG: [OpenCL] Drop pragma handling for extension types/decls.

Drop non-conformant extension pragma implementation as
it does not properly disable anything and therefore
enabling non-disabled logic has no meaning.

This simplifies clang code and user interface to the extension
functionality. With this patch extension pragma 'begin'/'end'
and 'enable'/'disable' are only accepted for backward
compatibility and no longer have any default behavior.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Overload.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/SemaOpenCL/extension-begin.cl
clang/test/SemaOpenCL/extension-begin.h

Removed: 
clang/test/CodeGenOpenCL/extension-begin.cl



diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 9a3f7adc619ba..97cb7020f3452 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1239,8 +1239,6 @@ def warn_pragma_expected_colon : Warning<
   "missing ':' after %0 - ignoring">, InGroup;
 def warn_pragma_expected_predicate : Warning<
   "expected %select{'enable', 'disable', 'begin' or 'end'|'disable'}0 - 
ignoring">, InGroup;
-def warn_pragma_begin_end_mismatch : Warning<
-  "OpenCL extension end directive mismatches begin directive - ignoring">, 
InGroup;
 def warn_pragma_unknown_extension : Warning<
   "unknown OpenCL extension %0 - ignoring">, InGroup;
 def warn_pragma_unsupported_extension : Warning<

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0683469506e9b..9dd9b1b5118b5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4372,8 +4372,6 @@ def warn_diagnose_if_succeeded : Warning<"%0">, 
InGroup,
 ShowInSystemHeader;
 def note_ovl_candidate_disabled_by_function_cond_attr : Note<
 "candidate disabled: %0">;
-def note_ovl_candidate_disabled_by_extension : Note<
-"candidate unavailable as it requires OpenCL extension '%0' to be 
enabled">;
 def err_addrof_function_disabled_by_enable_if_attr : Error<
 "cannot take address of function %0 because it has one or more "
 "non-tautological enable_if conditions">;

diff  --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 5be6a618711cd..699c3e8088726 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -760,9 +760,6 @@ class Sema;
 /// This candidate was not viable because its address could not be taken.
 ovl_fail_addr_not_available,
 
-/// This candidate was not viable because its OpenCL extension is disabled.
-ovl_fail_ext_disabled,
-
 /// This inherited constructor is not viable because it would slice the
 /// argument.
 ovl_fail_inhctor_slice,

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 135da703c4df9..3a8f41196cc4a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10142,73 +10142,6 @@ class Sema final {
   /// potentially-throwing.
   bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend);
 
-  
//======//
-  // OpenCL extensions.
-  //
-private:
-  std::string CurrOpenCLExtension;
-  /// Extensions required by an OpenCL type.
-  llvm::DenseMap> OpenCLTypeExtMap;
-  /// Extensions required by an OpenCL declaration.
-  llvm::DenseMap> OpenCLDeclExtMap;
-public:
-  llvm::StringRef getCurrentOpenCLExtension() const {
-return CurrOpenCLExtension;
-  }
-
-  /// Check if a function declaration \p FD associates with any
-  /// extensions present in OpenCLDeclExtMap and if so return the
-  /// extension(s) name(s).
-  std::string getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD);
-
-  /// Check if a function type \p FT associates with any
-  /// extensions present in OpenCLTypeExtMap and if so return the
-  /// extension(s) name(s).
-  std::string 

[clang] 769cc33 - [OpenCL] Simplify use of C11 atomic types.

2021-05-14 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-14T17:43:00+01:00
New Revision: 769cc335e6e63e5eac0c0ac849de44714326e20b

URL: 
https://github.com/llvm/llvm-project/commit/769cc335e6e63e5eac0c0ac849de44714326e20b
DIFF: 
https://github.com/llvm/llvm-project/commit/769cc335e6e63e5eac0c0ac849de44714326e20b.diff

LOG: [OpenCL] Simplify use of C11 atomic types.

Remove requirements on extension pragma in atomic types
because it has not respected the spec wrt disabling types
and hasn't been useful either. With this change, the
developers can use atomic types from the extensions if they
are supported without enabling the pragma just like the builtin
functions

This patch does not break backward compatibility since the
extension pragma is still supported and it makes the behavior of
the compiler less strict by accepting code without needless and
inconsistent pragma statements.

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

Added: 


Modified: 
clang/lib/Sema/Sema.cpp
clang/test/Parser/opencl-atomics-cl20.cl

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 72e2ee613cbf4..36fcadfc9b9b7 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -313,8 +313,7 @@ void Sema::Initialize() {
   // OpenCLC v2.0, s6.13.11.6 requires that atomic_flag is implemented as
   // 32-bit integer and OpenCLC v2.0, s6.1.1 int is always 32-bit wide.
   addImplicitTypedef("atomic_flag", Context.getAtomicType(Context.IntTy));
-  auto AtomicSizeT = Context.getAtomicType(Context.getSizeType());
-  addImplicitTypedef("atomic_size_t", AtomicSizeT);
+
 
   // OpenCL v2.0 s6.13.11.6:
   // - The atomic_long and atomic_ulong types are supported if the
@@ -327,6 +326,23 @@ void Sema::Initialize() {
   //   atomic_intptr_t, atomic_uintptr_t, atomic_size_t and
   //   atomic_ptr
diff _t are supported if the cl_khr_int64_base_atomics and
   //   cl_khr_int64_extended_atomics extensions are supported.
+
+  auto AddPointerSizeDependentTypes = [&]() {
+auto AtomicSizeT = Context.getAtomicType(Context.getSizeType());
+auto AtomicIntPtrT = Context.getAtomicType(Context.getIntPtrType());
+auto AtomicUIntPtrT = Context.getAtomicType(Context.getUIntPtrType());
+auto AtomicPtrDiffT =
+Context.getAtomicType(Context.getPointerDiffType());
+addImplicitTypedef("atomic_size_t", AtomicSizeT);
+addImplicitTypedef("atomic_intptr_t", AtomicIntPtrT);
+addImplicitTypedef("atomic_uintptr_t", AtomicUIntPtrT);
+addImplicitTypedef("atomic_ptr
diff _t", AtomicPtrDiffT);
+  };
+
+  if (Context.getTypeSize(Context.getSizeType()) == 32) {
+AddPointerSizeDependentTypes();
+  }
+
   std::vector Atomic64BitTypes;
   if (getOpenCLOptions().isSupported("cl_khr_int64_base_atomics",
  getLangOpts()) &&
@@ -335,35 +351,18 @@ void Sema::Initialize() {
 if (getOpenCLOptions().isSupported("cl_khr_fp64", getLangOpts())) {
   auto AtomicDoubleT = Context.getAtomicType(Context.DoubleTy);
   addImplicitTypedef("atomic_double", AtomicDoubleT);
-  setOpenCLExtensionForType(AtomicDoubleT, "cl_khr_fp64");
   Atomic64BitTypes.push_back(AtomicDoubleT);
 }
 auto AtomicLongT = Context.getAtomicType(Context.LongTy);
 auto AtomicULongT = Context.getAtomicType(Context.UnsignedLongTy);
-auto AtomicIntPtrT = Context.getAtomicType(Context.getIntPtrType());
-auto AtomicUIntPtrT = Context.getAtomicType(Context.getUIntPtrType());
-auto AtomicPtrDiffT =
-Context.getAtomicType(Context.getPointerDiffType());
-
 addImplicitTypedef("atomic_long", AtomicLongT);
 addImplicitTypedef("atomic_ulong", AtomicULongT);
-addImplicitTypedef("atomic_intptr_t", AtomicIntPtrT);
-addImplicitTypedef("atomic_uintptr_t", AtomicUIntPtrT);
-addImplicitTypedef("atomic_ptr
diff _t", AtomicPtrDiffT);
 
-Atomic64BitTypes.push_back(AtomicLongT);
-Atomic64BitTypes.push_back(AtomicULongT);
-if (Context.getTypeSize(AtomicSizeT) == 64) {
-  Atomic64BitTypes.push_back(AtomicSizeT);
-  Atomic64BitTypes.push_back(AtomicIntPtrT);
-  Atomic64BitTypes.push_back(AtomicUIntPtrT);
-  Atomic64BitTypes.push_back(AtomicPtrDiffT);
+
+if (Context.getTypeSize(Context.getSizeType()) == 64) {
+  AddPointerSizeDependentTypes();
 }
   }
-
-  for (auto  : Atomic64BitTypes)
-setOpenCLExtensionForType(I,
-"cl_khr_int64_base_atomics cl_khr_int64_extended_atomics");
 }
 
 

diff  --git a/clang/test/Parser/opencl-atomics-cl20.cl 
b/clang/test/Parser/opencl-atomics-cl20.cl
index 2f5f913d28738..c3f86b6a44c49 100644
--- a/clang/test/Parser/opencl-atomics-cl20.cl
+++ 

[clang] 58d18dd - [OpenCL] Remove pragma requirement from Arm dot extension.

2021-05-12 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-12T16:25:33+01:00
New Revision: 58d18dde5cca3417e3d52670775c95d2f6fe9d05

URL: 
https://github.com/llvm/llvm-project/commit/58d18dde5cca3417e3d52670775c95d2f6fe9d05
DIFF: 
https://github.com/llvm/llvm-project/commit/58d18dde5cca3417e3d52670775c95d2f6fe9d05.diff

LOG: [OpenCL] Remove pragma requirement from Arm dot extension.

This removed the pointless need for extension pragma since
it doesn't disable anything properly and it doesn't need to
enable anything that is not possible to disable.

The change doesn't break existing kernels since it allows to
compile more cases i.e. without pragma statements but the
pragma continues to be accepted.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c.h
clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
clang/test/SemaOpenCL/arm-integer-dot-product.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 62dbe459baa76..dcd325528f38b 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -16996,31 +16996,23 @@ uint16 __ovld amd_sadw(uint16 src0, uint16 src1, 
uint16 src2);
 #endif // cl_amd_media_ops2
 
 #if defined(cl_arm_integer_dot_product_int8)
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : begin
 uint __ovld arm_dot(uchar4 a, uchar4 b);
 int __ovld arm_dot(char4 a, char4 b);
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : end
 #endif // defined(cl_arm_integer_dot_product_int8)
 
 #if defined(cl_arm_integer_dot_product_accumulate_int8)
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : begin
 uint __ovld arm_dot_acc(uchar4 a, uchar4 b, uint c);
 int __ovld arm_dot_acc(char4 a, char4 b, int c);
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : end
 #endif // defined(cl_arm_integer_dot_product_accumulate_int8)
 
 #if defined(cl_arm_integer_dot_product_accumulate_int16)
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int16 : begin
 uint __ovld arm_dot_acc(ushort2 a, ushort2 b, uint c);
 int __ovld arm_dot_acc(short2 a, short2 b, int c);
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int16 : end
 #endif // defined(cl_arm_integer_dot_product_accumulate_int16)
 
 #if defined(cl_arm_integer_dot_product_accumulate_saturate_int8)
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_saturate_int8 : 
begin
 uint __ovld arm_dot_acc_sat(uchar4 a, uchar4 b, uint c);
 int __ovld arm_dot_acc_sat(char4 a, char4 b, int c);
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_saturate_int8 : 
end
 #endif // defined(cl_arm_integer_dot_product_accumulate_saturate_int8)
 
 // Disable any extensions we may have enabled previously.

diff  --git a/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl 
b/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
index a4d28c7e6cf8f..c98615c5dd988 100644
--- a/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
+++ b/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
@@ -1,38 +1,39 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -finclude-default-header 
-fdeclare-opencl-builtins -cl-std=CL1.2 -emit-llvm -o - -O0 | FileCheck %s
 
+// Pragmas are only accepted for backward compatibility.
+
 #pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : enable
+#pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : disable
 void test_int8(uchar4 ua, uchar4 ub, char4 sa, char4 sb) {
 uint ur = arm_dot(ua, ub);
 // CHECK: call spir_func i32 @_Z7arm_dotDv4_hS_
 int sr = arm_dot(sa, sb);
 // CHECK: call spir_func i32 @_Z7arm_dotDv4_cS_
 }
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : disable
 
 #pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : enable
+#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : disable
 void test_accumulate_int8(uchar4 ua, uchar4 ub, uint uc, char4 sa, char4 sb, 
int c) {
 uint ur = arm_dot_acc(ua, ub, uc);
 // CHECK: call spir_func i32 @_Z11arm_dot_accDv4_hS_j
 int sr = arm_dot_acc(sa, sb, c);
 // CHECK: call spir_func i32 @_Z11arm_dot_accDv4_cS_i
 }
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int8 : disable
 
 #pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int16 : enable
+#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int16 : disable
 void test_accumulate_int16(ushort2 ua, ushort2 ub, uint uc, short2 sa, short2 
sb, int c) {
 uint ur = arm_dot_acc(ua, ub, uc);
 // CHECK: call spir_func i32 @_Z11arm_dot_accDv2_tS_j
 int sr = arm_dot_acc(sa, sb, c);
 // CHECK: call spir_func i32 @_Z11arm_dot_accDv2_sS_i
 }
-#pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_int16 : disable
 
 #pragma OPENCL EXTENSION cl_arm_integer_dot_product_accumulate_saturate_int8 : 
enable
+#pragma OPENCL 

[clang] 13ea238 - [OpenCL] Allow use of double type without extension pragma.

2021-05-11 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-11T12:54:38+01:00
New Revision: 13ea238b1e1db96ef5fd409e869d9a8ebeef1332

URL: 
https://github.com/llvm/llvm-project/commit/13ea238b1e1db96ef5fd409e869d9a8ebeef1332
DIFF: 
https://github.com/llvm/llvm-project/commit/13ea238b1e1db96ef5fd409e869d9a8ebeef1332.diff

LOG: [OpenCL] Allow use of double type without extension pragma.

Simply use of extensions by allowing the use of supported
double types without the pragma. Since earlier standards
instructed that the pragma is used explicitly a new warning
is introduced in pedantic mode to indicate that use of
type without extension pragma enable can be non-portable.

This patch does not break backward compatibility since the
extension pragma is still supported and it makes the behavior
of the compiler less strict by accepting code without extra
pragma statements.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Misc/warning-flags.c
clang/test/SemaOpenCL/extensions.cl

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f78940a6e6fad..3d665cc76c539 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10023,6 +10023,9 @@ def err_opencl_variadic_function : Error<
   "invalid prototype, variadic arguments are not allowed in OpenCL">;
 def err_opencl_requires_extension : Error<
   "use of %select{type|declaration}0 %1 requires %2 support">;
+def ext_opencl_double_without_pragma : Extension<
+  "Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is"
+  " supported">;
 def warn_opencl_generic_address_space_arg : Warning<
   "passing non-generic address space pointer to %0"
   " may cause dynamic conversion affecting performance">,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 6c78d7325d681..b23140b4589c3 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -366,7 +366,6 @@ void Sema::Initialize() {
 "cl_khr_int64_base_atomics cl_khr_int64_extended_atomics");
 }
 
-setOpenCLExtensionForType(Context.DoubleTy, "cl_khr_fp64");
 
 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext)  
\
   if (getOpenCLOptions().isSupported(#Ext, getLangOpts())) {   
\

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index e3f8b747a783b..9801dd6ffb66e 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1524,6 +1524,13 @@ static QualType 
ConvertDeclSpecToType(TypeProcessingState ) {
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
   case DeclSpec::TST_double:
+if (S.getLangOpts().OpenCL) {
+  if (!S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts()))
+S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
+  << 0 << Context.DoubleTy << "cl_khr_fp64";
+  else if (!S.getOpenCLOptions().isAvailableOption("cl_khr_fp64", 
S.getLangOpts()))
+S.Diag(DS.getTypeSpecTypeLoc(), 
diag::ext_opencl_double_without_pragma);
+}
 if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long)
   Result = Context.LongDoubleTy;
 else

diff  --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c
index 54e36e1e08845..e4f9069b88c86 100644
--- a/clang/test/Misc/warning-flags.c
+++ b/clang/test/Misc/warning-flags.c
@@ -91,4 +91,4 @@ CHECK-NEXT:   warn_weak_import
 
 The list of warnings in -Wpedantic should NEVER grow.
 
-CHECK: Number in -Wpedantic (not covered by other -W flags): 26
+CHECK: Number in -Wpedantic (not covered by other -W flags): 27

diff  --git a/clang/test/SemaOpenCL/extensions.cl 
b/clang/test/SemaOpenCL/extensions.cl
index b0be017511a80..97380292dcae6 100644
--- a/clang/test/SemaOpenCL/extensions.cl
+++ b/clang/test/SemaOpenCL/extensions.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic 
-fsyntax-only
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic 
-fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -fsyntax-only 
-cl-std=CL1.1 -DNOPEDANTIC
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic 
-fsyntax-only -cl-std=CL1.2 -DFP64
 
 // Test with a target not supporting fp64.
@@ -43,8 +44,20 @@
 #endif
 
 #if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
-void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 
support}}
-  double d; // expected-error {{type 'double' requires cl_khr_fp64 support}}
+void f1(double da) {
+#ifdef NOFP64
+// expected-error@-2 {{type 'double' requires cl_khr_fp64 support}}
+#elif !defined(NOPEDANTIC)
+// 

Re: [clang] e994e74 - [OpenCL] Add clang extension for non-portable kernel parameters.

2021-05-11 Thread Anastasia Stulova via cfe-commits
Hi Tom,

Thanks for letting me know. It has been fixed by 
https://github.com/llvm/llvm-project/commit/7d20f709ea6da8442a153beda7ecdda07440f046.

And sorry for disruption.

Anastasia

From: Tom Stellard 
Sent: 11 May 2021 06:15
To: Anastasia Stulova ; Anastasia Stulova 
; cfe-commits@lists.llvm.org 
Subject: Re: [clang] e994e74 - [OpenCL] Add clang extension for non-portable 
kernel parameters.

On 5/5/21 6:58 AM, Anastasia Stulova via cfe-commits wrote:
>
> Author: Anastasia Stulova
> Date: 2021-05-05T14:58:23+01:00
> New Revision: e994e74bca49831eb649e7c67955e9de7a1784b6
>
> URL: 
> https://github.com/llvm/llvm-project/commit/e994e74bca49831eb649e7c67955e9de7a1784b6
> DIFF: 
> https://github.com/llvm/llvm-project/commit/e994e74bca49831eb649e7c67955e9de7a1784b6.diff
>
> LOG: [OpenCL] Add clang extension for non-portable kernel parameters.
>
> Added __cl_clang_non_portable_kernel_param_types extension that
> allows using non-portable types as kernel parameters. This allows
> bypassing the portability guarantees from the restrictions specified
> in C++ for OpenCL v1.0 s2.4.
>
> Currently this only disables the restrictions related to the data
> layout. The programmer should ensure the compiler generates the same
> layout for host and device or otherwise the argument should only be
> accessed on the device side. This extension could be extended to other
> case (e.g. permitting size_t) if desired in the future.
>
> Patch by olestrohm (Ole Strohm)!
>

Hi Anastasia,


This change broke the clang-sphinx-docs builder:

https://lab.llvm.org/buildbot/#/builders/92/builds/9110

-Tom

> https://reviews.llvm.org/D101168
>
> Added:
>
>
> Modified:
>  clang/docs/LanguageExtensions.rst
>  clang/include/clang/Basic/OpenCLExtensions.def
>  clang/lib/Basic/Targets/AMDGPU.h
>  clang/lib/Basic/Targets/NVPTX.h
>  clang/lib/Sema/SemaDecl.cpp
>  clang/test/Misc/amdgcn.languageOptsOpenCL.cl
>  clang/test/Misc/nvptx.languageOptsOpenCL.cl
>  clang/test/Misc/r600.languageOptsOpenCL.cl
>  clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/docs/LanguageExtensions.rst 
> b/clang/docs/LanguageExtensions.rst
> index 5e5382879e0c8..bdb5b3adf39fb 100644
> --- a/clang/docs/LanguageExtensions.rst
> +++ b/clang/docs/LanguageExtensions.rst
> @@ -1813,6 +1813,54 @@ supporting the variadic arguments e.g. majority of CPU 
> targets.
> #pragma OPENCL EXTENSION __cl_clang_variadic_functions : disable
> void bar(int a, ...); // error - variadic prototype is not allowed
>
> +``__cl_clang_non_portable_kernel_param_types``
> +-
> +
> +With this extension it is possible to enable the use of some restricted types
> +in kernel parameters specified in `C++ for OpenCL v1.0 s2.4
> +<https://www.khronos.org/opencl/assets/CXX_for_OpenCL.html#kernel_function>`_.
> +The restrictions can be relaxed using regular OpenCL extension pragma 
> mechanism
> +detailed in `the OpenCL Extension Specification, section 1.2
> +<https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#extensions-overview>`_.
> +
> +This is not a conformant behavior and it can only be used when the
> +kernel arguments are not accessed on the host side or the data layout/size
> +between the host and device is known to be compatible.
> +
> +**Example of Use**:
> +
> +.. code-block:: c++
> +
> +  // Plain Old Data type.
> +  struct Pod {
> +int a;
> +int b;
> +  };
> +
> +  // Not POD type because of the constructor.
> +  // Standard layout type because there is only one access control.
> +  struct OnlySL {
> +int a;
> +int b;
> +NotPod() : a(0), b(0) {}
> +  };
> +
> +  // Not standard layout type because of two
> diff erent access controls.
> +  struct NotSL {
> +int a;
> +  private:
> +int b;
> +  }
> +
> +  kernel void kernel_main(
> +Pod a,
> +  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : 
> enable
> +OnlySL b,
> +global NotSL *c,
> +  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : 
> disable
> +global OnlySL *d,
> +  );
> +
>   Legacy 1.x atomics with generic address space
>   -
>
>
> diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
> b/clang/include/clang/Basic/OpenCLExtensions.def
> index 5e2977f478f3a..a0f01a2af9c37 100644
> --- a/clang/include/clang/Basic/OpenCLExtensions.def
> +++ b/clang/include/clang/Basic/OpenCLExte

[clang] 76f1de1 - [OpenCL] Fix optional image types.

2021-05-07 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-07T13:29:28+01:00
New Revision: 76f1de10f43ec4d1eb6146c45ccd6f93df5aa3e1

URL: 
https://github.com/llvm/llvm-project/commit/76f1de10f43ec4d1eb6146c45ccd6f93df5aa3e1
DIFF: 
https://github.com/llvm/llvm-project/commit/76f1de10f43ec4d1eb6146c45ccd6f93df5aa3e1.diff

LOG: [OpenCL] Fix optional image types.

This change allows the use of identifiers for image types
from `cl_khr_gl_msaa_sharing` freely in the kernel code if
the extension is not supported since they are not in the
list of the reserved identifiers.

This change also removed the need for pragma for the types
in the extensions since the spec does not require the pragma
uses.

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

Added: 


Modified: 
clang/include/clang/Basic/OpenCLImageTypes.def
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaType.cpp
clang/test/SemaOpenCL/access-qualifier.cl
clang/test/SemaOpenCL/invalid-image.cl

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLImageTypes.def 
b/clang/include/clang/Basic/OpenCLImageTypes.def
index cfb018a661aef..ada5892c06b36 100644
--- a/clang/include/clang/Basic/OpenCLImageTypes.def
+++ b/clang/include/clang/Basic/OpenCLImageTypes.def
@@ -65,7 +65,7 @@ IMAGE_WRITE_TYPE(image2d_msaa, OCLImage2dMSAA, 
"cl_khr_gl_msaa_sharing")
 IMAGE_WRITE_TYPE(image2d_array_msaa, OCLImage2dArrayMSAA, 
"cl_khr_gl_msaa_sharing")
 IMAGE_WRITE_TYPE(image2d_msaa_depth, OCLImage2dMSAADepth, 
"cl_khr_gl_msaa_sharing")
 IMAGE_WRITE_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth, 
"cl_khr_gl_msaa_sharing")
-IMAGE_WRITE_TYPE(image3d, OCLImage3d, "cl_khr_3d_image_writes")
+IMAGE_WRITE_TYPE(image3d, OCLImage3d, "")
 
 IMAGE_READ_WRITE_TYPE(image1d, OCLImage1d, "")
 IMAGE_READ_WRITE_TYPE(image1d_array, OCLImage1dArray, "")

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index b56f3934fcedf..928ef33bc9f20 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3071,6 +3071,19 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec ,
 
 SourceLocation Loc = Tok.getLocation();
 
+// Helper for image types in OpenCL.
+auto handleOpenCLImageKW = [&] (StringRef Ext, TypeSpecifierType 
ImageTypeSpec) {
+  // Check if the image type is supported and otherwise turn the keyword 
into an identifier
+  // because image types from extensions are not reserved identifiers.
+  if (!StringRef(Ext).empty() && 
!getActions().getOpenCLOptions().isSupported(Ext, getLangOpts())) {
+Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
+Tok.setKind(tok::identifier);
+return false;
+  }
+  isInvalid = DS.SetTypeSpecType(ImageTypeSpec, Loc, PrevSpec, DiagID, 
Policy);
+  return true;
+};
+
 switch (Tok.getKind()) {
 default:
 DoneWithDeclSpec:
@@ -3935,11 +3948,14 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec ,
   }
   isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy);
   break;
-#define GENERIC_IMAGE_TYPE(ImgType, Id) \
-  case tok::kw_##ImgType##_t: \
-isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, 
\
-   DiagID, Policy); \
-break;
+// We only need to enumerate each image type once.
+#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
+#define IMAGE_WRITE_TYPE(Type, Id, Ext)
+#define IMAGE_READ_TYPE(ImgType, Id, Ext) \
+case tok::kw_##ImgType##_t: \
+  if (!handleOpenCLImageKW(Ext, DeclSpec::TST_##ImgType##_t)) \
+goto DoneWithDeclSpec; \
+  break;
 #include "clang/Basic/OpenCLImageTypes.def"
 case tok::kw___unknown_anytype:
   isInvalid = DS.SetTypeSpecType(TST_unknown_anytype, Loc,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 40f11e40882ce..6c78d7325d681 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -368,9 +368,6 @@ void Sema::Initialize() {
 
 setOpenCLExtensionForType(Context.DoubleTy, "cl_khr_fp64");
 
-#define GENERIC_IMAGE_TYPE_EXT(Type, Id, Ext) \
-setOpenCLExtensionForType(Context.Id, Ext);
-#include "clang/Basic/OpenCLImageTypes.def"
 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext)  
\
   if (getOpenCLOptions().isSupported(#Ext, getLangOpts())) {   
\
 addImplicitTypedef(#ExtType, Context.Id##Ty);  
\

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 9e826eb0d2476..e3f8b747a783b 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1713,6 +1713,13 @@ static QualType 
ConvertDeclSpecToType(TypeProcessingState ) {
   if (Result->containsErrors())
 declarator.setInvalidType();
 
+  if (S.getLangOpts().OpenCL && Result->isOCLImage3dWOType() &&
+  !S.getOpenCLOptions().isSupported("cl_khr_3d_image_writes", 

[clang] c28a602 - [OpenCL] Remove subgroups pragma in enqueue kernel and pipe builtins.

2021-05-06 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-06T13:59:38+01:00
New Revision: c28a602329a78db5c02cc85679b5035aaf6753b4

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

LOG: [OpenCL] Remove subgroups pragma in enqueue kernel and pipe builtins.

This patch simplifies the parser and makes the language semantics
consistent. There is no extension pragma requirement in the spec
for the subgroup functions in enqueue kernel or pipes and all other
builtin functions are available without the pragama.

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaOpenCL/cl20-device-side-enqueue.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 38cda657bac8b..415773e62ad52 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -838,8 +838,7 @@ static bool checkOpenCLBlockArgs(Sema , Expr *BlockArg) {
 }
 
 static bool checkOpenCLSubgroupExt(Sema , CallExpr *Call) {
-  if (!S.getOpenCLOptions().isAvailableOption("cl_khr_subgroups",
-  S.getLangOpts())) {
+  if (!S.getOpenCLOptions().isSupported("cl_khr_subgroups", S.getLangOpts())) {
 S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_extension)
 << 1 << Call->getDirectCallee() << "cl_khr_subgroups";
 return true;

diff  --git a/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl 
b/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
index d25a03504c03a..5cfdfb3cdc5ca 100644
--- a/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ b/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS=
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify 
-pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify 
-pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
@@ -212,8 +213,8 @@ kernel void work_group_size_tests() {
   size = get_kernel_preferred_work_group_size_multiple(block_A, 1); // 
expected-error{{too many arguments to function call, expected 1, have 2}}
 }
 
+#ifdef cl_khr_subgroups
 #pragma OPENCL EXTENSION cl_khr_subgroups : enable
-
 kernel void foo(global unsigned int *buf)
 {
   ndrange_t n;
@@ -231,7 +232,7 @@ kernel void bar(global unsigned int *buf)
 }
 
 #pragma OPENCL EXTENSION cl_khr_subgroups : disable
-
+#else
 kernel void foo1(global unsigned int *buf)
 {
   ndrange_t n;
@@ -243,3 +244,4 @@ kernel void bar1(global unsigned int *buf)
   ndrange_t n;
   buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error 
{{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires 
cl_khr_subgroups support}}
 }
+#endif // ifdef cl_khr_subgroups



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e994e74 - [OpenCL] Add clang extension for non-portable kernel parameters.

2021-05-05 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-05T14:58:23+01:00
New Revision: e994e74bca49831eb649e7c67955e9de7a1784b6

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

LOG: [OpenCL] Add clang extension for non-portable kernel parameters.

Added __cl_clang_non_portable_kernel_param_types extension that
allows using non-portable types as kernel parameters. This allows
bypassing the portability guarantees from the restrictions specified
in C++ for OpenCL v1.0 s2.4.

Currently this only disables the restrictions related to the data
layout. The programmer should ensure the compiler generates the same
layout for host and device or otherwise the argument should only be
accessed on the device side. This extension could be extended to other
case (e.g. permitting size_t) if desired in the future.

Patch by olestrohm (Ole Strohm)!

https://reviews.llvm.org/D101168

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/OpenCLExtensions.def
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Sema/SemaDecl.cpp
clang/test/Misc/amdgcn.languageOptsOpenCL.cl
clang/test/Misc/nvptx.languageOptsOpenCL.cl
clang/test/Misc/r600.languageOptsOpenCL.cl
clang/test/SemaOpenCLCXX/invalid-kernel.clcpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 5e5382879e0c8..bdb5b3adf39fb 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1813,6 +1813,54 @@ supporting the variadic arguments e.g. majority of CPU 
targets.
   #pragma OPENCL EXTENSION __cl_clang_variadic_functions : disable
   void bar(int a, ...); // error - variadic prototype is not allowed
 
+``__cl_clang_non_portable_kernel_param_types``
+-
+
+With this extension it is possible to enable the use of some restricted types
+in kernel parameters specified in `C++ for OpenCL v1.0 s2.4
+`_.
+The restrictions can be relaxed using regular OpenCL extension pragma mechanism
+detailed in `the OpenCL Extension Specification, section 1.2
+`_.
+
+This is not a conformant behavior and it can only be used when the
+kernel arguments are not accessed on the host side or the data layout/size
+between the host and device is known to be compatible.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  // Plain Old Data type.
+  struct Pod {
+int a;
+int b;
+  };
+
+  // Not POD type because of the constructor.
+  // Standard layout type because there is only one access control.
+  struct OnlySL {
+int a;
+int b;
+NotPod() : a(0), b(0) {}
+  };
+
+  // Not standard layout type because of two 
diff erent access controls.
+  struct NotSL {
+int a;
+  private:
+int b;
+  }
+
+  kernel void kernel_main(
+Pod a,
+  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable
+OnlySL b,
+global NotSL *c,
+  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : disable
+global OnlySL *d,
+  );
+
 Legacy 1.x atomics with generic address space
 -
 

diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index 5e2977f478f3a..a0f01a2af9c37 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -87,6 +87,7 @@ OPENCL_EXTENSION(cl_khr_subgroups, true, 200)
 OPENCL_EXTENSION(cl_clang_storage_class_specifiers, true, 100)
 OPENCL_EXTENSION(__cl_clang_function_pointers, true, 100)
 OPENCL_EXTENSION(__cl_clang_variadic_functions, true, 100)
+OPENCL_EXTENSION(__cl_clang_non_portable_kernel_param_types, true, 100)
 
 // AMD OpenCL extensions
 OPENCL_EXTENSION(cl_amd_media_ops, true, 100)

diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 8ee0ca30d305d..b2d422ce0bbe9 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -287,6 +287,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
 Opts["cl_clang_storage_class_specifiers"] = true;
 Opts["__cl_clang_variadic_functions"] = true;
 Opts["__cl_clang_function_pointers"] = true;
+Opts["__cl_clang_non_portable_kernel_param_types"] = true;
 
 bool IsAMDGCN = isAMDGCN(getTriple());
 

diff  --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h
index 9e80473df9e00..b7b0aae65819d 100644
--- a/clang/lib/Basic/Targets/NVPTX.h
+++ b/clang/lib/Basic/Targets/NVPTX.h
@@ -133,6 +133,7 @@ class 

[clang] 64911ee - [OpenCL] Allow pipe as a valid identifier prior to OpenCL 2.0.

2021-05-04 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-05-04T14:30:42+01:00
New Revision: 64911eec75bb0c54e40665a2c3f744f046c66a59

URL: 
https://github.com/llvm/llvm-project/commit/64911eec75bb0c54e40665a2c3f744f046c66a59
DIFF: 
https://github.com/llvm/llvm-project/commit/64911eec75bb0c54e40665a2c3f744f046c66a59.diff

LOG: [OpenCL] Allow pipe as a valid identifier prior to OpenCL 2.0.

Pipe has not been a reserved keyword in the earlier OpenCL
standards. However we failed to allow its use as an identifier
in the original commit. This issues is fixed now and testing
is improved accordingly.

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

Added: 


Modified: 
clang/lib/Parse/ParseDecl.cpp
clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl

Removed: 




diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index eb567f528a1cd..b56f3934fcedf 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3930,6 +3930,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec ,
 // OpenCL 2.0 and later define this keyword. OpenCL 1.2 and earlier
 // should support the "pipe" word as identifier.
 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
+Tok.setKind(tok::identifier);
 goto DoneWithDeclSpec;
   }
   isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy);

diff  --git a/clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl 
b/clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
index 441a24cf85227..557c191f64076 100644
--- a/clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
+++ b/clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
@@ -1,3 +1,9 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
 
-void foo(read_only pipe int p); // expected-error {{expected parameter 
declarator}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+void foo(read_only pipe int p);
+// expected-warning@-1 {{type specifier missing, defaults to 'int'}}
+// expected-error@-2 {{access qualifier can only be used for pipe and image 
type}}
+// expected-error@-3 {{expected ')'}} expected-note@-3 {{to match this '('}}
+
+// 'pipe' should be accepted as an identifier.
+typedef int pipe;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3ec82e5 - [OpenCL] Prevent adding vendor extensions for all targets

2021-04-30 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-04-30T14:42:51+01:00
New Revision: 3ec82e519513b231bb0e8dd5e098c4c5a51501a2

URL: 
https://github.com/llvm/llvm-project/commit/3ec82e519513b231bb0e8dd5e098c4c5a51501a2
DIFF: 
https://github.com/llvm/llvm-project/commit/3ec82e519513b231bb0e8dd5e098c4c5a51501a2.diff

LOG: [OpenCL] Prevent adding vendor extensions for all targets

Removed extension begin/end pragma as it has no effect and
it is added unconditionally for all targets.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index dd038a23ee0f9..72f8c2576ebd3 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -567,7 +567,6 @@ int printf(__constant const char* st, ...) 
__attribute__((format(printf, 1, 2)))
 #endif
 
 #ifdef cl_intel_device_side_avc_motion_estimation
-#pragma OPENCL EXTENSION cl_intel_device_side_avc_motion_estimation : begin
 
 #define CLK_AVC_ME_MAJOR_16x16_INTEL 0x0
 #define CLK_AVC_ME_MAJOR_16x8_INTEL 0x1
@@ -701,7 +700,6 @@ int printf(__constant const char* st, ...) 
__attribute__((format(printf, 1, 2)))
 #define CLK_AVC_IME_RESULT_DUAL_REFERENCE_STREAMOUT_INITIALIZE_INTEL 0x0
 #define CLK_AVC_IME_RESULT_DUAL_REFERENCE_STREAMIN_INITIALIZE_INTEL 0x0
 
-#pragma OPENCL EXTENSION cl_intel_device_side_avc_motion_estimation : end
 #endif // cl_intel_device_side_avc_motion_estimation
 
 // Disable any extensions we may have enabled previously.

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 6a532db4b1cb2..62dbe459baa76 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -23,10 +23,11 @@
 #endif //cl_khr_3d_image_writes
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
+
+#if (defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_1_2)) && defined(__SPIR__)
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : end
-#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_1_2)
+#endif // (defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_1_2)) && defined(__SPIR__)
 
 #define __ovld __attribute__((overloadable))
 #define __conv __attribute__((convergent))

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index f72cea61fcd91..f97a089e744a4 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -89,9 +89,10 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 
 // Check that extension macros are defined correctly.
 
-// FIXME: this should not be defined for all targets
-// Verify that non-builtin cl_intel_planar_yuv extension is defined from
-// OpenCL 1.2 onwards.
+// For SPIR all extensions are supported.
+#if defined(__SPIR__)
+
+// Verify that cl_intel_planar_yuv extension is defined from OpenCL 1.2 
onwards.
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // expected-no-diagnostics
 #else //__OPENCL_C_VERSION__
@@ -99,9 +100,6 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #endif //__OPENCL_C_VERSION__
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
 
-// For SPIR all extensions are supported.
-#if defined(__SPIR__)
-
 #if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 
 #if cl_khr_subgroup_extended_types != 1



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1ed6e87 - [OpenCL][Docs] Misc updates to C++ for OpenCL and offline compilation

2021-04-29 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-04-29T14:15:07+01:00
New Revision: 1ed6e87ab02db4fb9379b80c820bebad9869aa4d

URL: 
https://github.com/llvm/llvm-project/commit/1ed6e87ab02db4fb9379b80c820bebad9869aa4d
DIFF: 
https://github.com/llvm/llvm-project/commit/1ed6e87ab02db4fb9379b80c820bebad9869aa4d.diff

LOG: [OpenCL][Docs] Misc updates to C++ for OpenCL and offline compilation

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 0d5774091fb6..5bde2c332022 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -334,17 +334,9 @@ to view the full bug list.
 Missing features or with limited support
 
 
-- Use of ObjC blocks is disabled and therefore the ``enqueue_kernel`` builtin
-  function is not supported currently. It is expected that if support for this
-  feature is added in the future, it will utilize C++ lambdas instead of ObjC
-  blocks.
-
 - IR generation for global destructors is incomplete (See:
   `PR48047 `_).
 
-- There is no distinct file extension for sources that are to be compiled
-  in C++ for OpenCL mode (See: `PR48097 `_)
-
 .. _opencl_300:
 
 OpenCL 3.0 Implementation Status

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index ec521155a7f7..f84c4eceebb9 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2927,7 +2927,7 @@ tools as well as open source tools such as `SPIRV-LLVM 
Translator
 to produce SPIR-V binary. More details are provided in `the offline
 compilation from OpenCL kernel sources into SPIR-V using open source
 tools
-`_.
+`_.
 
 Clang currently supports OpenCL C language standards up to v2.0. Clang mainly
 supports full profile. There is only very limited support of the embedded



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8fb0d6d - [OpenCL][Docs] Describe extension for legacy atomics with generic addr space.

2021-04-29 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-04-29T14:02:34+01:00
New Revision: 8fb0d6df11e4d2b4a534c96fcc1b55459940151e

URL: 
https://github.com/llvm/llvm-project/commit/8fb0d6df11e4d2b4a534c96fcc1b55459940151e
DIFF: 
https://github.com/llvm/llvm-project/commit/8fb0d6df11e4d2b4a534c96fcc1b55459940151e.diff

LOG: [OpenCL][Docs] Describe extension for legacy atomics with generic addr 
space.

This extension is primarily targeting SPIR-V compilations flow
as the IR translation is the same between 1.x and 2.x atomics.

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 00759113775d4..5e5382879e0c8 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1813,6 +1813,23 @@ supporting the variadic arguments e.g. majority of CPU 
targets.
   #pragma OPENCL EXTENSION __cl_clang_variadic_functions : disable
   void bar(int a, ...); // error - variadic prototype is not allowed
 
+Legacy 1.x atomics with generic address space
+-
+
+Clang allows use of atomic functions from the OpenCL 1.x standards
+with the generic address space pointer in C++ for OpenCL mode.
+
+This is a non-portable feature and might not be supported by all
+targets.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  void foo(__generic volatile unsigned int* a) {
+atomic_add(a, 1);
+  }
+
 Builtin Functions
 =
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6a92c19 - [C++4OpenCL] Add diagnostics for OpenCL types in templates.

2021-04-27 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-04-27T13:04:25+01:00
New Revision: 6a92c19f3bbc47827b8844a2b527f6c6fba63afd

URL: 
https://github.com/llvm/llvm-project/commit/6a92c19f3bbc47827b8844a2b527f6c6fba63afd
DIFF: 
https://github.com/llvm/llvm-project/commit/6a92c19f3bbc47827b8844a2b527f6c6fba63afd.diff

LOG: [C++4OpenCL] Add diagnostics for OpenCL types in templates.

Refactored diagnostics for OpenCL types to allow their
reuse for templates.

Patch by olestrohm (Ole Strohm)!

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

Added: 
clang/test/SemaOpenCLCXX/template-opencl-types.clcpp

Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaOpenCL/clk_event_t.cl
clang/test/SemaOpenCL/event_t.cl
clang/test/SemaOpenCL/sampler_t.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f57e705604c8..9c5bc19f2215 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6726,17 +6726,20 @@ static bool isDeclExternC(const Decl *D) {
 
   llvm_unreachable("Unknown type of decl!");
 }
+
 /// Returns true if there hasn't been any invalid type diagnosed.
-static bool diagnoseOpenCLTypes(Scope *S, Sema , Declarator ,
-DeclContext *DC, QualType R) {
+static bool diagnoseOpenCLTypes(Sema , VarDecl *NewVD) {
+  DeclContext *DC = NewVD->getDeclContext();
+  QualType R = NewVD->getType();
+
   // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
   // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
   // argument.
   if (R->isImageType() || R->isPipeType()) {
-Se.Diag(D.getIdentifierLoc(),
+Se.Diag(NewVD->getLocation(),
 diag::err_opencl_type_can_only_be_used_as_function_parameter)
 << R;
-D.setInvalidType();
+NewVD->setInvalidDecl();
 return false;
   }
 
@@ -6745,12 +6748,12 @@ static bool diagnoseOpenCLTypes(Scope *S, Sema , 
Declarator ,
   // OpenCL v2.0 s6.9.q:
   // The clk_event_t and reserve_id_t types cannot be declared in program
   // scope.
-  if (NULL == S->getParent()) {
+  if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) {
 if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {
-  Se.Diag(D.getIdentifierLoc(),
+  Se.Diag(NewVD->getLocation(),
   diag::err_invalid_type_for_program_scope_var)
   << R;
-  D.setInvalidType();
+  NewVD->setInvalidDecl();
   return false;
 }
   }
@@ -6763,9 +6766,9 @@ static bool diagnoseOpenCLTypes(Scope *S, Sema , 
Declarator ,
NR->isReferenceType()) {
   if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType() ||
   NR->isFunctionReferenceType()) {
-Se.Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer)
+Se.Diag(NewVD->getLocation(), diag::err_opencl_function_pointer)
 << NR->isReferenceType();
-D.setInvalidType();
+NewVD->setInvalidDecl();
 return false;
   }
   NR = NR->getPointeeType();
@@ -6777,8 +6780,8 @@ static bool diagnoseOpenCLTypes(Scope *S, Sema , 
Declarator ,
 // OpenCL v1.2 s6.1.1.1: reject declaring variables of the half and
 // half array type (unless the cl_khr_fp16 extension is enabled).
 if (Se.Context.getBaseElementType(R)->isHalfType()) {
-  Se.Diag(D.getIdentifierLoc(), diag::err_opencl_half_declaration) << R;
-  D.setInvalidType();
+  Se.Diag(NewVD->getLocation(), diag::err_opencl_half_declaration) << R;
+  NewVD->setInvalidDecl();
   return false;
 }
   }
@@ -6788,34 +6791,20 @@ static bool diagnoseOpenCLTypes(Scope *S, Sema , 
Declarator ,
   // address space qualifiers.
   if (R->isEventT()) {
 if (R.getAddressSpace() != LangAS::opencl_private) {
-  Se.Diag(D.getBeginLoc(), diag::err_event_t_addr_space_qual);
-  D.setInvalidType();
+  Se.Diag(NewVD->getBeginLoc(), diag::err_event_t_addr_space_qual);
+  NewVD->setInvalidDecl();
   return false;
 }
   }
 
-  // C++ for OpenCL does not allow the thread_local storage qualifier.
-  // OpenCL C does not support thread_local either, and
-  // also reject all other thread storage class specifiers.
-  DeclSpec::TSCS TSC = D.getDeclSpec().getThreadStorageClassSpec();
-  if (TSC != TSCS_unspecified) {
-bool IsCXX = Se.getLangOpts().OpenCLCPlusPlus;
-Se.Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
-diag::err_opencl_unknown_type_specifier)
-<< IsCXX << Se.getLangOpts().getOpenCLVersionTuple().getAsString()
-<< DeclSpec::getSpecifierName(TSC) << 1;
-D.setInvalidType();
-return false;
-  }
-
   if (R->isSamplerT()) {
 // OpenCL v1.2 s6.9.b p4:
 // The sampler type cannot be used with the __local and __global address
 // space qualifiers.
 if (R.getAddressSpace() == LangAS::opencl_local ||
 R.getAddressSpace() == 

[clang] fcb45b5 - [OpenCL] Fix typo in the test.

2021-04-23 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-04-23T14:36:36+01:00
New Revision: fcb45b544d3da87e0aab895eaac7903197a6c58c

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

LOG: [OpenCL] Fix typo in the test.

Added: 


Modified: 
clang/test/SemaOpenCL/func.cl

Removed: 




diff  --git a/clang/test/SemaOpenCL/func.cl b/clang/test/SemaOpenCL/func.cl
index bcac30b67e372..d4a6ec6170616 100644
--- a/clang/test/SemaOpenCL/func.cl
+++ b/clang/test/SemaOpenCL/func.cl
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -triple 
spir-unknown-unknown
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -triple 
spir-unknown-unknown -DFUNCPTREXT
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -triple 
spir-unknown-unknown -DVARARG
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -triple 
spir-unknown-unknown -DVARARGEXT
 
 #ifdef FUNCPTREXT
 #pragma OPENCL EXTENSION __cl_clang_function_pointers : enable



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 362958a - [C++4OpenCL] Add extra diagnostics for kernel argument types

2021-04-22 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-04-22T15:28:04+01:00
New Revision: 362958ac7346ba3539f819e9fe93d2529caad1e8

URL: 
https://github.com/llvm/llvm-project/commit/362958ac7346ba3539f819e9fe93d2529caad1e8
DIFF: 
https://github.com/llvm/llvm-project/commit/362958ac7346ba3539f819e9fe93d2529caad1e8.diff

LOG: [C++4OpenCL] Add extra diagnostics for kernel argument types

Add restrictions on type layout (PR48099):
- Types passed by pointer or reference must be standard layout types.
- Types passed by value must be POD types.

Patch by olestrohm (Ole Strohm)!

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaOpenCLCXX/invalid-kernel.clcpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d1dc9db5abd7f..8a718249d8549 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8648,7 +8648,7 @@ static bool isOpenCLSizeDependentType(ASTContext , 
QualType Ty) {
 }
 
 static OpenCLParamType getOpenCLKernelParameterType(Sema , QualType PT) {
-  if (PT->isPointerType()) {
+  if (PT->isPointerType() || PT->isReferenceType()) {
 QualType PointeeType = PT->getPointeeType();
 if (PointeeType.getAddressSpace() == LangAS::opencl_generic ||
 PointeeType.getAddressSpace() == LangAS::opencl_private ||
@@ -8665,6 +8665,15 @@ static OpenCLParamType getOpenCLKernelParameterType(Sema 
, QualType PT) {
 
   return PtrPtrKernelParam;
 }
+
+// C++ for OpenCL v1.0 s2.4:
+// Moreover the types used in parameters of the kernel functions must be:
+// Standard layout types for pointer parameters. The same applies to
+// reference if an implementation supports them in kernel parameters.
+if (S.getLangOpts().OpenCLCPlusPlus && !PointeeType->isAtomicType() &&
+!PointeeType->isVoidType() && !PointeeType->isStandardLayoutType())
+  return InvalidKernelParam;
+
 return PtrKernelParam;
   }
 
@@ -8689,9 +8698,6 @@ static OpenCLParamType getOpenCLKernelParameterType(Sema 
, QualType PT) {
   PT->isHalfType())
 return InvalidKernelParam;
 
-  if (PT->isRecordType())
-return RecordKernelParam;
-
   // Look into an array argument to check if it has a forbidden type.
   if (PT->isArrayType()) {
 const Type *UnderlyingTy = PT->getPointeeOrArrayElementType();
@@ -8701,6 +8707,17 @@ static OpenCLParamType getOpenCLKernelParameterType(Sema 
, QualType PT) {
 return getOpenCLKernelParameterType(S, QualType(UnderlyingTy, 0));
   }
 
+  // C++ for OpenCL v1.0 s2.4:
+  // Moreover the types used in parameters of the kernel functions must be:
+  // Trivial and standard-layout types C++17 [basic.types] (plain old data
+  // types) for parameters passed by value;
+  if (S.getLangOpts().OpenCLCPlusPlus && !PT->isOpenCLSpecificType() &&
+  !PT.isPODType(S.Context))
+return InvalidKernelParam;
+
+  if (PT->isRecordType())
+return RecordKernelParam;
+
   return ValidKernelParam;
 }
 

diff  --git a/clang/test/SemaOpenCLCXX/invalid-kernel.clcpp 
b/clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
index 2cbfffd5a00e9..977d487928b65 100644
--- a/clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
+++ b/clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
@@ -5,6 +5,7 @@ struct C {
 };
 
 template 
+//expected-error@+1{{'T' cannot be used as the type of a kernel parameter}}
 kernel void templ(T par) { //expected-error{{kernel functions cannot be used 
in a template declaration, instantiation or specialization}}
 }
 
@@ -15,3 +16,58 @@ kernel void bar(int par) { //expected-error{{kernel 
functions cannot be used in
 kernel void foo(int); //expected-note{{previous declaration is here}}
 
 kernel void foo(float); //expected-error{{conflicting types for 'foo'}}
+
+kernel void int_v(int in);
+kernel void int_p(__global int *in);
+kernel void int_r(__global int );
+kernel void int_p_p(__global int *__global *in);
+kernel void int_p_r(__global int *__global );
+kernel void int_p_p_r(__global int *__global *__global );
+
+// expected-error@+1{{'__private atomic_int' (aka '__private _Atomic(int)') 
cannot be used as the type of a kernel parameter}}
+kernel void k_atomic_v(atomic_int in);
+kernel void k_atomic_p(__global atomic_int *in);
+kernel void k_atomic_r(__global atomic_int );
+
+kernel void k_pipe(read_only pipe int in, write_only pipe int out);
+kernel void k_sampler(sampler_t in);
+kernel void k_void(__global void *in);
+
+typedef int int4 __attribute__((ext_vector_type(4)));
+
+kernel void int4_v(int4 in);
+kernel void int4_p(__global int4 *in);
+kernel void int4_p_p(__global int4 *__global *in);
+kernel void int4_r(__global int4 );
+
+struct POD {
+  int a;
+  int b;
+};
+
+kernel void pod_v(POD in) {}
+kernel void pod_p(__global POD *in) {}
+kernel void pod_p_p(__global POD *__global *in) {}
+kernel void pod_r(__global POD ) {}
+
+struct StandardLayout {
+  int a;

[clang] 6e8601f - [OpenCL][Docs] Fix typo in section label

2021-04-08 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-04-08T10:59:44+01:00
New Revision: 6e8601ff4ae1154e6f7963c70453b4818d7453e0

URL: 
https://github.com/llvm/llvm-project/commit/6e8601ff4ae1154e6f7963c70453b4818d7453e0
DIFF: 
https://github.com/llvm/llvm-project/commit/6e8601ff4ae1154e6f7963c70453b4818d7453e0.diff

LOG: [OpenCL][Docs] Fix typo in section label

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 71200364c7466..5b5ab2b1bec04 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -398,7 +398,7 @@ Feel free to contact us on `cfe-dev
 `_ or via `Bugzilla
 `__.
 
-.. _opencl_experimenal_cxxlibs:
+.. _opencl_experimental_cxxlibs:
 
 C++ libraries for OpenCL
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d4e9fe8 - [OpenCL][Docs] Update links to the C++ for OpenCL documentation

2021-04-01 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-04-01T20:38:24+01:00
New Revision: d4e9fe813f4fabc260f8e859cf2846cb34e0ad3b

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

LOG: [OpenCL][Docs] Update links to the C++ for OpenCL documentation

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 7ecc4f2bed0a..71200364c746 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -321,7 +321,7 @@ C++ for OpenCL Implementation Status
 
 Clang implements language version 1.0 published in `the official
 release of C++ for OpenCL Documentation
-`_.
+`_.
 
 Limited support of experimental C++ libraries is described in the 
:ref:`experimental features `.
 

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index c7b7f580ad93..9053398c937a 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3210,9 +3210,9 @@ Clang currently supports C++ for OpenCL v1.0.
 For detailed information about this language refer to the C++ for OpenCL
 Programming Language Documentation available
 in `the latest build
-`_
+`_
 or in `the official release
-`_.
+`_.
 
 To enable the C++ for OpenCL mode, pass one of following command line options 
when
 compiling ``.cl`` file ``-cl-std=clc++``, ``-cl-std=CLC++``, ``-std=clc++`` or



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7c541a1 - [OpenCL][Docs] Added a label for C++ libs section and example link

2021-04-01 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-04-01T13:55:23+01:00
New Revision: 7c541a195f651aa8d6aa270db83932a6ac7fac78

URL: 
https://github.com/llvm/llvm-project/commit/7c541a195f651aa8d6aa270db83932a6ac7fac78
DIFF: 
https://github.com/llvm/llvm-project/commit/7c541a195f651aa8d6aa270db83932a6ac7fac78.diff

LOG: [OpenCL][Docs] Added a label for C++ libs section and example link

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 8af579a082a9..7ecc4f2bed0a 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -398,6 +398,8 @@ Feel free to contact us on `cfe-dev
 `_ or via `Bugzilla
 `__.
 
+.. _opencl_experimenal_cxxlibs:
+
 C++ libraries for OpenCL
 
 
@@ -441,4 +443,5 @@ The possible clang invocation to compile the example is as 
follows:
  $ clang -cl-std=clc++  -I/include test.cl
 
 Note that `type_traits` is a header only library and therefore no extra
-linking step against the standard libraries is required.
+linking step against the standard libraries is required. See full example
+in `Compiler Explorer `_.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 706c1dc - [OpenCL][Docs] Minor update about C++ for OpenCL in UsersManual.

2021-03-26 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-03-26T19:24:07Z
New Revision: 706c1dc266d247232243b83a06a4904f527dc245

URL: 
https://github.com/llvm/llvm-project/commit/706c1dc266d247232243b83a06a4904f527dc245
DIFF: 
https://github.com/llvm/llvm-project/commit/706c1dc266d247232243b83a06a4904f527dc245.diff

LOG: [OpenCL][Docs] Minor update about C++ for OpenCL in UsersManual.

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 7709556fbace..6c8d297e618f 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3237,6 +3237,18 @@ compiling ``.cl`` file ``-cl-std=clc++``, 
``-cl-std=CLC++``, ``-std=clc++`` or
 
  clang -cl-std=clc++ test.cl
 
+Alternatively, files with ``.clcpp`` extension are compiled with the C++ for 
OpenCL
+mode.
+
+   .. code-block:: console
+
+ clang test.clcpp
+
+C++ for OpenCL kernel sources can also be compiled online in drivers 
supporting 
+`cl_ext_cxx_for_opencl
+`_
+extension.
+
 Constructing and destroying global objects
 ^^
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6e46f0b - [OpenCL] Fix AST check in address-space-templates test

2021-03-26 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-03-26T14:24:30Z
New Revision: 6e46f0b628308ba39feb13872cb21166b857dfdb

URL: 
https://github.com/llvm/llvm-project/commit/6e46f0b628308ba39feb13872cb21166b857dfdb
DIFF: 
https://github.com/llvm/llvm-project/commit/6e46f0b628308ba39feb13872cb21166b857dfdb.diff

LOG: [OpenCL] Fix AST check in address-space-templates test

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

Added: 


Modified: 
clang/test/SemaOpenCLCXX/address-space-templates.clcpp

Removed: 




diff  --git a/clang/test/SemaOpenCLCXX/address-space-templates.clcpp 
b/clang/test/SemaOpenCLCXX/address-space-templates.clcpp
index 105a0ddeb35f..0ea1a2a1e4df 100644
--- a/clang/test/SemaOpenCLCXX/address-space-templates.clcpp
+++ b/clang/test/SemaOpenCLCXX/address-space-templates.clcpp
@@ -31,7 +31,7 @@ template  struct as_pointer {
 // Check address space deduction in template parameter deduction.
 struct rep {
   // When there is no address space on a reference use __generic.
-  // CHECK: |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep 
&__private) __generic'
+  // CHECK: |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep 
&__private){{.*}} __generic'
   template::type>
   rep(U&& v) {}
 };
@@ -57,6 +57,6 @@ void bar() {
   rep_outer r;
   int i;
   // Preserve the address space of the type in forwarding reference.
-  // CHECK: CXXMethodDecl {{.*}} operator() 'void (__private int &__private) 
const __generic'
+  // CHECK: CXXMethodDecl {{.*}} operator() 'void (__private int 
&__private){{.*}} const __generic'
   foo4(i, [](auto&& x){;});
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a819256 - [OpenCL][Docs] Update status of OpenCL 3.0 development

2021-03-26 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-03-26T13:07:06Z
New Revision: a81925664bbbc62dc854df919e1b5180f0abfa56

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

LOG: [OpenCL][Docs] Update status of OpenCL 3.0 development

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index f7d6b1f7f2c9..8af579a082a9 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -360,7 +360,7 @@ implementation status.
 
+--+--+--+---+
 | Predefined macros| New version macro 
   | :good:`done` | https://reviews.llvm.org/D88300 
  |
 
+--+--+--+---+
-| Predefined macros| Feature macros
   | :part:`worked on`| https://reviews.llvm.org/D89869 
  |
+| Predefined macros| Feature macros
   | :good:`done` | https://reviews.llvm.org/D95776 
  |
 
+--+--+--+---+
 | Feature optionality  | Generic address space 
   | :none:`unclaimed`| 
  |
 
+--+--+--+---+



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d1c8a15 - [OpenCL] Added distinct file extension for C++ for OpenCL.

2021-03-24 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-03-24T13:07:04Z
New Revision: d1c8a151df830c6c727f0bb7d33774bd3eb96824

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

LOG: [OpenCL] Added distinct file extension for C++ for OpenCL.

Files compiled with C++ for OpenCL mode can now have a distinct
file extension - clcpp, then clang driver picks the compilation
mode automatically (-x clcpp) without the use of -cl-std=clc++.

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

Added: 
clang/test/CodeGenOpenCLCXX/address-space-deduction.clcpp
clang/test/CodeGenOpenCLCXX/address-space-deduction2.clcpp
clang/test/CodeGenOpenCLCXX/addrspace-conversion.clcpp
clang/test/CodeGenOpenCLCXX/addrspace-derived-base.clcpp
clang/test/CodeGenOpenCLCXX/addrspace-new-delete.clcpp
clang/test/CodeGenOpenCLCXX/addrspace-of-this.clcpp
clang/test/CodeGenOpenCLCXX/addrspace-operators.clcpp
clang/test/CodeGenOpenCLCXX/addrspace-references.clcpp
clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
clang/test/CodeGenOpenCLCXX/addrspace_cast.clcpp
clang/test/CodeGenOpenCLCXX/atexit.clcpp
clang/test/CodeGenOpenCLCXX/constexpr.clcpp
clang/test/CodeGenOpenCLCXX/global_init.clcpp
clang/test/CodeGenOpenCLCXX/local_addrspace_init.clcpp
clang/test/CodeGenOpenCLCXX/method-overload-address-space.clcpp
clang/test/CodeGenOpenCLCXX/template-address-spaces.clcpp
clang/test/Driver/cxx_for_opencl.clcpp
clang/test/SemaOpenCLCXX/address-space-castoperators.clcpp
clang/test/SemaOpenCLCXX/address-space-cond.clcpp
clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
clang/test/SemaOpenCLCXX/address-space-lambda.clcpp
clang/test/SemaOpenCLCXX/address-space-of-this-class-scope.clcpp
clang/test/SemaOpenCLCXX/address-space-of-this.clcpp
clang/test/SemaOpenCLCXX/address-space-references.clcpp
clang/test/SemaOpenCLCXX/address-space-templates.clcpp
clang/test/SemaOpenCLCXX/address_space_overloading.clcpp
clang/test/SemaOpenCLCXX/addrspace-auto.clcpp
clang/test/SemaOpenCLCXX/addrspace_cast.clcpp
clang/test/SemaOpenCLCXX/addrspace_cast_ast_dump.clcpp
clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
clang/test/SemaOpenCLCXX/members.clcpp
clang/test/SemaOpenCLCXX/method-overload-address-space.clcpp
clang/test/SemaOpenCLCXX/newdelete.clcpp
clang/test/SemaOpenCLCXX/references.clcpp
clang/test/SemaOpenCLCXX/restricted.clcpp

Modified: 
clang/include/clang/Basic/LangStandard.h
clang/include/clang/Driver/Types.def
clang/lib/Driver/Types.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Frontend/FrontendOptions.cpp
clang/test/Driver/lit.local.cfg
clang/test/lit.cfg.py

Removed: 
clang/test/CodeGenOpenCLCXX/address-space-deduction.cl
clang/test/CodeGenOpenCLCXX/address-space-deduction2.cl
clang/test/CodeGenOpenCLCXX/addrspace-conversion.cl
clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
clang/test/CodeGenOpenCLCXX/addrspace-new-delete.cl
clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
clang/test/CodeGenOpenCLCXX/addrspace-operators.cl
clang/test/CodeGenOpenCLCXX/addrspace-references.cl
clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl
clang/test/CodeGenOpenCLCXX/addrspace_cast.cl
clang/test/CodeGenOpenCLCXX/atexit.cl
clang/test/CodeGenOpenCLCXX/constexpr.cl
clang/test/CodeGenOpenCLCXX/global_init.cl
clang/test/CodeGenOpenCLCXX/local_addrspace_init.cl
clang/test/CodeGenOpenCLCXX/method-overload-address-space.cl
clang/test/CodeGenOpenCLCXX/template-address-spaces.cl
clang/test/SemaOpenCLCXX/address-space-castoperators.cl
clang/test/SemaOpenCLCXX/address-space-cond.cl
clang/test/SemaOpenCLCXX/address-space-deduction.cl
clang/test/SemaOpenCLCXX/address-space-lambda.cl
clang/test/SemaOpenCLCXX/address-space-of-this-class-scope.cl
clang/test/SemaOpenCLCXX/address-space-of-this.cl
clang/test/SemaOpenCLCXX/address-space-references.cl
clang/test/SemaOpenCLCXX/address-space-templates.cl
clang/test/SemaOpenCLCXX/address_space_overloading.cl
clang/test/SemaOpenCLCXX/addrspace-auto.cl
clang/test/SemaOpenCLCXX/addrspace_cast.cl
clang/test/SemaOpenCLCXX/addrspace_cast_ast_dump.cl
clang/test/SemaOpenCLCXX/invalid-kernel.cl
clang/test/SemaOpenCLCXX/members.cl
clang/test/SemaOpenCLCXX/method-overload-address-space.cl
clang/test/SemaOpenCLCXX/newdelete.cl
clang/test/SemaOpenCLCXX/references.cl
clang/test/SemaOpenCLCXX/restricted.cl



diff  --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index f82ce05a63692..b0785409628c4 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ 

[clang] eed88e9 - [OpenCL] Use spir target for CIndex tests for OpenCL.

2021-03-12 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-03-12T20:11:26Z
New Revision: eed88e91f331d158d3d0c91e91fca408c9f1d1e1

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

LOG: [OpenCL] Use spir target for CIndex tests for OpenCL.

This fixes failing bots.

Patch by azabaznov (Anton Zabaznov)!

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

Added: 


Modified: 
clang/test/Index/cxx.cl
clang/test/Index/opencl-types.cl

Removed: 




diff  --git a/clang/test/Index/cxx.cl b/clang/test/Index/cxx.cl
index f4b03d78740e..997d4288669f 100644
--- a/clang/test/Index/cxx.cl
+++ b/clang/test/Index/cxx.cl
@@ -3,5 +3,5 @@ void test(int *ptr) {
   addrspace_cast<__global int*>(ptr);
 }
 
-// RUN: c-index-test -test-load-source all %s -cl-std=clc++ | FileCheck %s
+// RUN: c-index-test -test-load-source all %s -cl-std=clc++ -target spir | 
FileCheck %s
 // CHECK: cxx.cl:3:3: CXXAddrspaceCastExpr

diff  --git a/clang/test/Index/opencl-types.cl 
b/clang/test/Index/opencl-types.cl
index 496f38752fa2..485060167d21 100644
--- a/clang/test/Index/opencl-types.cl
+++ b/clang/test/Index/opencl-types.cl
@@ -1,4 +1,4 @@
-// RUN: c-index-test -test-print-type %s -cl-std=CL2.0 | FileCheck %s
+// RUN: c-index-test -test-print-type %s -cl-std=CL2.0 -target spir | 
FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bafcb4c - [OpenCL][Docs] Add guidelines for new extensions and features.

2021-03-11 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-03-11T14:28:48Z
New Revision: bafcb4c6841a302d502b14fb93101fb590459935

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

LOG: [OpenCL][Docs] Add guidelines for new extensions and features.

Add documentation that explains how to extend clang with the new
extensions/features. The guidelines also detail clang's position
about the extension pragmas for the new functionality.

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 02522052e106..f7d6b1f7f2c9 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -168,6 +168,8 @@ also :ref:`the section on the address space attribute 
`).
 
  $ clang -cc1 -ffake-address-space-map test.cl
 
+.. _opencl_builtins:
+
 OpenCL builtins
 ---
 
@@ -210,6 +212,82 @@ of the following main components:
   inserted using ``InsertOCLBuiltinDeclarationsFromTable`` and overload
   resolution takes place.
 
+OpenCL Extensions and Features
+--
+
+Clang implements various extensions to OpenCL kernel languages.
+
+New functionality is accepted as soon as the documentation is detailed to the
+level sufficient to be implemented. There should be an evidence that the
+extension is designed with implementation feasibility in consideration and
+assessment of complexity for C/C++ based compilers. Alternatively, the
+documentation can be accepted in a format of a draft that can be further
+refined during the implementation.
+
+Implementation guidelines
+^
+
+This section explains how to extend clang with the new functionality.
+
+**Parsing functionality**
+
+If an extension modifies the standard parsing it needs to be added to
+the clang frontend source code. This also means that the associated macro
+indicating the presence of the extension should be added to clang.
+
+The default flow for adding a new extension into the frontend is to
+modify `OpenCLExtensions.def
+`_
+
+This will add the macro automatically and also add a field in the target
+options ``clang::TargetOptions::OpenCLFeaturesMap`` to control the exposure
+of the new extension during the compilation.
+
+Note that by default targets like `SPIR` or `X86` expose all the OpenCL
+extensions. For all other targets the configuration has to be made explicitly.
+
+Note that the target extension support performed by clang can be overridden
+with :ref:`-cl-ext ` command-line flags.
+
+**Library functionality**
+
+If an extension adds functionality that does not modify standard language
+parsing it should not require modifying anything other than header files or
+``OpenCLBuiltins.td`` detailed in :ref:`OpenCL builtins `.
+Most commonly such extensions add functionality via libraries (by adding
+non-native types or functions) parsed regularly. Similar to other languages 
this
+is the most common way to add new functionality.
+
+Clang has standard headers where new types and functions are being added,
+for more details refer to
+:ref:`the section on the OpenCL Header `. The macros indicating
+the presence of such extensions can be added in the standard header files
+conditioned on target specific predefined macros or/and language version
+predefined macros.
+
+**Pragmas**
+
+Some extensions alter standard parsing dynamically via pragmas.
+
+Clang provides a mechanism to add the standard extension pragma
+``OPENCL EXTENSION`` by setting a dedicated flag in the extension list entry of
+``OpenCLExtensions.def``. Note that there is no default behavior for the
+standard extension pragmas as it is not specified (for the standards up to and
+including version 3.0) in a sufficient level of detail and, therefore,
+there is no default functionality provided by clang.
+
+Pragmas without detailed information of their behavior (e.g. an explanation of
+changes it triggers in the parsing) should not be added to clang. Moreover, the
+pragmas should provide useful functionality to the user. For example, such
+functionality should address a practical use case and not be redundant i.e.
+cannot be achieved using existing features.
+
+Note that some legacy extensions (published prior to OpenCL 3.0) still
+provide some non-conformant functionality for pragmas e.g. add diagnostics on
+the use of types or functions. This functionality is not guaranteed to remain 
in
+future releases. However, any future changes should not affect backward
+compatibility.
+
 .. _opencl_addrsp:
 
 Address spaces attribute



___

[clang] 25ad188 - [OpenCL] Prevent adding extension pragma by default.

2021-03-03 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-03-03T15:02:21Z
New Revision: 25ad188bfcdb2a85416013c6303f30cbc7775674

URL: 
https://github.com/llvm/llvm-project/commit/25ad188bfcdb2a85416013c6303f30cbc7775674
DIFF: 
https://github.com/llvm/llvm-project/commit/25ad188bfcdb2a85416013c6303f30cbc7775674.diff

LOG: [OpenCL] Prevent adding extension pragma by default.

This commit refactors extension support to allow
specifying whether pragma is needed or not explicitly.

For backward compatibility pragmas are set to required
for all extensions that were added prior to this but
not for OpenCL 3.0 features.

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

Added: 


Modified: 
clang/include/clang/Basic/OpenCLExtensions.def
clang/include/clang/Basic/OpenCLOptions.h
clang/lib/Basic/OpenCLOptions.cpp
clang/lib/Basic/Targets.cpp
clang/lib/Parse/ParsePragma.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/SemaOpenCL/extension-version.cl

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index 8e6f723a53a6..c5352dadc0de 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -16,8 +16,12 @@
 // If extensions are to be enumerated with information about whether
 // an extension is core or optional core and minimum OpenCL version
 // when an extension becomes available,
-// define OPENCL_GENERIC_EXTENSION(ext, avail, core, opt) where
+// define OPENCL_GENERIC_EXTENSION(ext, pragma, avail, core, opt) where
 //   ext - name of the extension or optional core feature.
+//   pragma - true if extension needs pragmas or false otherwise.
+//NOTE: extension pragma without any documentation detailing
+//its behavior explicitly is deprecated. Therefore the default
+//value is false.
 //   avail - minimum OpenCL version supporting it.
 //   core - OpenCL versions mask when the extension becomes core feature.
 //  0U indicates not a core feature.
@@ -50,67 +54,67 @@
 #endif // OPENCL_GENERIC_EXTENSION
 
 // Declaration helpers
-#define OPENCL_EXTENSION(ext, avail) OPENCL_GENERIC_EXTENSION(ext, avail, 0U, 
0U)
-#define OPENCL_COREFEATURE(ext, avail, core)  OPENCL_GENERIC_EXTENSION(ext, 
avail, core, 0U)
-#define OPENCL_OPTIONALCOREFEATURE(ext, avail, opt) 
OPENCL_GENERIC_EXTENSION(ext, avail, 0U, opt)
+#define OPENCL_EXTENSION(ext, pragma, avail) OPENCL_GENERIC_EXTENSION(ext, 
pragma, avail, 0U, 0U)
+#define OPENCL_COREFEATURE(ext, pragma, avail, core)  
OPENCL_GENERIC_EXTENSION(ext, pragma, avail, core, 0U)
+#define OPENCL_OPTIONALCOREFEATURE(ext, pragma, avail, opt) 
OPENCL_GENERIC_EXTENSION(ext, pragma, avail, 0U, opt)
 
 // OpenCL 1.0.
-OPENCL_COREFEATURE(cl_khr_byte_addressable_store, 100, OCL_C_11P)
-OPENCL_COREFEATURE(cl_khr_global_int32_base_atomics, 100, OCL_C_11P)
-OPENCL_COREFEATURE(cl_khr_global_int32_extended_atomics, 100, OCL_C_11P)
-OPENCL_COREFEATURE(cl_khr_local_int32_base_atomics, 100, OCL_C_11P)
-OPENCL_COREFEATURE(cl_khr_local_int32_extended_atomics, 100, OCL_C_11P)
-OPENCL_OPTIONALCOREFEATURE(cl_khr_fp64, 100, OCL_C_12P)
-OPENCL_EXTENSION(cl_khr_fp16, 100)
-OPENCL_EXTENSION(cl_khr_int64_base_atomics, 100)
-OPENCL_EXTENSION(cl_khr_int64_extended_atomics, 100)
-OPENCL_COREFEATURE(cl_khr_3d_image_writes, 100, OCL_C_20)
+OPENCL_COREFEATURE(cl_khr_byte_addressable_store, true, 100, OCL_C_11P)
+OPENCL_COREFEATURE(cl_khr_global_int32_base_atomics, true, 100, OCL_C_11P)
+OPENCL_COREFEATURE(cl_khr_global_int32_extended_atomics, true, 100, OCL_C_11P)
+OPENCL_COREFEATURE(cl_khr_local_int32_base_atomics, true, 100, OCL_C_11P)
+OPENCL_COREFEATURE(cl_khr_local_int32_extended_atomics, true, 100, OCL_C_11P)
+OPENCL_OPTIONALCOREFEATURE(cl_khr_fp64, true, 100, OCL_C_12P)
+OPENCL_EXTENSION(cl_khr_fp16, true, 100)
+OPENCL_EXTENSION(cl_khr_int64_base_atomics, true, 100)
+OPENCL_EXTENSION(cl_khr_int64_extended_atomics, true, 100)
+OPENCL_COREFEATURE(cl_khr_3d_image_writes, true, 100, OCL_C_20)
 
 // EMBEDDED_PROFILE
-OPENCL_EXTENSION(cles_khr_int64, 110)
+OPENCL_EXTENSION(cles_khr_int64, true, 110)
 
 // OpenCL 1.2.
-OPENCL_EXTENSION(cl_khr_depth_images, 120)
-OPENCL_EXTENSION(cl_khr_gl_msaa_sharing, 120)
+OPENCL_EXTENSION(cl_khr_depth_images, true, 120)
+OPENCL_EXTENSION(cl_khr_gl_msaa_sharing,true, 120)
 
 // OpenCL 2.0.
-OPENCL_EXTENSION(cl_khr_mipmap_image, 200)
-OPENCL_EXTENSION(cl_khr_mipmap_image_writes, 200)
-OPENCL_EXTENSION(cl_khr_srgb_image_writes, 200)
-OPENCL_EXTENSION(cl_khr_subgroups, 200)
+OPENCL_EXTENSION(cl_khr_mipmap_image, true, 200)
+OPENCL_EXTENSION(cl_khr_mipmap_image_writes, true, 200)
+OPENCL_EXTENSION(cl_khr_srgb_image_writes, true, 200)
+OPENCL_EXTENSION(cl_khr_subgroups, true, 200)
 
 // Clang Extensions.
-OPENCL_EXTENSION(cl_clang_storage_class_specifiers, 100)

[clang] abbdb56 - [OpenCL] Allow taking address of functions as an extension.

2021-02-24 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-24T12:32:02Z
New Revision: abbdb5639c70d167bd66cd62296927330782c3b4

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

LOG: [OpenCL] Allow taking address of functions as an extension.

When '__cl_clang_function_pointers' extension is enabled
the parser should allow obtaining the function address.

This fixes PR49264!

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

Added: 


Modified: 
clang/lib/Parse/ParseExpr.cpp
clang/test/SemaOpenCL/func.cl

Removed: 




diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 6acf76d713fd..3b0dd3f4036f 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1807,7 +1807,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   // These can be followed by postfix-expr pieces.
   PreferredType = SavedType;
   Res = ParsePostfixExpressionSuffix(Res);
-  if (getLangOpts().OpenCL)
+  if (getLangOpts().OpenCL && !getActions().getOpenCLOptions().isEnabled(
+  "__cl_clang_function_pointers"))
 if (Expr *PostfixExpr = Res.get()) {
   QualType Ty = PostfixExpr->getType();
   if (!Ty.isNull() && Ty->isFunctionType()) {

diff  --git a/clang/test/SemaOpenCL/func.cl b/clang/test/SemaOpenCL/func.cl
index 8a9c20289f59..bcac30b67e37 100644
--- a/clang/test/SemaOpenCL/func.cl
+++ b/clang/test/SemaOpenCL/func.cl
@@ -38,6 +38,9 @@ typedef struct s
 
 //Function pointer
 void foo(void*);
+#ifdef FUNCPTREXT
+//expected-note@-2{{passing argument to parameter here}}
+#endif
 
 // Expect no diagnostics for an empty parameter list.
 void bar();
@@ -51,11 +54,30 @@ void bar()
 #endif
 
   // taking the address of a function is an error
-  foo((void*)foo); // expected-error{{taking address of function is not 
allowed}}
-  foo(); // expected-error{{taking address of function is not allowed}}
+  foo((void*)foo);
+#ifndef FUNCPTREXT
+  // expected-error@-2{{taking address of function is not allowed}}
+#else
+  // FIXME: Functions should probably be in the address space defined by the
+  // implementation. It might make sense to put them into the Default address
+  // space that is bind to a physical segment by the target rather than fixing
+  // it to any of the concrete OpenCL address spaces during parsing.
+  // expected-error@-8{{casting 'void (*)(__private void *__private)' to type 
'__private void *' changes address space}}
+#endif
 
+  foo();
+#ifndef FUNCPTREXT
+  // expected-error@-2{{taking address of function is not allowed}}
+#else
+  // expected-error@-4{{passing 'void (*)(__private void *__private)' to 
parameter of type '__private void *' changes address space of pointer}}
+#endif
+
+  // FIXME: If we stop rejecting the line below a bug (PR49315) gets
+  // hit due to incorrectly handled pointer conversion.
+#ifndef FUNCPTREXT
   // initializing an array with the address of functions is an error
   void* vptrarr[2] = {foo, }; // expected-error{{taking address of 
function is not allowed}} expected-error{{taking address of function is not 
allowed}}
+#endif
 
   // just calling a function is correct
   foo(0);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 90355d6 - [OpenCL][Docs] Change description for the OpenCL standard headers.

2021-02-23 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-23T11:49:05Z
New Revision: 90355d6f10765d03af1bfcc1ab3d17e8cae330f1

URL: 
https://github.com/llvm/llvm-project/commit/90355d6f10765d03af1bfcc1ab3d17e8cae330f1
DIFF: 
https://github.com/llvm/llvm-project/commit/90355d6f10765d03af1bfcc1ab3d17e8cae330f1.diff

LOG: [OpenCL][Docs] Change description for the OpenCL standard headers.

After updating the user interface in D96515, update the docs
reflecting the new approach.

Tags: #clang

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 266fde3436d3..02522052e106 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -63,6 +63,10 @@ OpenCL Specific Options
 In addition to the options described in :doc:`UsersManual` there are the
 following options specific to the OpenCL frontend.
 
+All the options in this section are frontend-only and therefore if used
+with regular clang driver they require frontend forwarding, e.g. ``-cc1``
+or ``-Xclang``.
+
 .. _opencl_cl_ext:
 
 .. option:: -cl-ext
@@ -76,9 +80,6 @@ can be either one of `the OpenCL published extensions
 or any vendor extension. Alternatively, ``'all'`` can be used to enable
 or disable all known extensions.
 
-Note that this is a frontend-only flag and therefore it requires the use of
-flags that forward options to the frontend e.g. ``-cc1`` or ``-Xclang``.
-
 Example disabling double support for the 64-bit SPIR target:
 
.. code-block:: console
@@ -91,6 +92,65 @@ Enabling all extensions except double support in R600 AMD 
GPU can be done using:
 
  $ clang -cc1 -triple r600-unknown-unknown -cl-ext=-all,+cl_khr_fp16 
test.cl
 
+.. _opencl_finclude_default_header:
+
+.. option:: -finclude-default-header
+
+Adds most of builtin types and function declarations during compilations. By
+default the OpenCL headers are not loaded by the frontend and therefore certain
+builtin types and most of builtin functions are not declared. To load them
+automatically this flag can be passed to the frontend (see also :ref:`the
+section on the OpenCL Header `):
+
+   .. code-block:: console
+
+ $ clang -Xclang -finclude-default-header test.cl
+
+Alternatively the internal header `opencl-c.h` containing the declarations
+can be included manually using ``-include`` or ``-I`` followed by the path
+to the header location. The header can be found in the clang source tree or
+installation directory.
+
+   .. code-block:: console
+
+ $ clang -I/lib/Headers/opencl-c.h test.cl
+ $ clang -I/lib/clang//include/opencl-c.h/opencl-c.h test.cl
+
+In this example it is assumed that the kernel code contains
+``#include `` just as a regular C include.
+
+Because the header is very large and long to parse, PCH (:doc:`PCHInternals`)
+and modules (:doc:`Modules`) can be used internally to improve the compilation
+speed.
+
+To enable modules for OpenCL:
+
+   .. code-block:: console
+
+ $ clang -target spir-unknown-unknown -c -emit-llvm -Xclang 
-finclude-default-header -fmodules -fimplicit-module-maps -fm 
odules-cache-path= test.cl
+
+Another way to circumvent long parsing latency for the OpenCL builtin
+declarations is to use mechanism enabled by :ref:`-fdeclare-opencl-builtins
+` flag that is available as an alternative
+feature.
+
+.. _opencl_fdeclare_opencl_builtins:
+
+.. option:: -fdeclare-opencl-builtins
+
+In addition to regular header includes with builtin types and functions using
+:ref:`-finclude-default-header `, clang
+supports a fast mechanism to declare builtin functions with
+``-fdeclare-opencl-builtins``. This does not declare the builtin types and
+therefore it has to be used in combination with ``-finclude-default-header``
+if full functionality is required.
+
+**Example of Use**:
+
+.. code-block:: console
+ 
+  $ clang -Xclang -fdeclare-opencl-builtins test.cl
+
 .. _opencl_fake_address_space_map:
 
 .. option:: -ffake-address-space-map
@@ -108,9 +168,6 @@ also :ref:`the section on the address space attribute 
`).
 
  $ clang -cc1 -ffake-address-space-map test.cl
 
-Note that this is a frontend-only flag and therefore it requires the use of
-flags that forward options to the frontend e.g. ``-cc1`` or ``-Xclang``.
-
 OpenCL builtins
 ---
 
@@ -134,8 +191,8 @@ There are some standard OpenCL functions that are 
implemented as Clang builtins:
 **Fast builtin function declarations**
 
 The implementation of the fast builtin function declarations (available via the
-:ref:`-fdeclare-opencl-builtins option `) consists of the
-following main components:
+:ref:`-fdeclare-opencl-builtins option `) 
consists
+of the following main components:
 
 - A TableGen definitions file ``OpenCLBuiltins.td``.  This contains a compact
   representation of the 

[clang-tools-extra] b71add9 - [pp-trace] Fix test for OpenCL pragmas.

2021-02-22 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-22T14:28:45Z
New Revision: b71add9777bed67e05206fa1fdb665f3e21a13ab

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

LOG: [pp-trace] Fix test for OpenCL pragmas.

After updating clang driver to include standard
OpenCL headers implicitly, the output being checked
in the test does not match because the implicit
header contains other pragmas. The test does not
aim to use the header and therefore it has to be
updated passing '-cl-no-stdinc' command-line flag.

This fixes failing bots.

Added: 


Modified: 
clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp

Removed: 




diff  --git a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp 
b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
index 8ba26c3b7396..31f61027994f 100644
--- a/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
+++ b/clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
@@ -1,4 +1,4 @@
-// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl | 
FileCheck --strict-whitespace %s
+// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x cl 
-cl-no-stdinc | FileCheck --strict-whitespace %s
 
 #pragma OPENCL EXTENSION all : disable
 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : disable



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] cf3ef15 - [OpenCL] Add builtin declarations by default.

2021-02-22 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-22T12:24:16Z
New Revision: cf3ef15a6ec5e5b45c6c54e8fbe3769255e815ce

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

LOG: [OpenCL] Add builtin declarations by default.

This change enables the builtin function declarations
in clang driver by default using the Tablegen solution
along with the implicit include of 'opencl-c-base.h'
header.

A new flag '-cl-no-stdinc' disabling all default
declarations and header includes is added. If any other
mechanisms were used to include the declarations (e.g.
with -Xclang -finclude-default-header) and the new default
approach is not sufficient the, `-cl-no-stdinc` flag has
to be used with clang to activate the old behavior.

Tags: #clang

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

Added: 
clang/test/Driver/default-includes.cl

Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/Types.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/Types.cpp
clang/unittests/AST/MatchVerifier.h

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bbaa16658639..e4a6ef9cb2f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -818,6 +818,8 @@ def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], 
"cl-fp32-correctly-round
 def cl_uniform_work_group_size : Flag<["-"], "cl-uniform-work-group-size">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Defines that the global work-size be a multiple of 
the work-group size specified to clEnqueueNDRangeKernel">,
   MarshallingInfoFlag>;
+def cl_no_stdinc : Flag<["-"], "cl-no-stdinc">, Group,
+  HelpText<"OpenCL only. Disables all standard includes containing non-native 
compiler types and functions.">;
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, 
Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;

diff  --git a/clang/include/clang/Driver/Types.h 
b/clang/include/clang/Driver/Types.h
index 97bf5fd672ab..6a1f57416ae5 100644
--- a/clang/include/clang/Driver/Types.h
+++ b/clang/include/clang/Driver/Types.h
@@ -81,6 +81,9 @@ namespace types {
   /// isObjC - Is this an "ObjC" input (Obj-C and Obj-C++ sources and headers).
   bool isObjC(ID Id);
 
+  /// isOpenCL - Is this an "OpenCL" input.
+  bool isOpenCL(ID Id);
+
   /// isFortran - Is this a Fortran input.
   bool isFortran(ID Id);
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 386bec831175..17bb48cd595d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3193,7 +3193,8 @@ static void RenderTrivialAutoVarInitOptions(const Driver 
,
   }
 }
 
-static void RenderOpenCLOptions(const ArgList , ArgStringList ) {
+static void RenderOpenCLOptions(const ArgList , ArgStringList ,
+types::ID InputType) {
   // cl-denorms-are-zero is not forwarded. It is translated into a generic flag
   // for denormal flushing handling based on the target.
   const unsigned ForwardedArguments[] = {
@@ -3218,6 +3219,13 @@ static void RenderOpenCLOptions(const ArgList , 
ArgStringList ) {
   for (const auto  : ForwardedArguments)
 if (const auto *A = Args.getLastArg(Arg))
   CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
+
+  // Only add the default headers if we are compiling OpenCL sources.
+  if ((types::isOpenCL(InputType) || Args.hasArg(options::OPT_cl_std_EQ)) &&
+  !Args.hasArg(options::OPT_cl_no_stdinc)) {
+CmdArgs.push_back("-finclude-default-header");
+CmdArgs.push_back("-fdeclare-opencl-builtins");
+  }
 }
 
 static void RenderARCMigrateToolOptions(const Driver , const ArgList ,
@@ -5726,7 +5734,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   }
 
   // Forward -cl options to -cc1
-  RenderOpenCLOptions(Args, CmdArgs);
+  RenderOpenCLOptions(Args, CmdArgs, InputType);
 
   if (IsHIP) {
 if (Args.hasFlag(options::OPT_fhip_new_launch_api,

diff  --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index 2050dffa6fa0..9bdebe2dd761 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -160,6 +160,8 @@ bool types::isObjC(ID Id) {
   }
 }
 
+bool types::isOpenCL(ID Id) { return Id == TY_CL; }
+
 bool types::isCXX(ID Id) {
   switch (Id) {
   default:

diff  --git a/clang/test/Driver/default-includes.cl 
b/clang/test/Driver/default-includes.cl
new file mode 100644
index ..2596ccca9638
--- /dev/null
+++ b/clang/test/Driver/default-includes.cl
@@ -0,0 +1,13 @@
+// RUN: %clang %s -Xclang -verify -fsyntax-only
+// RUN: 

[clang] 79b222c - [OpenCL] Fix types with signed prefix in arginfo metadata.

2021-02-09 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-09T15:13:19Z
New Revision: 79b222c39f0e4377b49191b6aba080b1607f3fa7

URL: 
https://github.com/llvm/llvm-project/commit/79b222c39f0e4377b49191b6aba080b1607f3fa7
DIFF: 
https://github.com/llvm/llvm-project/commit/79b222c39f0e4377b49191b6aba080b1607f3fa7.diff

LOG: [OpenCL] Fix types with signed prefix in arginfo metadata.

Signed prefix is removed and the single word spelling is
printed for the scalar types.

Tags: #clang

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenOpenCL/kernel-arg-info.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 62448b74c727..1c28c50e60f5 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1501,6 +1501,8 @@ void CodeGenModule::GenOpenCLArgMetadata(llvm::Function 
*Fn,
   // Turn "unsigned type" to "utype"
   if (typeNameRef.consume_front("unsigned "))
 return std::string("u") + typeNameRef.str();
+  if (typeNameRef.consume_front("signed "))
+return typeNameRef.str();
 }
 
 return typeName;

diff  --git a/clang/test/CodeGenOpenCL/kernel-arg-info.cl 
b/clang/test/CodeGenOpenCL/kernel-arg-info.cl
index fae8a007b2d8..dbb59af9470c 100644
--- a/clang/test/CodeGenOpenCL/kernel-arg-info.cl
+++ b/clang/test/CodeGenOpenCL/kernel-arg-info.cl
@@ -107,6 +107,16 @@ kernel void foo8(pipe int p1, pipe uchar p2, pipe uchar2 
p3, const pipe uchar p4
 // CHECK-NOT: !kernel_arg_name
 // ARGINFO: !kernel_arg_name ![[PIPE_ARG_NAMES:[0-9]+]]
 
+kernel void foo9(signed char sc1,  global const signed char* sc2) {}
+// CHECK: define{{.*}} spir_kernel void @foo9{{[^!]+}}
+// CHECK: !kernel_arg_addr_space ![[SCHAR_AS_QUAL:[0-9]+]]
+// CHECK: !kernel_arg_access_qual ![[MD42]]
+// CHECK: !kernel_arg_type ![[SCHAR_TY:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[SCHAR_TY]]
+// CHECK: !kernel_arg_type_qual ![[SCHAR_QUAL:[0-9]+]]
+// CHECK-NOT: !kernel_arg_name
+// ARGINFO: !kernel_arg_name ![[SCHAR_ARG_NAMES:[0-9]+]]
+
 // CHECK: ![[MD11]] = !{i32 1, i32 1, i32 1, i32 1, i32 2, i32 2, i32 1, i32 
1, i32 1, i32 1, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 0, 
i32 0, i32 0, i32 0}
 // CHECK: ![[MD12]] = !{!"none", !"none", !"none", !"none", !"none", !"none", 
!"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none", 
!"none", !"none", !"none", !"none", !"none", !"none", !"none", !"none"}
 // CHECK: ![[MD13]] = !{!"int*", !"int*", !"int*", !"int*", !"int*", !"int*", 
!"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", !"int*", 
!"int*", !"int*", !"int*", !"int*", !"int", !"int", !"int", !"int"}
@@ -146,3 +156,7 @@ kernel void foo8(pipe int p1, pipe uchar p2, pipe uchar2 
p3, const pipe uchar p4
 // CHECK: ![[PIPE_BASE_TY]] = !{!"int", !"uchar", !"uchar 
__attribute__((ext_vector_type(2)))", !"uchar", !"uchar"}
 // CHECK: ![[PIPE_QUAL]] = !{!"pipe", !"pipe", !"pipe", !"pipe", !"pipe"}
 // ARGINFO: ![[PIPE_ARG_NAMES]] = !{!"p1", !"p2", !"p3", !"p4", !"p5"}
+// CHECK: ![[SCHAR_AS_QUAL]] = !{i32 0, i32 1}
+// CHECK: ![[SCHAR_TY]] = !{!"char", !"char*"}
+// CHECK: ![[SCHAR_QUAL]] = !{!"", !"const"}
+// ARGINFO: ![[SCHAR_ARG_NAMES]] = !{!"sc1", !"sc2"}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0fb4341 - [OpenCL][Docs] Link page explaining tooling for offline compilation.

2021-02-04 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-04T14:01:27Z
New Revision: 0fb4341519ef3ac06518ba56bb100277d89cdf11

URL: 
https://github.com/llvm/llvm-project/commit/0fb4341519ef3ac06518ba56bb100277d89cdf11
DIFF: 
https://github.com/llvm/llvm-project/commit/0fb4341519ef3ac06518ba56bb100277d89cdf11.diff

LOG: [OpenCL][Docs] Link page explaining tooling for offline compilation.

Tags: #clang

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

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index fae22feef07b..dfc0ea29487e 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2901,8 +2901,10 @@ Note that if compiled to bitcode for generic targets 
such as SPIR,
 portable IR is produced that can be used with various vendor
 tools as well as open source tools such as `SPIRV-LLVM Translator
 `_
-to produce SPIR-V binary.
-
+to produce SPIR-V binary. More details are provided in `the offline
+compilation from OpenCL kernel sources into SPIR-V using open source
+tools
+`_.
 
 Clang currently supports OpenCL C language standards up to v2.0. Clang mainly
 supports full profile. There is only very limited support of the embedded



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0c65993 - [OpenCL] Fix default address space in template argument deduction.

2021-02-04 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-04T13:51:53Z
New Revision: 0c65993be186640463ac90415113474d35889dbb

URL: 
https://github.com/llvm/llvm-project/commit/0c65993be186640463ac90415113474d35889dbb
DIFF: 
https://github.com/llvm/llvm-project/commit/0c65993be186640463ac90415113474d35889dbb.diff

LOG: [OpenCL] Fix default address space in template argument deduction.

When deducing a reference type for forwarding references prevent
adding default address space of a template argument if it is given.

This got reported in PR48896 because in OpenCL all parameters are
in private address space and therefore when we initialize a
forwarding reference with a parameter we should just inherit the
address space from it i.e. keep __private instead of __generic.

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaOpenCLCXX/address-space-templates.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index ee4316e7a632..6336f3b99452 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3869,7 +3869,7 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
 Arg->isLValue()) {
-  if (S.getLangOpts().OpenCL)
+  if (S.getLangOpts().OpenCL  && !ArgType.hasAddressSpace())
 ArgType = S.Context.getAddrSpaceQualType(ArgType, 
LangAS::opencl_generic);
   ArgType = S.Context.getLValueReferenceType(ArgType);
 }

diff  --git a/clang/test/SemaOpenCLCXX/address-space-templates.cl 
b/clang/test/SemaOpenCLCXX/address-space-templates.cl
index be187de5684b..b7db0e6de3d2 100644
--- a/clang/test/SemaOpenCLCXX/address-space-templates.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-templates.cl
@@ -1,4 +1,4 @@
-//RUN: %clang_cc1 %s -cl-std=clc++ -pedantic -verify -fsyntax-only
+//RUN: %clang_cc1 %s -cl-std=clc++ -pedantic -verify -ast-dump  | FileCheck %s
 
 template 
 struct S {
@@ -28,8 +28,10 @@ template  struct as_pointer {
 typedef typename remove_reference<_Tp>::type* type;
 };
 
+// Check address space deduction in template parameter deduction.
 struct rep {
-  // CHECK |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep 
&__private) __generic'
+  // When there is no address space on a reference use __generic.
+  // CHECK: |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep 
&__private) __generic'
   template::type>
   rep(U&& v) {}
 };
@@ -39,11 +41,22 @@ struct rep_outer : private rep {
 : rep(0) {}
 };
 
+
+template
+void foo4(T t, F f){
+  f(t);
+}
+
 void bar() {
   S sintgl; // expected-note{{in instantiation of template 
class 'S' requested here}}
 
   foo1<__local int>(1); // expected-error{{no matching function for call to 
'foo1'}}
   foo2<__global int>(0);
   foo3<__global int>(); // expected-note{{in instantiation of function 
template specialization 'foo3<__global int>' requested here}}
+
   rep_outer r;
+  int i;
+  // Preserve the address space of the type in forwarding reference.
+  // CHECK: CXXMethodDecl {{.*}} operator() 'void (__private int &__private) 
const __generic'
+  foo4(i, [](auto&& x){;});
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7a45f27 - [OpenCL][Docs] Fix command line flag in the example.

2021-02-03 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-03T14:07:46Z
New Revision: 7a45f27ba156e311bf1deaa42761ec08d8e34d05

URL: 
https://github.com/llvm/llvm-project/commit/7a45f27ba156e311bf1deaa42761ec08d8e34d05
DIFF: 
https://github.com/llvm/llvm-project/commit/7a45f27ba156e311bf1deaa42761ec08d8e34d05.diff

LOG: [OpenCL][Docs] Fix command line flag in the example.

Fixed incorrect example of clang command line with
the builtin function declarations in OpenCLSupport.

Tags: #clang

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 64109b7fab48..716ce9953e35 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -253,7 +253,7 @@ if full functionality is required.
 
 .. code-block:: console
  
-  $ clang -Xclang -finclude-default-header test.cl
+  $ clang -Xclang -fdeclare-opencl-builtins test.cl
 
 Note that this is a frontend-only flag and therefore it requires the use of
 flags that forward options to the frontend, e.g. ``-cc1`` or ``-Xclang``.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e635feb - [OpenCL] Fix address space in binding of initializer lists to referencs

2021-02-03 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-03T12:48:21Z
New Revision: e635feb15a91e6eeb77876031be2811e63d542f3

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

LOG: [OpenCL] Fix address space in binding of initializer lists to referencs

Prevent materializing temporaries in the address space of the references
they are bind to. The temporaries should always be in the same address
space - private for OpenCL.

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/CodeGenOpenCLCXX/addrspace-references.cl
clang/test/SemaOpenCLCXX/address-space-references.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index f4493d84238d..4e3547c5121f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4289,17 +4289,36 @@ static void TryReferenceListInitialization(Sema ,
 if (Sequence.step_begin() != Sequence.step_end())
   Sequence.RewrapReferenceInitList(cv1T1, InitList);
   }
-
+  // Perform address space compatibility check.
+  QualType cv1T1IgnoreAS = cv1T1;
+  if (T1Quals.hasAddressSpace()) {
+Qualifiers T2Quals;
+(void)S.Context.getUnqualifiedArrayType(InitList->getType(), T2Quals);
+if (!T1Quals.isAddressSpaceSupersetOf(T2Quals)) {
+  Sequence.SetFailed(
+  InitializationSequence::FK_ReferenceInitDropsQualifiers);
+  return;
+}
+// Ignore address space of reference type at this point and perform address
+// space conversion after the reference binding step.
+cv1T1IgnoreAS =
+S.Context.getQualifiedType(T1, T1Quals.withoutAddressSpace());
+  }
   // Not reference-related. Create a temporary and bind to that.
-  InitializedEntity TempEntity = InitializedEntity::InitializeTemporary(cv1T1);
+  InitializedEntity TempEntity =
+  InitializedEntity::InitializeTemporary(cv1T1IgnoreAS);
 
   TryListInitialization(S, TempEntity, Kind, InitList, Sequence,
 TreatUnavailableAsInvalid);
   if (Sequence) {
 if (DestType->isRValueReferenceType() ||
-(T1Quals.hasConst() && !T1Quals.hasVolatile()))
-  Sequence.AddReferenceBindingStep(cv1T1, /*BindingTemporary=*/true);
-else
+(T1Quals.hasConst() && !T1Quals.hasVolatile())) {
+  Sequence.AddReferenceBindingStep(cv1T1IgnoreAS,
+   /*BindingTemporary=*/true);
+  if (T1Quals.hasAddressSpace())
+Sequence.AddQualificationConversionStep(
+cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+} else
   Sequence.SetFailed(
   
InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);
   }

diff  --git a/clang/test/CodeGenOpenCLCXX/addrspace-references.cl 
b/clang/test/CodeGenOpenCLCXX/addrspace-references.cl
index 056168684d2d..6d4bece1a624 100644
--- a/clang/test/CodeGenOpenCLCXX/addrspace-references.cl
+++ b/clang/test/CodeGenOpenCLCXX/addrspace-references.cl
@@ -1,8 +1,16 @@
-//RUN: %clang_cc1 %s -cl-std=clc++ -triple spir -emit-llvm -o - | FileCheck %s
+//RUN: %clang_cc1 %s -cl-std=clc++ -triple spir -emit-llvm -o - -O0 | 
FileCheck %s
+
+typedef short short2 __attribute__((ext_vector_type(2)));
 
 int bar(const unsigned int );
-// CHECK-LABEL: define{{.*}} spir_func void @_Z3foov() 
-void foo() {
+
+class C {
+public:
+  void bar(const short2 &);
+};
+
+// CHECK-LABEL: define{{.*}} spir_func void @_Z6scalarv()
+void scalar() {
   // The generic addr space reference parameter object will be bound
   // to a temporary value allocated in private addr space. We need an
   // addrspacecast before passing the value to the function.
@@ -12,3 +20,14 @@ void foo() {
   // CHECK: call spir_func i32 @_Z3barRU3AS4Kj(i32 addrspace(4)* align 4 
dereferenceable(4) [[REG]])
   bar(1);
 }
+
+// Test list initialization
+// CHECK-LABEL: define{{.*}} spir_func void @_Z4listv()
+void list() {
+  C c1;
+// CHECK: [[REF:%.*]] = alloca <2 x i16>
+// CHECK: store <2 x i16> , <2 x i16>* [[REF]]
+// CHECK: [[REG:%[.a-z0-9]+]] = addrspacecast <2 x i16>* [[REF]] to <2 x i16> 
addrspace(4)*
+// CHECK: call {{.*}}void @_ZNU3AS41C3barERU3AS4KDv2_s(%class.C addrspace(4)* 
{{.*}}, <2 x i16> addrspace(4)*{{.*}} [[REG]])
+  c1.bar({1, 2});
+}

diff  --git a/clang/test/SemaOpenCLCXX/address-space-references.cl 
b/clang/test/SemaOpenCLCXX/address-space-references.cl
index 66cd1c02e32f..05e789a7d4fd 100644
--- a/clang/test/SemaOpenCLCXX/address-space-references.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-references.cl
@@ -10,8 +10,20 @@ int bar(const __global unsigned int ); // 
expected-note{{passing argument to p
 // can't detect this case and therefore fails.
 int bar(const unsigned int );
 
+typedef short short2 

[clang] 844f01f - Fixed failing OpenCL test

2021-02-02 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-02T16:19:28Z
New Revision: 844f01fc9589b25a3427a6cf4ca406e6787ae171

URL: 
https://github.com/llvm/llvm-project/commit/844f01fc9589b25a3427a6cf4ca406e6787ae171
DIFF: 
https://github.com/llvm/llvm-project/commit/844f01fc9589b25a3427a6cf4ca406e6787ae171.diff

LOG: Fixed failing OpenCL test

Added: 


Modified: 
clang/test/SemaOpenCLCXX/references.cl

Removed: 




diff  --git a/clang/test/SemaOpenCLCXX/references.cl 
b/clang/test/SemaOpenCLCXX/references.cl
index c02d73a4bd69..42acb1272927 100644
--- a/clang/test/SemaOpenCLCXX/references.cl
+++ b/clang/test/SemaOpenCLCXX/references.cl
@@ -1,5 +1,5 @@
-//RUN: %clang_cc1 %s -cl-std=clc++ -verify -fsyntax-only
-//RUN: %clang_cc1 %s -cl-std=clc++ -verify -fsyntax-only -DFPTREXT
+//RUN: %clang_cc1 %s -cl-std=clc++ -verify -fsyntax-only -triple spir
+//RUN: %clang_cc1 %s -cl-std=clc++ -verify -fsyntax-only -DFPTREXT -triple spir
 
 #ifdef FPTREXT
 #pragma OPENCL EXTENSION __cl_clang_function_pointers : enable



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5bbf397 - [OpenCL] Add diagnostics for references to functions

2021-02-02 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-02-02T15:07:40Z
New Revision: 5bbf39704c2b70581d78a463f3c9d20b0eb7dcd5

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

LOG: [OpenCL] Add diagnostics for references to functions

Restrict use of references to functions as they can
result in non-conforming behavior.

Tags: #clang

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

Added: 
clang/test/SemaOpenCLCXX/references.cl

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/test/SemaOpenCLCXX/members.cl

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 67c59f3ca09a..d31cc76b04d1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8547,7 +8547,7 @@ def err_invalid_conversion_between_vector_and_integer : 
Error<
   "of 
diff erent size">;
 
 def err_opencl_function_pointer : Error<
-  "pointers to functions are not allowed">;
+  "%select{pointers|references}0 to functions are not allowed">;
 
 def err_opencl_taking_address_capture : Error<
   "taking address of a capture is not allowed">;

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ef4947baf665..7da00cb598f4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6756,10 +6756,13 @@ static bool diagnoseOpenCLTypes(Scope *S, Sema , 
Declarator ,
 
   // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
   if (!Se.getOpenCLOptions().isEnabled("__cl_clang_function_pointers")) {
-QualType NR = R;
-while (NR->isPointerType() || NR->isMemberFunctionPointerType()) {
-  if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType()) {
-Se.Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer);
+QualType NR = R.getCanonicalType();
+while (NR->isPointerType() || NR->isMemberFunctionPointerType() ||
+   NR->isReferenceType()) {
+  if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType() ||
+  NR->isFunctionReferenceType()) {
+Se.Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer)
+<< NR->isReferenceType();
 D.setInvalidType();
 return false;
   }

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 4178024d1264..e24eb266dd5f 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2091,7 +2091,7 @@ QualType Sema::BuildPointerType(QualType T,
 
   if (T->isFunctionType() && getLangOpts().OpenCL &&
   !getOpenCLOptions().isEnabled("__cl_clang_function_pointers")) {
-Diag(Loc, diag::err_opencl_function_pointer);
+Diag(Loc, diag::err_opencl_function_pointer) << /*pointer*/ 0;
 return QualType();
   }
 
@@ -2163,6 +2163,12 @@ QualType Sema::BuildReferenceType(QualType T, bool 
SpelledAsLValue,
   if (checkQualifiedFunction(*this, T, Loc, QFK_Reference))
 return QualType();
 
+  if (T->isFunctionType() && getLangOpts().OpenCL &&
+  !getOpenCLOptions().isEnabled("__cl_clang_function_pointers")) {
+Diag(Loc, diag::err_opencl_function_pointer) << /*reference*/ 1;
+return QualType();
+  }
+
   // In ARC, it is forbidden to build references to unqualified pointers.
   if (getLangOpts().ObjCAutoRefCount)
 T = inferARCLifetimeForPointee(*this, T, Loc, /*reference*/ true);
@@ -2889,6 +2895,12 @@ QualType Sema::BuildMemberPointerType(QualType T, 
QualType Class,
 return QualType();
   }
 
+  if (T->isFunctionType() && getLangOpts().OpenCL &&
+  !getOpenCLOptions().isEnabled("__cl_clang_function_pointers")) {
+Diag(Loc, diag::err_opencl_function_pointer) << /*pointer*/ 0;
+return QualType();
+  }
+
   // Adjust the default free function calling convention to the default method
   // calling convention.
   bool IsCtorOrDtor =

diff  --git a/clang/test/SemaOpenCLCXX/members.cl 
b/clang/test/SemaOpenCLCXX/members.cl
index d561445eb8a2..855948f0615e 100644
--- a/clang/test/SemaOpenCLCXX/members.cl
+++ b/clang/test/SemaOpenCLCXX/members.cl
@@ -13,31 +13,13 @@ struct C {
 };
 
 typedef void (C::*p_t)(int);
-
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-
-template 
-void templ_test() {
-  typename remove_reference::type *ptr;
 #ifndef FUNCPTREXT
-  //expected-error@-2{{pointers to functions are not allowed}}
+//expected-error@-2{{pointers to functions are not allowed}}
 #endif
-}
 
 void test() {
   void (C::*p)(int);
 #ifndef FUNCPTREXT
 //expected-error@-2{{pointers to functions are not allowed}}
-#endif
-
-  p_t p1;
-#ifndef FUNCPTREXT
-//expected-error@-2{{pointers to 

[clang] 8fdd578 - [OpenCL][Docs] Describe tablegen BIFs declarations.

2021-01-25 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-01-25T11:17:03Z
New Revision: 8fdd5784f0d30b165602343a96a34611779b007b

URL: 
https://github.com/llvm/llvm-project/commit/8fdd5784f0d30b165602343a96a34611779b007b
DIFF: 
https://github.com/llvm/llvm-project/commit/8fdd5784f0d30b165602343a96a34611779b007b.diff

LOG: [OpenCL][Docs] Describe tablegen BIFs declarations.

Added documentation for the fast builtin
function declarations with -fdeclare-opencl-builtins.

Tags: #clang

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 5be7e91adcaf..0eaf0f300ee4 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -112,6 +112,28 @@ Feel free to contact us on `cfe-dev
 `_ or via `Bugzilla
 `__.
 
+Fast builtin function declarations
+--
+
+In addition to regular header includes with builtin types and functions using
+``-finclude-default-header`` explained in :doc:`UsersManual`, clang
+supports a fast mechanism to declare builtin functions with
+``-fdeclare-opencl-builtins``. This does not declare the builtin types and
+therefore it has to be used in combination with ``-finclude-default-header``
+if full functionality is required.
+
+**Example of Use**:
+
+.. code-block:: console
+ 
+  $ clang -Xclang -finclude-default-header test.cl
+
+Note that this is a frontend-only flag and therefore it requires the use of
+flags that forward options to the frontend, e.g. ``-cc1`` or ``-Xclang``.
+
+As this feature is still in experimental phase some changes might still occur
+on the command line interface side.
+
 C++ libraries for OpenCL
 
 

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index a7b698d77c47..fe944a0166b8 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3021,6 +3021,11 @@ To enable modules for OpenCL:
 
  $ clang -target spir-unknown-unknown -c -emit-llvm -Xclang 
-finclude-default-header -fmodules -fimplicit-module-maps 
-fmodules-cache-path= test.cl
 
+Another way to circumvent long parsing latency for the OpenCL builtin
+declarations is to use mechanism enabled by ``-fdeclare-opencl-builtins`` flag
+that is available as an experimental feature (see more information in
+:doc:`OpenCLSupport`).
+
 OpenCL Extensions
 -
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bc84f89 - [OpenCL][Docs] Fixed cross-section reference in OpenCLSupport

2021-01-15 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-01-15T17:20:13Z
New Revision: bc84f89c71ab62d510973f64f022bee31e53af96

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

LOG: [OpenCL][Docs] Fixed cross-section reference in OpenCLSupport

Tags: #clang

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 7e5bb41f7dbc..5be7e91adcaf 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -37,7 +37,7 @@ Clang implements language version 1.0 published in `the 
official
 release of C++ for OpenCL Documentation
 
`_.
 
-Limited support of experimental C++ libraries is described in the 
`experimental features `.
+Limited support of experimental C++ libraries is described in the 
:ref:`experimental features `.
 
 Bugzilla bugs for this functionality are typically prefixed
 with '[C++4OpenCL]' - click `here



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d1862a1 - [OpenCL][Docs] Fixed malformed table in OpenCLSupport

2021-01-15 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-01-15T14:27:26Z
New Revision: d1862a16310379179a40b309a9721318ae7e3254

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

LOG: [OpenCL][Docs] Fixed malformed table in OpenCLSupport

 Tags: #clang

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 9c17bd8f2692..7e5bb41f7dbc 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -67,40 +67,39 @@ OpenCL 3.0 Implementation Status
 The following table provides an overview of features in OpenCL C 3.0 and their
 implementation status. 
 
-+--+--+--+---
+
-| Category | Feature   
   | Status   | Reviews 
  |
-+==+==+==+===
+
-| Command line interface   | New value for ``-cl-std`` flag
   | :good:`done` | https://reviews.llvm.org/D88300 
  |
-+--+--+--+---
+
-| Predefined macros| New version macro 
   | :good:`done` | https://reviews.llvm.org/D88300 
  |
-+--+--+--+---
+
-| Predefined macros| Feature macros
   | :part:`worked on`| https://reviews.llvm.org/D89869 
  |
-+--+--+--+---
+
-| Feature optionality  | Generic address space 
   | :none:`unclaimed`| 
  |
-+--+--+--+---
+
-| Feature optionality  | Builtin function overloads with generic 
address space| :part:`worked on`| https://reviews.llvm.o
rg/D92004   |
-
-+--+--+--+---
+
-| Feature optionality  | Program scope variables in global memory  
   | :none:`unclaimed`| 
  |
-+--+--+--+---
+
-| Feature optionality  | 3D image writes including builtin functions   
   | :none:`unclaimed`| 
  |
-+--+--+--+---
+
-| Feature optionality  | read_write images including builtin functions 
   | :none:`unclaimed`| 
  |
-+--+--+--+---
+
-| Feature optionality  | C11 atomics memory scopes, ordering and 
builtin function | :part:`worked on`| https://reviews.llvm.o
rg/D92004 (functions only)  |

[clang] adb77a7 - [OpenCL] Improve online documentation.

2021-01-14 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-01-14T14:56:10Z
New Revision: adb77a7456920a46908c7e20b2d3008789274975

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

LOG: [OpenCL] Improve online documentation.

Update UsersManual and OpenCLSupport pages to reflect
recent functionality i.e. SPIR-V generation,
C++ for OpenCL, OpenCL 3.0 development plans.

Tags: #clang

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index b00a9ef41064..9c17bd8f2692 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -17,34 +17,92 @@
 OpenCL Support
 ==
 
-Clang fully supports all OpenCL C versions from 1.1 to 2.0.
+Clang has complete support of OpenCL C versions from 1.0 to 2.0.
 
-Please refer to `Bugzilla
-`__
-for the most up to date bug reports.
+Clang also supports :ref:`the C++ for OpenCL kernel language 
`.
 
+There is an ongoing work to support :ref:`OpenCL 3.0 `.
+
+There are also other :ref:`new and experimental features ` 
available.
+
+For general issues and bugs with OpenCL in clang refer to `Bugzilla
+`__.
+
+.. _cxx_for_opencl_impl:
 
 C++ for OpenCL Implementation Status
 
 
-Bugzilla bugs for this functionality are typically prefixed
-with '[C++]'.
+Clang implements language version 1.0 published in `the official
+release of C++ for OpenCL Documentation
+`_.
 
-Differences to OpenCL C

+Limited support of experimental C++ libraries is described in the 
`experimental features `.
+
+Bugzilla bugs for this functionality are typically prefixed
+with '[C++4OpenCL]' - click `here
+`_
+to view the full bug list.
 
-TODO!
 
 Missing features or with limited support
 
 
-- Use of ObjC blocks is disabled.
-
-- Global destructor invocation is not generated correctly.
-
-- Initialization of objects in `__constant` address spaces is not guaranteed 
to work.
-
-- `addrspace_cast` operator is not supported.
+- Use of ObjC blocks is disabled and therefore the ``enqueue_kernel`` builtin
+  function is not supported currently. It is expected that if support for this
+  feature is added in the future, it will utilize C++ lambdas instead of ObjC
+  blocks.
+
+- IR generation for global destructors is incomplete (See:
+  `PR48047 `_).
+
+- There is no distinct file extension for sources that are to be compiled
+  in C++ for OpenCL mode (See: `PR48097 `_)
+
+.. _opencl_300:
+
+OpenCL 3.0 Implementation Status
+
+
+The following table provides an overview of features in OpenCL C 3.0 and their
+implementation status. 
+
++--+--+--+---
+
+| Category | Feature   
   | Status   | Reviews 
  |
++==+==+==+===
+
+| Command line interface   | New value for ``-cl-std`` flag
   | :good:`done` | https://reviews.llvm.org/D88300 
  |
++--+--+--+---
+
+| Predefined macros| New version macro 
   | :good:`done` | https://reviews.llvm.org/D88300 
  |
++--+--+--+---
+
+| Predefined macros| Feature macros
   | :part:`worked on`| https://reviews.llvm.o

[clang] 0ef2b68 - [OpenCL] Documentation for experimental C++ libs

2021-01-08 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-01-08T13:45:59Z
New Revision: 0ef2b68ff063164a83a37a2a363196d51b76ed8d

URL: 
https://github.com/llvm/llvm-project/commit/0ef2b68ff063164a83a37a2a363196d51b76ed8d
DIFF: 
https://github.com/llvm/llvm-project/commit/0ef2b68ff063164a83a37a2a363196d51b76ed8d.diff

LOG: [OpenCL] Documentation for experimental C++ libs

Started a new doc section about the OpenCL experimental
features and described ongoing work on C++ libraries
e.g. type traits.

Tags: #clang

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 62ba890c3a95..b00a9ef41064 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -20,7 +20,7 @@ OpenCL Support
 Clang fully supports all OpenCL C versions from 1.1 to 2.0.
 
 Please refer to `Bugzilla
-`_
+`__
 for the most up to date bug reports.
 
 
@@ -45,3 +45,57 @@ Missing features or with limited support
 - Initialization of objects in `__constant` address spaces is not guaranteed 
to work.
 
 - `addrspace_cast` operator is not supported.
+
+Experimental features
+=
+
+Clang provides the following new WIP features for the developers to experiment
+and provide early feedback or contribute with further improvements.
+Feel free to contact us on `cfe-dev
+`_ or via `Bugzilla
+`__.
+
+C++ libraries for OpenCL
+
+
+There is ongoing work to support C++ standard libraries from `LLVM's libcxx
+`_ in OpenCL kernel code using C++ for OpenCL mode.
+
+It is currently possible to include `type_traits` from C++17 in the kernel
+sources when the following clang extensions are enabled
+``__cl_clang_function_pointers`` and ``__cl_clang_variadic_functions``,
+see :doc:`LanguageExtensions` for more details. The use of non-conformant
+features enabled by the extensions does not expose non-conformant behavior
+beyond the compilation i.e. does not get generated in IR or binary.
+The extension only appear in metaprogramming
+mechanism to identify or verify the properties of types. This allows to provide
+the full C++ functionality without a loss of portability. To avoid unsafe use
+of the extensions it is recommended that the extensions are disabled directly
+after the header include.
+
+**Example of Use**:
+
+The example of kernel code with `type_traits` is illustrated here.
+
+.. code-block:: c++
+
+  #pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
+  #pragma OPENCL EXTENSION __cl_clang_variadic_functions : enable
+  #include 
+  #pragma OPENCL EXTENSION __cl_clang_function_pointers : disable
+  #pragma OPENCL EXTENSION __cl_clang_variadic_functions : disable
+
+  using sint_type = std::make_signed::type;
+
+  __kernel void foo() {
+static_assert(!std::is_same::value);
+  }
+
+The possible clang invocation to compile the example is as follows:
+
+   .. code-block:: console
+
+ $ clang -cl-std=clc++  -I/include test.cl
+
+Note that `type_traits` is a header only library and therefore no extra
+linking step against the standard libraries is required.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0e874fc - [OpenCL] Add clang extension for variadic functions.

2021-01-06 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-01-06T20:39:57Z
New Revision: 0e874fc014be818a9c6782729f2c8e8273a7a906

URL: 
https://github.com/llvm/llvm-project/commit/0e874fc014be818a9c6782729f2c8e8273a7a906
DIFF: 
https://github.com/llvm/llvm-project/commit/0e874fc014be818a9c6782729f2c8e8273a7a906.diff

LOG: [OpenCL] Add clang extension for variadic functions.

With the internal clang extension '__cl_clang_variadic_functions'
variadic functions are accepted by the frontend.

This is not a fully supported vendor/Khronos extension
as it can only be used on targets with variadic prototype
support or in metaprogramming to represent functions with
generic prototype without calling such functions in the
kernel code.

Tags: #clang

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/OpenCLExtensions.def
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Sema/SemaType.cpp
clang/test/Misc/amdgcn.languageOptsOpenCL.cl
clang/test/Misc/nvptx.languageOptsOpenCL.cl
clang/test/Misc/r600.languageOptsOpenCL.cl
clang/test/SemaOpenCL/extension-version.cl
clang/test/SemaOpenCL/func.cl

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index fd011b101b6e..0c01a2bbc52b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1773,6 +1773,31 @@ correctly in any circumstances. It can be used if:
 void (*fp)(); // error - pointers to function are not allowed
   }
 
+``__cl_clang_variadic_functions``
+-
+
+With this extension it is possible to enable variadic arguments in functions
+using regular OpenCL extension pragma mechanism detailed in `the OpenCL
+Extension Specification, section 1.2
+`_.
+
+This is not conformant behavior and it can only be used portably when the
+functions with variadic prototypes do not get generated in binary e.g. the
+variadic prototype is used to spesify a function type with any number of
+arguments in metaprogramming algorithms in C++ for OpenCL.
+
+This extensions can also be used when the kernel code is intended for targets
+supporting the variadic arguments e.g. majority of CPU targets.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  #pragma OPENCL EXTENSION __cl_clang_variadic_functions : enable
+  void foo(int a, ...); // compiled - no diagnostic generated
+
+  #pragma OPENCL EXTENSION __cl_clang_variadic_functions : disable
+  void bar(int a, ...); // error - variadic prototype is not allowed
 
 Builtin Functions
 =

diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index 149594ed40b0..9353be1753b0 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -70,6 +70,7 @@ OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)
 // Clang Extensions.
 OPENCLEXT_INTERNAL(cl_clang_storage_class_specifiers, 100, ~0U)
 OPENCLEXT_INTERNAL(__cl_clang_function_pointers, 100, ~0U)
+OPENCLEXT_INTERNAL(__cl_clang_variadic_functions, 100, ~0U)
 
 // AMD OpenCL extensions
 OPENCLEXT_INTERNAL(cl_amd_media_ops, 100, ~0U)

diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 3fdbf320a329..fba1e4288ed1 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -286,6 +286,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
 auto  = getSupportedOpenCLOpts();
 Opts.support("cl_clang_storage_class_specifiers");
 Opts.support("__cl_clang_function_pointers");
+Opts.support("__cl_clang_variadic_functions");
 
 bool IsAMDGCN = isAMDGCN(getTriple());
 

diff  --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h
index 8e0da6554708..c4320e86e0db 100644
--- a/clang/lib/Basic/Targets/NVPTX.h
+++ b/clang/lib/Basic/Targets/NVPTX.h
@@ -129,6 +129,7 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public 
TargetInfo {
 auto  = getSupportedOpenCLOpts();
 Opts.support("cl_clang_storage_class_specifiers");
 Opts.support("__cl_clang_function_pointers");
+Opts.support("__cl_clang_variadic_functions");
 
 Opts.support("cl_khr_fp64");
 Opts.support("cl_khr_byte_addressable_store");

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 31018dc1d0e7..f51c616169f5 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5019,6 +5019,7 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState ,
 // (s6.9.e and s6.12.5 OpenCL v2.0) except for printf.
 // We also allow here any toolchain reserved identifiers.
 if (FTI.isVariadic &&
+ 

[clang] 4fde2b6 - [OpenCL] Add clang extension for function pointers.

2021-01-06 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-01-06T20:39:57Z
New Revision: 4fde2b6a0c080cb2a598383b5850038d67ca6833

URL: 
https://github.com/llvm/llvm-project/commit/4fde2b6a0c080cb2a598383b5850038d67ca6833
DIFF: 
https://github.com/llvm/llvm-project/commit/4fde2b6a0c080cb2a598383b5850038d67ca6833.diff

LOG: [OpenCL] Add clang extension for function pointers.

The new clang internal extension '__cl_clang_function_pointers'
allows use of function pointers and other features that have
the same functionality:
- Use of member function pointers;
- Unrestricted use of references to functions;
- Virtual member functions.

This not a vendor extension and therefore it doesn't require any
special target support. Exposing this functionality fully
will require vendor or Khronos extension.

Tags: #clang

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/OpenCLExtensions.def
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Misc/amdgcn.languageOptsOpenCL.cl
clang/test/Misc/nvptx.languageOptsOpenCL.cl
clang/test/Misc/r600.languageOptsOpenCL.cl
clang/test/Parser/opencl-cxx-virtual.cl
clang/test/SemaOpenCL/extension-version.cl
clang/test/SemaOpenCL/func.cl
clang/test/SemaOpenCLCXX/members.cl

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 6280c486ccbb..fd011b101b6e 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1722,6 +1722,58 @@ syntax to be used with ``std::complex`` with the same 
meaning.)
 For GCC compatibility, ``__builtin_complex(re, im)`` can also be used to
 construct a complex number from the given real and imaginary components.
 
+OpenCL Features
+===
+
+Clang supports internal OpenCL extensions documented below.
+
+``__cl_clang_function_pointers``
+
+
+With this extension it is possible to enable various language features that
+are relying on function pointers using regular OpenCL extension pragma
+mechanism detailed in `the OpenCL Extension Specification,
+section 1.2
+`_.
+
+In C++ for OpenCL this also enables:
+
+- Use of member function pointers;
+
+- Unrestricted use of references to functions;
+
+- Virtual member functions.
+
+Such functionality is not conformant and does not guarantee to compile
+correctly in any circumstances. It can be used if:
+
+- the kernel source does not contain call expressions to (member-) function
+  pointers, or virtual functions. For example this extension can be used in
+  metaprogramming algorithms to be able to specify/detect types generically.
+
+- the generated kernel binary does not contain indirect calls because they
+  are eliminated using compiler optimizations e.g. devirtualization. 
+
+- the selected target supports the function pointer like functionality e.g.
+  most CPU targets.
+
+**Example of Use**:
+
+.. code-block:: c++
+
+  #pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
+  void foo()
+  {
+void (*fp)(); // compiled - no diagnostic generated
+  }
+
+  #pragma OPENCL EXTENSION __cl_clang_function_pointers : disable
+  void bar()
+  {
+void (*fp)(); // error - pointers to function are not allowed
+  }
+
+
 Builtin Functions
 =
 

diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index 17d402f300f1..149594ed40b0 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -69,6 +69,7 @@ OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)
 
 // Clang Extensions.
 OPENCLEXT_INTERNAL(cl_clang_storage_class_specifiers, 100, ~0U)
+OPENCLEXT_INTERNAL(__cl_clang_function_pointers, 100, ~0U)
 
 // AMD OpenCL extensions
 OPENCLEXT_INTERNAL(cl_amd_media_ops, 100, ~0U)

diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 8b3f30ed70e9..3fdbf320a329 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -285,6 +285,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   void setSupportedOpenCLOpts() override {
 auto  = getSupportedOpenCLOpts();
 Opts.support("cl_clang_storage_class_specifiers");
+Opts.support("__cl_clang_function_pointers");
 
 bool IsAMDGCN = isAMDGCN(getTriple());
 

diff  --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h
index f8d0afdcceae..8e0da6554708 100644
--- a/clang/lib/Basic/Targets/NVPTX.h
+++ b/clang/lib/Basic/Targets/NVPTX.h
@@ -128,6 +128,7 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo 

[clang] 6f77029 - [OpenCL] Restrict pointer to member functions.

2021-01-05 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-01-05T13:32:18Z
New Revision: 6f770292a39f265c985623b1550aa50566b0

URL: 
https://github.com/llvm/llvm-project/commit/6f770292a39f265c985623b1550aa50566b0
DIFF: 
https://github.com/llvm/llvm-project/commit/6f770292a39f265c985623b1550aa50566b0.diff

LOG: [OpenCL] Restrict pointer to member functions.

Pointers to member functions are a special case
of function pointers and therefore have to be
disallowed.

Tags: #clang

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

Added: 
clang/test/SemaOpenCLCXX/members.cl

Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 949df53b40e0..73a6aea4fb7e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6749,8 +6749,8 @@ static bool diagnoseOpenCLTypes(Scope *S, Sema , 
Declarator ,
 
   // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
   QualType NR = R;
-  while (NR->isPointerType()) {
-if (NR->isFunctionPointerType()) {
+  while (NR->isPointerType() || NR->isMemberFunctionPointerType()) {
+if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType()) {
   Se.Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer);
   D.setInvalidType();
   return false;

diff  --git a/clang/test/SemaOpenCLCXX/members.cl 
b/clang/test/SemaOpenCLCXX/members.cl
new file mode 100644
index ..699619ccbe48
--- /dev/null
+++ b/clang/test/SemaOpenCLCXX/members.cl
@@ -0,0 +1,22 @@
+//RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -verify -fsyntax-only
+
+// Check that pointer to member functions are diagnosed
+struct C {
+  void f(int n);
+};
+
+typedef void (C::*p_t)(int);
+
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+
+template 
+void templ_test() {
+  typename remove_reference::type *ptr; //expected-error{{pointers to 
functions are not allowed}}
+}
+
+void test() {
+  void (C::*p)(int);   //expected-error{{pointers to functions are not 
allowed}}
+  p_t p1;  //expected-error{{pointers to functions are not 
allowed}}
+  templ_test(); //expected-note{{in instantiation of function 
template specialization}}
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a84599f - [OpenCL] Implement extended subgroups fully in headers.

2020-12-10 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-12-10T16:40:15Z
New Revision: a84599f177a67d4a8c1c30ccd96c99fa40af75f7

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

LOG: [OpenCL] Implement extended subgroups fully in headers.

Extended subgroups are library style extensions and therefore
they require no changes in the frontend. This commit:
1. Moves extension macro definitions to the internal headers.
2. Removes extension pragmas because they are not needed.

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/OpenCLExtensions.def
clang/lib/Headers/opencl-c-base.h
clang/test/Headers/opencl-c-header.cl
clang/test/SemaOpenCL/extension-version.cl

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index d67cb3ff019b..17d402f300f1 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -66,13 +66,6 @@ OPENCLEXT_INTERNAL(cl_khr_mipmap_image, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_subgroup_extended_types, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_subgroup_non_uniform_vote, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_subgroup_ballot, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_subgroup_non_uniform_arithmetic, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_subgroup_shuffle, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_subgroup_shuffle_relative, 200, ~0U)
-OPENCLEXT_INTERNAL(cl_khr_subgroup_clustered_reduce, 200, ~0U)
 
 // Clang Extensions.
 OPENCLEXT_INTERNAL(cl_clang_storage_class_specifiers, 100, ~0U)

diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 4c52ebed1709..e8dcd70377e5 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -9,6 +9,21 @@
 #ifndef _OPENCL_BASE_H_
 #define _OPENCL_BASE_H_
 
+// Define extension macros
+
+#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
+// For SPIR all extensions are supported.
+#if defined(__SPIR__)
+#define cl_khr_subgroup_extended_types 1
+#define cl_khr_subgroup_non_uniform_vote 1
+#define cl_khr_subgroup_ballot 1
+#define cl_khr_subgroup_non_uniform_arithmetic 1
+#define cl_khr_subgroup_shuffle 1
+#define cl_khr_subgroup_shuffle_relative 1
+#define cl_khr_subgroup_clustered_reduce 1
+#endif // defined(__SPIR__)
+#endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
+
 // built-in scalar data types:
 
 /**

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index 1b151ffdd16a..13a3b62481ec 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -84,7 +84,11 @@ void test_atomics(__generic volatile unsigned int* a) {
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 global atomic_int z = ATOMIC_VAR_INIT(99);
 #endif //__OPENCL_C_VERSION__
+// CHECK-MOD: Reading modules
+
+// Check that extension macros are defined correctly.
 
+// FIXME: this should not be defined for all targets
 // Verify that non-builtin cl_intel_planar_yuv extension is defined from
 // OpenCL 1.2 onwards.
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
@@ -94,4 +98,57 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #endif //__OPENCL_C_VERSION__
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
 
-// CHECK-MOD: Reading modules
+// For SPIR all extensions are supported.
+#if defined(__SPIR__)
+
+#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
+
+#if cl_khr_subgroup_extended_types != 1
+#error "Incorrectly defined cl_khr_subgroup_extended_types"
+#endif
+#if cl_khr_subgroup_non_uniform_vote != 1
+#error "Incorrectly defined cl_khr_subgroup_non_uniform_vote"
+#endif
+#if cl_khr_subgroup_ballot != 1
+#error "Incorrectly defined cl_khr_subgroup_ballot"
+#endif
+#if cl_khr_subgroup_non_uniform_arithmetic != 1
+#error "Incorrectly defined cl_khr_subgroup_non_uniform_arithmetic"
+#endif
+#if cl_khr_subgroup_shuffle != 1
+#error "Incorrectly defined cl_khr_subgroup_shuffle"
+#endif
+#if cl_khr_subgroup_shuffle_relative != 1
+#error "Incorrectly defined cl_khr_subgroup_shuffle_relative"
+#endif
+#if cl_khr_subgroup_clustered_reduce != 1
+#error "Incorrectly defined cl_khr_subgroup_clustered_reduce"
+#endif
+
+#else
+
+#ifdef cl_khr_subgroup_extended_types
+#error "Incorrect cl_khr_subgroup_extended_types define"
+#endif
+#ifdef cl_khr_subgroup_non_uniform_vote
+#error "Incorrect cl_khr_subgroup_non_uniform_vote define"
+#endif
+#ifdef cl_khr_subgroup_ballot
+#error 

[clang] 71d3b7e - [OpenCL] Add new compilation mode for OpenCL 3.0.

2020-10-09 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-10-09T15:28:38+01:00
New Revision: 71d3b7ec7b62d37dd3c8eb1a921f0b3e1ffdaa7f

URL: 
https://github.com/llvm/llvm-project/commit/71d3b7ec7b62d37dd3c8eb1a921f0b3e1ffdaa7f
DIFF: 
https://github.com/llvm/llvm-project/commit/71d3b7ec7b62d37dd3c8eb1a921f0b3e1ffdaa7f.diff

LOG: [OpenCL] Add new compilation mode for OpenCL 3.0.

Extended -cl-std/std flag with CL3.0 and added predefined version macros.

Patch by Anton Zabaznov (azabaznov)!

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/LangStandards.def
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Driver/autocomplete.c
clang/test/Driver/opencl.cl
clang/test/Driver/unknown-std.cl
clang/test/Frontend/stdlang.c
clang/test/Preprocessor/predefined-macros.c

Removed: 




diff  --git a/clang/include/clang/Basic/LangStandards.def 
b/clang/include/clang/Basic/LangStandards.def
index b09568e8b3e8..7b915c312746 100644
--- a/clang/include/clang/Basic/LangStandards.def
+++ b/clang/include/clang/Basic/LangStandards.def
@@ -167,6 +167,9 @@ LANGSTANDARD(opencl12, "cl1.2",
 LANGSTANDARD(opencl20, "cl2.0",
  OpenCL, "OpenCL 2.0",
  LineComment | C99 | Digraphs | HexFloat | OpenCL)
+LANGSTANDARD(opencl30, "cl3.0",
+ OpenCL, "OpenCL 3.0",
+ LineComment | C99 | Digraphs | HexFloat | OpenCL)
 LANGSTANDARD(openclcpp, "clc++",
  OpenCL, "C++ for OpenCL",
  LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 
|
@@ -176,6 +179,7 @@ LANGSTANDARD_ALIAS_DEPR(opencl10, "CL")
 LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1")
 LANGSTANDARD_ALIAS_DEPR(opencl12, "CL1.2")
 LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0")
+LANGSTANDARD_ALIAS_DEPR(opencl30, "CL3.0")
 LANGSTANDARD_ALIAS_DEPR(openclcpp, "CLC++")
 
 // CUDA

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9170a33b3155..8e0343710d68 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -573,7 +573,7 @@ def cl_mad_enable : Flag<["-"], "cl-mad-enable">, 
Group, Flags<[CC
 def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Allow use of less precise no signed zeros 
computations in the generated binary.">;
 def cl_std_EQ : Joined<["-"], "cl-std=">, Group, 
Flags<[CC1Option]>,
-  HelpText<"OpenCL language standard to compile for.">, 
Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,clc++,CLC++">;
+  HelpText<"OpenCL language standard to compile for.">, 
Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,cl3.0,CL3.0,clc++,CLC++">;
 def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, 
Group,
   HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;
 def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], 
"cl-fp32-correctly-rounded-divide-sqrt">, Group, 
Flags<[CC1Option]>,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1df92b086986..77ecbbd093e5 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2368,6 +2368,8 @@ void CompilerInvocation::setLangDefaults(LangOptions 
, InputKind IK,
 Opts.OpenCLVersion = 120;
   else if (LangStd == LangStandard::lang_opencl20)
 Opts.OpenCLVersion = 200;
+  else if (LangStd == LangStandard::lang_opencl30)
+Opts.OpenCLVersion = 300;
   else if (LangStd == LangStandard::lang_openclcpp)
 Opts.OpenCLCPlusPlusVersion = 100;
 
@@ -2574,6 +2576,7 @@ static void ParseLangArgs(LangOptions , ArgList 
, InputKind IK,
 .Cases("cl1.1", "CL1.1", LangStandard::lang_opencl11)
 .Cases("cl1.2", "CL1.2", LangStandard::lang_opencl12)
 .Cases("cl2.0", "CL2.0", LangStandard::lang_opencl20)
+.Cases("cl3.0", "CL3.0", LangStandard::lang_opencl30)
 .Cases("clc++", "CLC++", LangStandard::lang_openclcpp)
 .Default(LangStandard::lang_unspecified);
 

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 6eef1e2376f6..08907fe2469c 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -445,6 +445,9 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo ,
   case 200:
 Builder.defineMacro("__OPENCL_C_VERSION__", "200");
 break;
+  case 300:
+Builder.defineMacro("__OPENCL_C_VERSION__", "300");
+break;
   default:
 llvm_unreachable("Unsupported OpenCL version");
   }
@@ -453,6 +456,7 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo ,
 Builder.defineMacro("CL_VERSION_1_1", "110");
 Builder.defineMacro("CL_VERSION_1_2", 

[clang] 3c8a4ee - [OpenCL] Remove warning for variadic macros in C++ for OpenCL.

2020-08-12 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-08-12T16:17:54+01:00
New Revision: 3c8a4ee0764cafb2ba204c7cb7d8b37e6adf72a8

URL: 
https://github.com/llvm/llvm-project/commit/3c8a4ee0764cafb2ba204c7cb7d8b37e6adf72a8
DIFF: 
https://github.com/llvm/llvm-project/commit/3c8a4ee0764cafb2ba204c7cb7d8b37e6adf72a8.diff

LOG: [OpenCL] Remove warning for variadic macros in C++ for OpenCL.

Patch by Ole Strohm (olestrohm)!

Tags: #clang

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

Added: 


Modified: 
clang/lib/Lex/PPDirectives.cpp
clang/test/Preprocessor/macro_variadic.cl

Removed: 




diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 053ef1d2dd18..e4b901a950ae 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2397,7 +2397,7 @@ bool Preprocessor::ReadMacroParameterList(MacroInfo *MI, 
Token ) {
  diag::ext_variadic_macro);
 
   // OpenCL v1.2 s6.9.e: variadic macros are not supported.
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL && !LangOpts.OpenCLCPlusPlus) {
 Diag(Tok, diag::ext_pp_opencl_variadic_macros);
   }
 

diff  --git a/clang/test/Preprocessor/macro_variadic.cl 
b/clang/test/Preprocessor/macro_variadic.cl
index cc9458da558e..e58896487121 100644
--- a/clang/test/Preprocessor/macro_variadic.cl
+++ b/clang/test/Preprocessor/macro_variadic.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify %s -cl-std=CL1.2
 // RUN: %clang_cc1 -verify %s -pedantic -DPEDANTIC -cl-std=CL1.2
+// RUN: %clang_cc1 -verify %s -cl-std=CLC++
+// RUN: %clang_cc1 -verify %s -pedantic -cl-std=CLC++
 
 
 #define NO_VAR_FUNC(...)  5
@@ -15,6 +17,11 @@ int printf(__constant const char *st, ...);
 
 void foo() {
   NO_VAR_FUNC(1, 2, 3);
-  VAR_FUNC(1, 2, 3); //expected-error{{implicit declaration of function 'func' 
is invalid in OpenCL}}
+  VAR_FUNC(1, 2, 3);
+#if !__OPENCL_CPP_VERSION__
+// expected-error@-2{{implicit declaration of function 'func' is invalid in 
OpenCL}}
+#else
+// expected-error@-4{{use of undeclared identifier 'func'}}
+#endif
   VAR_PRINTF("%i", 1);
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 92fa91b - [OpenCL] Fixed missing address space for templated copy constructor.

2020-07-27 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-07-27T15:18:49+01:00
New Revision: 92fa91bb402921a5705507c38f583e9b8e9d84e4

URL: 
https://github.com/llvm/llvm-project/commit/92fa91bb402921a5705507c38f583e9b8e9d84e4
DIFF: 
https://github.com/llvm/llvm-project/commit/92fa91bb402921a5705507c38f583e9b8e9d84e4.diff

LOG: [OpenCL] Fixed missing address space for templated copy constructor.

Added missing address space for the parameter of copy ctor created
for templated constructor with an R-value reference.

Patch by Ole Strohm (olestrohm)!

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaOpenCLCXX/address-space-templates.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 52062e9a5039..8e7b4e1655ea 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3815,8 +3815,11 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
 //   If P is a forwarding reference and the argument is an lvalue, the type
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
-Arg->isLValue())
+Arg->isLValue()) {
+  if (S.getLangOpts().OpenCL)
+ArgType = S.Context.getAddrSpaceQualType(ArgType, 
LangAS::opencl_generic);
   ArgType = S.Context.getLValueReferenceType(ArgType);
+}
   } else {
 // C++ [temp.deduct.call]p2:
 //   If P is not a reference type:

diff  --git a/clang/test/SemaOpenCLCXX/address-space-templates.cl 
b/clang/test/SemaOpenCLCXX/address-space-templates.cl
index 6b304d2fdda4..be187de5684b 100644
--- a/clang/test/SemaOpenCLCXX/address-space-templates.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-templates.cl
@@ -22,10 +22,28 @@ void foo3() {
   __private T ii; // expected-error{{conflicting address space qualifiers are 
provided between types '__private T' and '__global int'}}
 }
 
+template  struct remove_reference { typedef _Tp type; };
+template  struct remove_reference<_Tp &>  { typedef _Tp type; };
+template  struct as_pointer {
+typedef typename remove_reference<_Tp>::type* type;
+};
+
+struct rep {
+  // CHECK |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep 
&__private) __generic'
+  template::type>
+  rep(U&& v) {}
+};
+
+struct rep_outer : private rep {
+  rep_outer()
+: rep(0) {}
+};
+
 void bar() {
   S sintgl; // expected-note{{in instantiation of template 
class 'S' requested here}}
 
   foo1<__local int>(1); // expected-error{{no matching function for call to 
'foo1'}}
   foo2<__global int>(0);
   foo3<__global int>(); // expected-note{{in instantiation of function 
template specialization 'foo3<__global int>' requested here}}
+  rep_outer r;
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6050c15 - [OpenCL] Defer addr space deduction for dependent type.

2020-07-13 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-07-13T11:44:38+01:00
New Revision: 6050c156ab4f13a3c54ca6ec297a72ece95966d7

URL: 
https://github.com/llvm/llvm-project/commit/6050c156ab4f13a3c54ca6ec297a72ece95966d7
DIFF: 
https://github.com/llvm/llvm-project/commit/6050c156ab4f13a3c54ca6ec297a72ece95966d7.diff

LOG: [OpenCL] Defer addr space deduction for dependent type.

This patch removes deduction of address spaces in parsing
for types that depend on template parameter even if an
address space is already known. Deducing it early interferes
with template instantiation/specialization logic that uses
source address space where address space is not present.

Address space deduction for templates is therefore fully
moved to the template instantiation/specialization phase.

Patch by Ole Strohm (olestrohm)!

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaOpenCLCXX/address-space-deduction.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f5e375134c29..3e2b61ae8cdf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6290,6 +6290,8 @@ bool Sema::inferObjCARCLifetime(ValueDecl *decl) {
 void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
   if (Decl->getType().hasAddressSpace())
 return;
+  if (Decl->getType()->isDependentType())
+return;
   if (VarDecl *Var = dyn_cast(Decl)) {
 QualType Type = Var->getType();
 if (Type->isSamplerT() || Type->isVoidType())
@@ -7859,6 +7861,7 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
 if (NewVD->isFileVarDecl() || NewVD->isStaticLocal() ||
 NewVD->hasExternalStorage()) {
   if (!T->isSamplerT() &&
+  !T->isDependentType() &&
   !(T.getAddressSpace() == LangAS::opencl_constant ||
 (T.getAddressSpace() == LangAS::opencl_global &&
  (getLangOpts().OpenCLVersion == 200 ||

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 85adc4ef2dbd..2efb7acb9724 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3625,6 +3625,9 @@ Decl 
*TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
   if (InsertPos)
 VarTemplate->AddSpecialization(Var, InsertPos);
 
+  if (SemaRef.getLangOpts().OpenCL)
+SemaRef.deduceOpenCLAddressSpace(Var);
+
   // Substitute the nested name specifier, if any.
   if (SubstQualifier(D, Var))
 return nullptr;
@@ -4895,6 +4898,9 @@ VarTemplateSpecializationDecl 
*Sema::CompleteVarTemplateSpecializationDecl(
   // Instantiate the initializer.
   InstantiateVariableInitializer(VarSpec, PatternDecl, TemplateArgs);
 
+  if (getLangOpts().OpenCL)
+deduceOpenCLAddressSpace(VarSpec);
+
   return VarSpec;
 }
 

diff  --git a/clang/test/SemaOpenCLCXX/address-space-deduction.cl 
b/clang/test/SemaOpenCLCXX/address-space-deduction.cl
index 6a81a8b2d7c7..ddfdb6da4347 100644
--- a/clang/test/SemaOpenCLCXX/address-space-deduction.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -5,6 +5,11 @@
 //CHECK: |-VarDecl {{.*}} foo 'const __global int'
 constexpr int foo = 0;
 
+//CHECK: |-VarDecl {{.*}} foo1 'T' cinit
+//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global 
long':'__global long' cinit
+template 
+T foo1 = 0;
+
 class c {
 public:
   //CHECK: `-VarDecl {{.*}} foo2 'const __global int'
@@ -30,7 +35,7 @@ struct c2 {
 
 template 
 struct x1 {
-//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &__private){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &){{( 
__attribute__.*)?}} __generic'
 //CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic 
x1 &__private){{( __attribute__.*)?}} __generic'
   x1& operator=(const x1& xx) {
 y = xx.y;
@@ -41,7 +46,7 @@ struct x1 {
 
 template 
 struct x2 {
-//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *__private){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *){{( __attribute__.*)?}} 
__generic'
 //CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *__private){{( 
__attribute__.*)?}} __generic'
   void foo(x1* xx) {
 m[0] = *xx;
@@ -57,10 +62,10 @@ void bar(__global x1 *xx, __global x2 *bar) {
 template 
 class x3 : public T {
 public:
-  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( 
__attribute__.*)?}} __generic'
+  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( 
__attribute__.*)?}} __generic'
   x3(const x3 );
 };
-//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( 
__attribute__.*)?}} __generic'
+//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( 
__attribute__.*)?}} __generic'
 template 
 x3::x3(const x3 

[clang] 8c8a2fd - [OpenCL] Fixed typo for ctor stub name in UsersManual

2020-07-10 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-07-10T19:04:49+01:00
New Revision: 8c8a2fd1f015525d048444610a6e27c66aa96293

URL: 
https://github.com/llvm/llvm-project/commit/8c8a2fd1f015525d048444610a6e27c66aa96293
DIFF: 
https://github.com/llvm/llvm-project/commit/8c8a2fd1f015525d048444610a6e27c66aa96293.diff

LOG: [OpenCL] Fixed typo for ctor stub name in UsersManual

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 4b4e28a8b65c..8615a77596b4 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3132,7 +3132,7 @@ Global objects must be constructed before the first 
kernel using the global obje
 is executed and destroyed just after the last kernel using the program objects 
is
 executed. In OpenCL v2.0 drivers there is no specific API for invoking global
 constructors. However, an easy workaround would be to enqueue a constructor
-initialization kernel that has a name ``@_GLOBAL__sub_I_``.
+initialization kernel that has a name ``_GLOBAL__sub_I_``.
 This kernel is only present if there are any global objects to be initialized 
in
 the compiled binary. One way to check this is by passing 
``CL_PROGRAM_KERNEL_NAMES``
 to ``clGetProgramInfo`` (OpenCL v2.0 s5.8.7).
@@ -3148,7 +3148,7 @@ before running any kernels in which the objects are used.
  clang -cl-std=clc++ test.cl
 
 If there are any global objects to be initialized, the final binary will 
contain
-the ``@_GLOBAL__sub_I_test.cl`` kernel to be enqueued.
+the ``_GLOBAL__sub_I_test.cl`` kernel to be enqueued.
 
 Global destructors can not be invoked in OpenCL v2.0 drivers. However, all 
memory used
 for program scope objects is released on ``clReleaseProgram``.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4a4402f - [OpenCL] Add cl_khr_extended_subgroup extensions.

2020-06-04 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-06-04T13:29:30+01:00
New Revision: 4a4402f0d72167477a6252e4c3daf5089ebc8f9a

URL: 
https://github.com/llvm/llvm-project/commit/4a4402f0d72167477a6252e4c3daf5089ebc8f9a
DIFF: 
https://github.com/llvm/llvm-project/commit/4a4402f0d72167477a6252e4c3daf5089ebc8f9a.diff

LOG: [OpenCL] Add cl_khr_extended_subgroup extensions.

Added extensions and their function declarations into
the standard header.

Patch by Piotr Fusik!

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/OpenCLExtensions.def
clang/lib/Headers/opencl-c.h
clang/test/SemaOpenCL/extension-version.cl

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index 517481584313..1ae36b32fb0a 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -74,6 +74,13 @@ OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_terminate_context, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_extended_types, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_non_uniform_vote, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_ballot, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_non_uniform_arithmetic, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_shuffle, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_shuffle_relative, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_subgroup_clustered_reduce, 200, ~0U)
 
 // Clang Extensions.
 OPENCLEXT_INTERNAL(cl_clang_storage_class_specifiers, 100, ~0U)

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 6ac9f92d23a2..66e18bdd47bb 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15460,6 +15460,674 @@ double  __ovld __conv 
sub_group_scan_inclusive_max(double x);
 
 #endif //cl_khr_subgroups cl_intel_subgroups
 
+#if defined(cl_khr_subgroup_extended_types)
+char __ovld __conv sub_group_broadcast( char value, uint index );
+char2 __ovld __conv sub_group_broadcast( char2 value, uint index );
+char3 __ovld __conv sub_group_broadcast( char3 value, uint index );
+char4 __ovld __conv sub_group_broadcast( char4 value, uint index );
+char8 __ovld __conv sub_group_broadcast( char8 value, uint index );
+char16 __ovld __conv sub_group_broadcast( char16 value, uint index );
+
+uchar __ovld __conv sub_group_broadcast( uchar value, uint index );
+uchar2 __ovld __conv sub_group_broadcast( uchar2 value, uint index );
+uchar3 __ovld __conv sub_group_broadcast( uchar3 value, uint index );
+uchar4 __ovld __conv sub_group_broadcast( uchar4 value, uint index );
+uchar8 __ovld __conv sub_group_broadcast( uchar8 value, uint index );
+uchar16 __ovld __conv sub_group_broadcast( uchar16 value, uint index );
+
+short __ovld __conv sub_group_broadcast( short value, uint index );
+short2 __ovld __conv sub_group_broadcast( short2 value, uint index );
+short3 __ovld __conv sub_group_broadcast( short3 value, uint index );
+short4 __ovld __conv sub_group_broadcast( short4 value, uint index );
+short8 __ovld __conv sub_group_broadcast( short8 value, uint index );
+short16 __ovld __conv sub_group_broadcast( short16 value, uint index );
+
+ushort __ovld __conv sub_group_broadcast( ushort value, uint index );
+ushort2 __ovld __conv sub_group_broadcast( ushort2 value, uint index );
+ushort3 __ovld __conv sub_group_broadcast( ushort3 value, uint index );
+ushort4 __ovld __conv sub_group_broadcast( ushort4 value, uint index );
+ushort8 __ovld __conv sub_group_broadcast( ushort8 value, uint index );
+ushort16 __ovld __conv sub_group_broadcast( ushort16 value, uint index );
+
+// scalar int broadcast is part of cl_khr_subgroups
+int2 __ovld __conv sub_group_broadcast( int2 value, uint index );
+int3 __ovld __conv sub_group_broadcast( int3 value, uint index );
+int4 __ovld __conv sub_group_broadcast( int4 value, uint index );
+int8 __ovld __conv sub_group_broadcast( int8 value, uint index );
+int16 __ovld __conv sub_group_broadcast( int16 value, uint index );
+
+// scalar uint broadcast is part of cl_khr_subgroups
+uint2 __ovld __conv sub_group_broadcast( uint2 value, uint index );
+uint3 __ovld __conv sub_group_broadcast( uint3 value, uint index );
+uint4 __ovld __conv sub_group_broadcast( uint4 value, uint index );
+uint8 __ovld __conv sub_group_broadcast( uint8 value, uint index );
+uint16 __ovld __conv sub_group_broadcast( uint16 value, uint index );
+
+// scalar long broadcast is part of cl_khr_subgroups
+long2 __ovld __conv sub_group_broadcast( long2 value, uint index );
+long3 __ovld __conv sub_group_broadcast( long3 value, uint index );
+long4 __ovld __conv sub_group_broadcast( long4 value, uint index );
+long8 __ovld __conv sub_group_broadcast( long8 value, uint 

[clang] a6a237f - [OpenCL] Added addrspace_cast operator in C++ mode.

2020-05-18 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-05-18T12:07:54+01:00
New Revision: a6a237f2046ad8993db30481c8b61aeb2f73a5ad

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

LOG: [OpenCL] Added addrspace_cast operator in C++ mode.

This operator is intended for casting between
pointers to objects in different address spaces
and follows similar logic as const_cast in C++.

Tags: #clang

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

Added: 
clang/test/CodeGenOpenCLCXX/addrspace_cast.cl
clang/test/Index/cxx.cl
clang/test/SemaOpenCLCXX/addrspace_cast.cl
clang/test/SemaOpenCLCXX/addrspace_cast_ast_dump.cl

Modified: 
clang/include/clang-c/Index.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 8e367b617bd3..3a8a1fdcae0c 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2052,58 +2052,62 @@ enum CXCursorKind {
*/
   CXCursor_CXXFunctionalCastExpr = 128,
 
+  /** OpenCL's addrspace_cast<> expression.
+   */
+  CXCursor_CXXAddrspaceCastExpr = 129,
+
   /** A C++ typeid expression (C++ [expr.typeid]).
*/
-  CXCursor_CXXTypeidExpr = 129,
+  CXCursor_CXXTypeidExpr = 130,
 
   /** [C++ 2.13.5] C++ Boolean Literal.
*/
-  CXCursor_CXXBoolLiteralExpr = 130,
+  CXCursor_CXXBoolLiteralExpr = 131,
 
   /** [C++0x 2.14.7] C++ Pointer Literal.
*/
-  CXCursor_CXXNullPtrLiteralExpr = 131,
+  CXCursor_CXXNullPtrLiteralExpr = 132,
 
   /** Represents the "this" expression in C++
*/
-  CXCursor_CXXThisExpr = 132,
+  CXCursor_CXXThisExpr = 133,
 
   /** [C++ 15] C++ Throw Expression.
*
* This handles 'throw' and 'throw' assignment-expression. When
* assignment-expression isn't present, Op will be null.
*/
-  CXCursor_CXXThrowExpr = 133,
+  CXCursor_CXXThrowExpr = 134,
 
   /** A new expression for memory allocation and constructor calls, e.g:
* "new CXXNewExpr(foo)".
*/
-  CXCursor_CXXNewExpr = 134,
+  CXCursor_CXXNewExpr = 135,
 
   /** A delete expression for memory deallocation and destructor calls,
* e.g. "delete[] pArray".
*/
-  CXCursor_CXXDeleteExpr = 135,
+  CXCursor_CXXDeleteExpr = 136,
 
   /** A unary expression. (noexcept, sizeof, or other traits)
*/
-  CXCursor_UnaryExpr = 136,
+  CXCursor_UnaryExpr = 137,
 
   /** An Objective-C string literal i.e. @"foo".
*/
-  CXCursor_ObjCStringLiteral = 137,
+  CXCursor_ObjCStringLiteral = 138,
 
   /** An Objective-C \@encode expression.
*/
-  CXCursor_ObjCEncodeExpr = 138,
+  CXCursor_ObjCEncodeExpr = 139,
 
   /** An Objective-C \@selector expression.
*/
-  CXCursor_ObjCSelectorExpr = 139,
+  CXCursor_ObjCSelectorExpr = 140,
 
   /** An Objective-C \@protocol expression.
*/
-  CXCursor_ObjCProtocolExpr = 140,
+  CXCursor_ObjCProtocolExpr = 141,
 
   /** An Objective-C "bridged" cast expression, which casts between
* Objective-C pointers and C pointers, transferring ownership in the 
process.
@@ -2112,7 +2116,7 @@ enum CXCursorKind {
*   NSString *str = (__bridge_transfer NSString *)CFCreateString();
* \endcode
*/
-  CXCursor_ObjCBridgedCastExpr = 141,
+  CXCursor_ObjCBridgedCastExpr = 142,
 
   /** Represents a C++0x pack expansion that produces a sequence of
* expressions.
@@ -2127,7 +2131,7 @@ enum CXCursorKind {
* }
* \endcode
*/
-  CXCursor_PackExpansionExpr = 142,
+  CXCursor_PackExpansionExpr = 143,
 
   /** Represents an expression that computes the length of a parameter
* pack.
@@ -2139,7 +2143,7 @@ enum CXCursorKind {
* };
* \endcode
*/
-  CXCursor_SizeOfPackExpr = 143,
+  CXCursor_SizeOfPackExpr = 144,
 
   /* Represents a C++ lambda expression that produces a local function

[clang] fe667e8 - [OpenCL] Fixed test for the cast operators.

2020-04-28 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-04-28T12:46:36+01:00
New Revision: fe667e8522a6be5f73b2aed1adf4ec92d0470695

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

LOG: [OpenCL] Fixed test for the cast operators.

The test had unused variable because it missed to cover
case with __constant address space. This change now
completes the testing fully.

Added: 


Modified: 
clang/test/SemaOpenCLCXX/address-space-castoperators.cl

Removed: 




diff  --git a/clang/test/SemaOpenCLCXX/address-space-castoperators.cl 
b/clang/test/SemaOpenCLCXX/address-space-castoperators.cl
index d61a9a72573c..7fd7f728fda3 100644
--- a/clang/test/SemaOpenCLCXX/address-space-castoperators.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-castoperators.cl
@@ -9,4 +9,9 @@ void nester_ptr() {
   gengen = static_cast(locgen); //expected-error{{static_cast from 
'__local int *__generic *' to '__generic int *__generic *' is not allowed}}
 // CHECK-NOT: AddressSpaceConversion
   gengen = reinterpret_cast(locgen); 
//expected-warning{{reinterpret_cast from '__local int *__generic *' to 
'__generic int *__generic *' changes address space of nested pointers}}
+
+  gengen = const_cast(congen); //expected-error{{const_cast from 
'__constant int *__generic *' to '__generic int *__generic *' is not allowed}}
+  gengen = static_cast(congen); //expected-error{{static_cast from 
'__constant int *__generic *' to '__generic int *__generic *' is not allowed}}
+// CHECK-NOT: AddressSpaceConversion
+  gengen = reinterpret_cast(congen); 
//expected-warning{{reinterpret_cast from '__constant int *__generic *' to 
'__generic int *__generic *' changes address space of nested pointers}}
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fa755d3 - [Sema][C++] Propagate conversion kind to specialize the diagnostics

2020-02-25 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-02-25T16:05:37Z
New Revision: fa755d3e71ed590ac5c62f0e1eff09435c9593fe

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

LOG: [Sema][C++] Propagate conversion kind to specialize the diagnostics

Compute and propagate conversion kind to diagnostics helper in C++
to provide more specific diagnostics about incorrect implicit
conversions in assignments, initializations, params, etc...

Duplicated some diagnostics as errors because C++ is more strict.

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CXX/conv/conv.fctptr/p1.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/except/except.handle/p16.cpp
clang/test/CXX/expr/p13.cpp
clang/test/CXX/temp/temp.spec/temp.expl.spec/p19.cpp
clang/test/CXX/temp/temp.spec/temp.explicit/p10.cpp
clang/test/CXX/temp/temp.spec/temp.explicit/p9.cpp
clang/test/OpenMP/allocate_allocator_messages.cpp
clang/test/Sema/block-call.c
clang/test/Sema/block-return.c
clang/test/Sema/callingconv-ms_abi.c
clang/test/Sema/callingconv-sysv_abi.c
clang/test/Sema/callingconv.c
clang/test/Sema/overloadable.c
clang/test/Sema/pass-object-size.c
clang/test/Sema/preserve-call-conv.c
clang/test/SemaCXX/addr-of-overloaded-function.cpp
clang/test/SemaCXX/decl-microsoft-call-conv.cpp
clang/test/SemaCXX/goto.cpp
clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
clang/test/SemaCXX/ms-property-error.cpp
clang/test/SemaObjC/arc.m
clang/test/SemaObjC/comptypes-legal.m
clang/test/SemaObjCXX/arc-type-conversion.mm
clang/test/SemaObjCXX/comptypes-1.mm
clang/test/SemaObjCXX/comptypes-7.mm
clang/test/SemaObjCXX/instantiate-expr.mm
clang/test/SemaObjCXX/instantiate-stmt.mm
clang/test/SemaObjCXX/noescape.mm
clang/test/SemaObjCXX/nullability-pragmas.mm
clang/test/SemaObjCXX/objc-container-subscripting.mm
clang/test/SemaObjCXX/parameterized_classes_subst.mm
clang/test/SemaObjCXX/property-invalid-type.mm
clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
clang/test/SemaOpenCL/address-spaces.cl
clang/test/SemaTemplate/extern-templates.cpp
clang/test/SemaTemplate/instantiate-member-class.cpp
clang/test/SemaTemplate/member-access-expr.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 60f2c777676d..91688cf99f9c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7367,6 +7367,21 @@ def warn_incompatible_qualified_id : Warning<
   "sending type to parameter of incompatible type}0,1"
   "|%
diff {casting $ to incompatible type $|"
   "casting type to incompatible type}0,1}2">;
+def err_incompatible_qualified_id : Error<
+  "%select{%
diff {assigning to $ from incompatible type $|"
+  "assigning to type from incompatible type}0,1"
+  "|%
diff {passing $ to parameter of incompatible type $|"
+  "passing type to parameter of incompatible type}0,1"
+  "|%
diff {returning $ from a function with incompatible result type $|"
+  "returning type from a function with incompatible result type}0,1"
+  "|%
diff {converting $ to incompatible type $|"
+  "converting type to incompatible type}0,1"
+  "|%
diff {initializing $ with an expression of incompatible type $|"
+  "initializing type with an expression of incompatible type}0,1"
+  "|%
diff {sending $ to parameter of incompatible type $|"
+  "sending type to parameter of incompatible type}0,1"
+  "|%
diff {casting $ to incompatible type $|"
+  "casting type to incompatible type}0,1}2">;
 def ext_typecheck_convert_pointer_int : ExtWarn<
   "incompatible pointer to integer conversion "
   "%select{%
diff {assigning to $ from $|assigning to 
diff erent types}0,1"
@@ -7385,6 +7400,23 @@ def ext_typecheck_convert_pointer_int : ExtWarn<
   "; remove *|"
   "; remove &}3">,
   InGroup;
+def err_typecheck_convert_pointer_int : Error<
+  "incompatible pointer to integer conversion "
+  "%select{%
diff {assigning to $ from $|assigning to 
diff erent types}0,1"
+  "|%
diff {passing $ to parameter of type $|"
+  "passing to parameter of 
diff erent type}0,1"
+  "|%
diff {returning $ from a function with result type $|"
+  "returning from function with 
diff erent return type}0,1"
+  "|%
diff {converting $ to type $|converting between types}0,1"
+  "|%
diff {initializing $ with an expression of type $|"
+  "initializing with expression of 
diff erent type}0,1"
+  "|%
diff {sending 

[clang] 6064f42 - [OpenCL] Restrict addr space conversions in nested pointers

2020-02-07 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-02-07T12:04:35Z
New Revision: 6064f426a18304e16b51cc79e74c9c2d55ef5a9c

URL: 
https://github.com/llvm/llvm-project/commit/6064f426a18304e16b51cc79e74c9c2d55ef5a9c
DIFF: 
https://github.com/llvm/llvm-project/commit/6064f426a18304e16b51cc79e74c9c2d55ef5a9c.diff

LOG: [OpenCL] Restrict addr space conversions in nested pointers

Address space conversion changes pointer representation.
This commit disallows such conversions when they are not
legal i.e. for the nested pointers even with compatible
address spaces. Because the address space conversion in
the nested levels can't be generated to modify the pointers
correctly. The behavior implemented is as follows:

- Any implicit conversions of nested pointers with different
  address spaces is rejected.
- Any conversion of address spaces in nested pointers in safe
  casts (e.g. const_cast or static_cast) is rejected.
- Conversion in low level C-style or reinterpret_cast is accepted
  but with a warning (this aligns with OpenCL C behavior).

Fixes PR39674

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

Added: 
clang/test/SemaOpenCLCXX/address-space-castoperators.cl

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
clang/test/SemaOpenCL/address-spaces.cl
clang/test/SemaOpenCLCXX/address-space-deduction.cl
clang/test/SemaOpenCLCXX/address-space-references.cl

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 504c9057107b..104a2a575481 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6760,6 +6760,10 @@ def err_bad_cxx_cast_scalar_to_vector_
diff erent_size : Error<
 def err_bad_cxx_cast_vector_to_vector_
diff erent_size : Error<
   "%select{||reinterpret_cast||C-style cast|}0 from vector %1 "
   "to vector %2 of 
diff erent size">;
+def warn_bad_cxx_cast_nested_pointer_addr_space : Warning<
+  "%select{reinterpret_cast|C-style cast}0 from %1 to %2 "
+  "changes address space of nested pointers">,
+  InGroup;
 def err_bad_lvalue_to_rvalue_cast : Error<
   "cannot cast from lvalue of type %1 to rvalue reference type %2; types are "
   "not compatible">;

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index a905ebc67305..7a8cbca1e3f1 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -2311,6 +2311,24 @@ static TryCastResult TryReinterpretCast(Sema , 
ExprResult ,
 return SuccessResult;
   }
 
+  // Diagnose address space conversion in nested pointers.
+  QualType DestPtee = DestType->getPointeeType().isNull()
+  ? DestType->getPointeeType()
+  : DestType->getPointeeType()->getPointeeType();
+  QualType SrcPtee = SrcType->getPointeeType().isNull()
+ ? SrcType->getPointeeType()
+ : SrcType->getPointeeType()->getPointeeType();
+  while (!DestPtee.isNull() && !SrcPtee.isNull()) {
+if (DestPtee.getAddressSpace() != SrcPtee.getAddressSpace()) {
+  Self.Diag(OpRange.getBegin(),
+diag::warn_bad_cxx_cast_nested_pointer_addr_space)
+  << CStyle << SrcType << DestType << SrcExpr.get()->getSourceRange();
+  break;
+}
+DestPtee = DestPtee->getPointeeType();
+SrcPtee = SrcPtee->getPointeeType();
+  }
+
   // C++ 5.2.10p7: A pointer to an object can be explicitly converted to
   //   a pointer to an object of 
diff erent type.
   // Void pointers are not specified, but supported by every compiler out 
there.

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 9b89bac0db39..858e7ae34a7f 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -3180,7 +3180,7 @@ static bool isNonTrivialObjCLifetimeConversion(Qualifiers 
FromQuals,
 /// FromType and \p ToType is permissible, given knowledge about whether every
 /// outer layer is const-qualified.
 static bool isQualificationConversionStep(QualType FromType, QualType ToType,
-  bool CStyle,
+  bool CStyle, bool IsTopLevel,
   bool ,
   bool ) {
   Qualifiers FromQuals = FromType.getQualifiers();
@@ -3217,11 +3217,15 @@ static bool isQualificationConversionStep(QualType 
FromType, QualType ToType,
   if (!CStyle && !ToQuals.compatiblyIncludes(FromQuals))
 return false;
 
-  // For a C-style cast, just require the address spaces to overlap.
-  // FIXME: Does "superset" also imply the representation of a pointer is the
-  // same? We're assuming that it does here and in 

[clang] e456165 - [OpenCL] Add link to C++ for OpenCL documentation

2020-01-03 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-01-03T12:01:03Z
New Revision: e456165f9fec9148566849f21bc4f7dda2fea034

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

LOG: [OpenCL] Add link to C++ for OpenCL documentation

Remove description of language mode from the language
extensions and add a link to pdf document.

Tags: #clang

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index d9a4862dbe80..b0f57202e079 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1631,285 +1631,6 @@ parameters of protocol-qualified type.
 Query the presence of this new mangling with
 ``__has_feature(objc_protocol_qualifier_mangling)``.
 
-
-OpenCL Features
-===
-
-C++ for OpenCL
---
-
-This functionality is built on top of OpenCL C v2.0 and C++17 enabling most of
-regular C++ features in OpenCL kernel code. Most functionality from OpenCL C
-is inherited. This section describes minor 
diff erences to OpenCL C and any
-limitations related to C++ support as well as interactions between OpenCL and
-C++ features that are not documented elsewhere.
-
-Restrictions to C++17
-^
-
-The following features are not supported:
-
-- Virtual functions
-- Exceptions
-- ``dynamic_cast`` operator
-- Non-placement ``new``/``delete`` operators
-- Standard C++ libraries. Currently there is no solution for alternative C++
-  libraries provided. Future release will feature library support.
-
-
-Interplay of OpenCL and C++ features
-
-
-Address space behavior
-""
-
-Address spaces are part of the type qualifiers; many rules are just inherited
-from the qualifier behavior documented in OpenCL C v2.0 s6.5 and Embedded C
-extension ISO/IEC JTC1 SC22 WG14 N1021 s3.1. Note that since the address space
-behavior in C++ is not documented formally, Clang extends the existing concept
-from C and OpenCL. For example conversion rules are extended from qualification
-conversion but the compatibility is determined using notation of sets and
-overlapping of address spaces from Embedded C (ISO/IEC JTC1 SC22 WG14 N1021
-s3.1.3). For OpenCL it means that implicit conversions are allowed from
-a named address space (except for ``__constant``) to ``__generic`` (OpenCL C
-v2.0 6.5.5). Reverse conversion is only allowed explicitly. The ``__constant``
-address space does not overlap with any other and therefore no valid conversion
-between ``__constant`` and other address spaces exists. Most of the rules
-follow this logic.
-
-**Casts**
-
-C-style casts follow OpenCL C v2.0 rules (s6.5.5). All cast operators
-permit conversion to ``__generic`` implicitly. However converting from
-``__generic`` to named address spaces can only be done using 
``addrspace_cast``.
-Note that conversions between ``__constant`` and any other address space
-are disallowed.
-
-.. _opencl_cpp_addrsp_deduction:
-
-**Deduction**
-
-Address spaces are not deduced for:
-
-- non-pointer/non-reference template parameters or any dependent types except
-  for template specializations.
-- non-pointer/non-reference class members except for static data members that 
are
-  deduced to ``__global`` address space.
-- non-pointer/non-reference alias declarations.
-- ``decltype`` expressions.
-
-.. code-block:: c++
-
-  template 
-  void foo() {
-T m; // address space of m will be known at template instantiation time.
-T * ptr; // ptr points to __generic address space object.
-T & ref = ...; // ref references an object in __generic address space.
-  };
-
-  template 
-  struct S {
-int i; // i has no address space
-static int ii; // ii is in global address space
-int * ptr; // ptr points to __generic address space int.
-int & ref = ...; // ref references int in __generic address space.
-  };
-
-  template 
-  void bar()
-  {
-S s; // s is in __private address space
-  }
-
-TODO: Add example for type alias and decltype!
-
-**References**
-
-Reference types can be qualified with an address space.
-
-.. code-block:: c++
-
-  __private int & ref = ...; // references int in __private address space
-
-By default references will refer to ``__generic`` address space objects, except
-for dependent types that are not template specializations
-(see :ref:`Deduction `). Address space 
compatibility
-checks are performed when references are bound to values. The logic follows the
-rules from address space pointer conversion (OpenCL v2.0 s6.5.5).
-
-**Default address space**
-
-All non-static member functions take an implicit object parameter 

[clang] 752220e - [OpenCL] Fixed printing of __private in AMDGPU test

2019-12-27 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2019-12-27T17:08:42Z
New Revision: 752220ea2664c814eb1eb046d755fe63ade9c32e

URL: 
https://github.com/llvm/llvm-project/commit/752220ea2664c814eb1eb046d755fe63ade9c32e
DIFF: 
https://github.com/llvm/llvm-project/commit/752220ea2664c814eb1eb046d755fe63ade9c32e.diff

LOG: [OpenCL] Fixed printing of __private in AMDGPU test

Tags: #clang

Added: 


Modified: 
clang/test/SemaOpenCL/numbered-address-space.cl

Removed: 




diff  --git a/clang/test/SemaOpenCL/numbered-address-space.cl 
b/clang/test/SemaOpenCL/numbered-address-space.cl
index 8a24b3ce979c..ab824ac531ff 100644
--- a/clang/test/SemaOpenCL/numbered-address-space.cl
+++ b/clang/test/SemaOpenCL/numbered-address-space.cl
@@ -11,7 +11,7 @@ void 
test_numeric_as_to_generic_explicit_cast(__attribute__((address_space(3)))
 
 void test_generic_to_numeric_as_implicit_cast() {
   generic int* generic_ptr = 0;
-  __attribute__((address_space(3))) int *as3_ptr = generic_ptr; // 
expected-error{{initializing '__attribute__((address_space(3))) int *' with an 
expression of type '__generic int *' changes address space of pointer}}
+  __attribute__((address_space(3))) int *as3_ptr = generic_ptr; // 
expected-error{{initializing '__attribute__((address_space(3))) int *__private' 
with an expression of type '__generic int *__private' changes address space of 
pointer}}
 }
 
 void test_generic_to_numeric_as_explicit_cast() {
@@ -26,6 +26,6 @@ void 
test_generic_as_to_builtin_parameter_explicit_cast_numeric(__attribute__((a
 
 void 
test_generic_as_to_builtin_parameterimplicit_cast_numeric(__attribute__((address_space(3)))
 int *as3_ptr, float src) {
   generic int* generic_ptr = as3_ptr;
-  volatile float result = __builtin_amdgcn_ds_fmaxf(generic_ptr, src, 0, 0, 
false); // expected-error {{passing '__generic int *' to parameter of type 
'__local float *' changes address space of pointer}}
+  volatile float result = __builtin_amdgcn_ds_fmaxf(generic_ptr, src, 0, 0, 
false); // expected-error {{passing '__generic int *__private' to parameter of 
type '__local float *' changes address space of pointer}}
 }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ed8dadb - [Sema] Improve diagnostic about addr spaces for overload candidates

2019-12-13 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2019-12-13T12:35:18Z
New Revision: ed8dadb37c7e1a7f4889d868ac9b19bfe7762237

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

LOG: [Sema] Improve diagnostic about addr spaces for overload candidates

Allow sending address spaces into diagnostics to simplify and improve
error reporting. Improved wording of diagnostics for address spaces
in overloading.

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/ASTDiagnostic.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/Diagnostic.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/address-space-references.cpp
clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
clang/test/SemaOpenCLCXX/address-space-lambda.cl
clang/test/SemaOpenCLCXX/address-space-of-this-class-scope.cl

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index caf2a3dd79a3..6d1d69bd87a2 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -553,6 +553,8 @@ class Qualifiers {
   std::string getAsString() const;
   std::string getAsString(const PrintingPolicy ) const;
 
+  static std::string getAddrSpaceAsString(LangAS AS);
+
   bool isEmptyWhenPrinted(const PrintingPolicy ) const;
   void print(raw_ostream , const PrintingPolicy ,
  bool appendSpaceIfNonEmpty = false) const;
@@ -6838,6 +6840,23 @@ inline const Type *Type::getPointeeOrArrayElementType() 
const {
 return type->getBaseElementTypeUnsafe();
   return type;
 }
+/// Insertion operator for diagnostics. This allows sending address spaces into
+/// a diagnostic with <<.
+inline const DiagnosticBuilder <<(const DiagnosticBuilder ,
+   LangAS AS) {
+  DB.AddTaggedVal(static_cast>(AS),
+  DiagnosticsEngine::ArgumentKind::ak_addrspace);
+  return DB;
+}
+
+/// Insertion operator for partial diagnostics. This allows sending adress
+/// spaces into a diagnostic with <<.
+inline const PartialDiagnostic <<(const PartialDiagnostic ,
+   LangAS AS) {
+  PD.AddTaggedVal(static_cast>(AS),
+  DiagnosticsEngine::ArgumentKind::ak_addrspace);
+  return PD;
+}
 
 /// Insertion operator for diagnostics. This allows sending Qualifiers into a
 /// diagnostic with <<.

diff  --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 94ae011a0b20..ce996b615bba 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -177,6 +177,9 @@ class DiagnosticsEngine : public 
RefCountedBase {
 /// IdentifierInfo
 ak_identifierinfo,
 
+/// address space
+ak_addrspace,
+
 /// Qualifiers
 ak_qual,
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c91ef356f944..b91fd262c9d3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3987,8 +3987,12 @@ def note_ovl_candidate_bad_lvalue : Note<
 "%select{%ordinal4 argument|object argument}3">;
 def note_ovl_candidate_bad_addrspace : Note<
 "candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
-"address space mismatch in %select{%ordinal6|'this'}5 argument (%3), "
-"parameter type must be %4">;
+"cannot %select{pass pointer to|bind reference in}5 %3 "
+"%select{as a pointer to|to object in}5 %4 in %ordinal6 "
+"argument">;
+def note_ovl_candidate_bad_addrspace_this : Note<
+"candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
+"'this' object is in %3, but method expects object in %4">;
 def note_ovl_candidate_bad_gc : Note<
 "candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
 "%select{%ordinal7|'this'}6 argument (%3) has %select{no|__weak|__strong}4 
"

diff  --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 30985441031d..8ff3cebb1d83 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -338,6 +338,21 @@ void clang::FormatASTNodeDiagnosticArgument(
 
   switch (Kind) {
 default: llvm_unreachable("unknown ArgumentKind");
+case DiagnosticsEngine::ak_addrspace: {
+  assert(Modifier.empty() && Argument.empty() &&
+ "Invalid modifier for Qualfiers argument");
+
+  auto S = Qualifiers::getAddrSpaceAsString(static_cast(Val));
+  if (S.empty()) {
+OS << (Context.getLangOpts().OpenCL ? "default" : "generic");
+OS << " address space";
+  } else {

[clang] e6522a9 - [OpenCL] Allow addr space qualifiers on lambda call expressions

2019-12-04 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2019-12-04T12:25:20Z
New Revision: e6522a96f56ce0257ab8cc6fca77bf9ea4462fa6

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

LOG: [OpenCL] Allow addr space qualifiers on lambda call expressions

The addr space qualifier can be added optionally for lambdas after
the attributes. They will alter the default addr space of lambda
call operator that is in generic address space by default for OpenCL.

Syntax:

[ captures ] ( params ) specifiers exception attr opencl_addrspace
-> ret { body }

Example:

[&] (int i) mutable __global { ... };

On the call into lambda a compatibility check will be performed to
determine whether address space of lambda object and its call operator
are compatible. This will follow regular addr space conversion rules
and there will be no difference to how addr spaces work in method
qualifiers.

Tags: #clang

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

Added: 


Modified: 
clang/lib/Parse/ParseExprCXX.cpp
clang/test/SemaOpenCLCXX/address-space-lambda.cl

Removed: 




diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index 77eed5437609..7dfe71fb9ebc 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1352,6 +1352,13 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
 // Parse attribute-specifier[opt].
 MaybeParseCXX11Attributes(Attr, );
 
+// Parse OpenCL addr space attribute.
+if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
+tok::kw___constant, tok::kw___generic)) {
+  ParseOpenCLQualifiers(DS.getAttributes());
+  ConsumeToken();
+}
+
 SourceLocation FunLocalRangeEnd = DeclEndLoc;
 
 // Parse trailing-return-type[opt].
@@ -1380,10 +1387,12 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
   /*ExceptionSpecTokens*/ nullptr,
   /*DeclsInPrototype=*/None, LParenLoc, FunLocalRangeEnd, 
D,
-  TrailingReturnType),
+  TrailingReturnType, ),
   std::move(Attr), DeclEndLoc);
   } else if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
- tok::kw_constexpr, tok::kw_consteval) ||
+ tok::kw_constexpr, tok::kw_consteval,
+ tok::kw___private, tok::kw___global, tok::kw___local,
+ tok::kw___constant, tok::kw___generic) ||
  (Tok.is(tok::l_square) && NextToken().is(tok::l_square))) {
 // It's common to forget that one needs '()' before 'mutable', an attribute
 // specifier, or the result type. Deal with this.
@@ -1392,6 +1401,11 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
 case tok::kw_mutable: TokKind = 0; break;
 case tok::arrow: TokKind = 1; break;
 case tok::kw___attribute:
+case tok::kw___private:
+case tok::kw___global:
+case tok::kw___local:
+case tok::kw___constant:
+case tok::kw___generic:
 case tok::l_square: TokKind = 2; break;
 case tok::kw_constexpr: TokKind = 3; break;
 case tok::kw_consteval: TokKind = 4; break;

diff  --git a/clang/test/SemaOpenCLCXX/address-space-lambda.cl 
b/clang/test/SemaOpenCLCXX/address-space-lambda.cl
index 8f7a839da448..cf87bfaeede2 100644
--- a/clang/test/SemaOpenCLCXX/address-space-lambda.cl
+++ b/clang/test/SemaOpenCLCXX/address-space-lambda.cl
@@ -3,7 +3,7 @@
 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'int (int) const __generic'
 auto glambda = [](auto a) { return a; };
 
-__kernel void foo() {
+__kernel void test() {
   int i;
 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'void () const __generic'
   auto  llambda = [&]() {i++;};
@@ -23,3 +23,31 @@ __kernel void foo() {
   (*(__constant decltype(llambda) *)nullptr)(); //expected-error{{multiple 
address spaces specified for type}}
   (*(decltype(llambda) *)nullptr)();
 }
+
+__kernel void test_qual() {
+//CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () const'
+  auto priv1 = []() __private {};
+  priv1();
+//CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () const __generic'
+  auto priv2 = []() __generic {};
+  priv2();
+  auto priv3 = []() __global {}; //expected-note-re{{candidate function not 
viable: address space mismatch in 'this' argument ('(lambda at {{.*}})'), 
parameter type must be 'const __global (lambda at {{.*}})'}} 
//expected-note{{conversion candidate of type 'void (*)()'}}
+  priv3(); //expected-error{{no matching function for call to object of type}}
+
+  __constant auto const1 = []() __private{}; //expected-note-re{{candidate 

[clang] 980133a - [OpenCL] Use generic addr space for lambda call operator

2019-12-03 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2019-12-03T16:07:18Z
New Revision: 980133a2098cf6159785b8ac0cbe4d8fbf99bfea

URL: 
https://github.com/llvm/llvm-project/commit/980133a2098cf6159785b8ac0cbe4d8fbf99bfea
DIFF: 
https://github.com/llvm/llvm-project/commit/980133a2098cf6159785b8ac0cbe4d8fbf99bfea.diff

LOG: [OpenCL] Use generic addr space for lambda call operator

Since lambdas are represented by callable objects, we add
generic addr space for implicit object parameter in call
operator.

Any lambda variable declared in __constant addr space
(which is not convertible to generic) fails to compile with
a diagnostic. To support constant addr space we need to
add a way to qualify the lambda call operators.

Tags: #clang

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

Added: 
clang/test/SemaOpenCLCXX/address-space-lambda.cl

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 59e8f3439669..bb8fd4c9c857 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3907,6 +3907,9 @@ class Sema final {
   /// Add the given method to the list of globally-known methods.
   void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
 
+  /// Returns default addr space for method qualifiers.
+  LangAS getDefaultCXXMethodAddrSpace() const;
+
 private:
   /// AddMethodToGlobalPool - Add an instance or factory method to the global
   /// pool. See descriptoin of AddInstanceMethodToGlobalPool.

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 035cb2e15ca0..5ade6bbea074 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1290,6 +1290,12 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() {
   return nullptr;
 }
 
+LangAS Sema::getDefaultCXXMethodAddrSpace() const {
+  if (getLangOpts().OpenCL)
+return LangAS::opencl_generic;
+  return LangAS::Default;
+}
+
 void Sema::EmitCurrentDiagnostic(unsigned DiagID) {
   // FIXME: It doesn't make sense to me that DiagID is an incoming argument 
here
   // and yet we also use the current diag ID on the DiagnosticsEngine. This has

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index f469580dd866..36f7bb320e08 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11417,10 +11417,9 @@ void 
Sema::setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem,
   // Build an exception specification pointing back at this constructor.
   FunctionProtoType::ExtProtoInfo EPI = getImplicitMethodEPI(*this, 
SpecialMem);
 
-  if (getLangOpts().OpenCLCPlusPlus) {
-// OpenCL: Implicitly defaulted special member are of the generic address
-// space.
-EPI.TypeQuals.addAddressSpace(LangAS::opencl_generic);
+  LangAS AS = getDefaultCXXMethodAddrSpace();
+  if (AS != LangAS::Default) {
+EPI.TypeQuals.addAddressSpace(AS);
   }
 
   auto QT = Context.getFunctionType(ResultTy, Args, EPI);
@@ -12330,8 +12329,9 @@ CXXMethodDecl 
*Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) {
 return nullptr;
 
   QualType ArgType = Context.getTypeDeclType(ClassDecl);
-  if (Context.getLangOpts().OpenCLCPlusPlus)
-ArgType = Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
+  LangAS AS = getDefaultCXXMethodAddrSpace();
+  if (AS != LangAS::Default)
+ArgType = Context.getAddrSpaceQualType(ArgType, AS);
   QualType RetType = Context.getLValueReferenceType(ArgType);
   bool Const = ClassDecl->implicitCopyAssignmentHasConstParam();
   if (Const)
@@ -12656,8 +12656,9 @@ CXXMethodDecl 
*Sema::DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl) {
   // constructor rules.
 
   QualType ArgType = Context.getTypeDeclType(ClassDecl);
-  if (Context.getLangOpts().OpenCLCPlusPlus)
-ArgType = Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
+  LangAS AS = getDefaultCXXMethodAddrSpace();
+  if (AS != LangAS::Default)
+ArgType = Context.getAddrSpaceQualType(ArgType, AS);
   QualType RetType = Context.getLValueReferenceType(ArgType);
   ArgType = Context.getRValueReferenceType(ArgType);
 
@@ -13034,8 +13035,9 @@ CXXConstructorDecl 
*Sema::DeclareImplicitCopyConstructor(
   if (Const)
 ArgType = ArgType.withConst();
 
-  if (Context.getLangOpts().OpenCLCPlusPlus)
-ArgType = Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
+  LangAS AS = getDefaultCXXMethodAddrSpace();
+  if (AS != LangAS::Default)
+ArgType = Context.getAddrSpaceQualType(ArgType, AS);
 
   ArgType = Context.getLValueReferenceType(ArgType);
 
@@ -13166,8 +13168,9 @@ CXXConstructorDecl 
*Sema::DeclareImplicitMoveConstructor(
   QualType ClassType = Context.getTypeDeclType(ClassDecl);
 
   QualType ArgType = ClassType;
-  if 

[clang] a29aa47 - [OpenCL] Move addr space deduction to Sema.

2019-11-27 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2019-11-27T12:44:42Z
New Revision: a29aa47106205ec95c12e0ebac4260c5de878a6a

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

LOG: [OpenCL] Move addr space deduction to Sema.

In order to simplify implementation we are moving add space
deduction into Sema while constructing variable declaration
and on template instantiation. Pointee are deduced to generic
addr space during creation of types.

This commit also
- fixed addr space dedution for auto type;
- factors out in a separate helper function OpenCL specific
  logic from type diagnostics in var decl.

Tags: #clang

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

Added: 
clang/test/SemaOpenCLCXX/addrspace-auto.cl

Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaOpenCL/event_t.cl
clang/test/SemaOpenCL/invalid-block.cl
clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
clang/test/SemaOpenCL/sampler_t.cl
clang/test/SemaOpenCLCXX/address-space-deduction.cl
clang/test/SemaOpenCLCXX/restricted.cl

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ecbbd73e19fb..05e78aa78236 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2069,6 +2069,8 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   bool isAlignValT() const; // C++17 std::align_val_t
   bool isStdByteType() const;   // C++17 std::byte
   bool isAtomicType() const;// C11 _Atomic()
+  bool isUndeducedAutoType() const; // C++11 auto or
+// C++14 decltype(auto)
 
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
   bool is##Id##Type() const;
@@ -6509,6 +6511,10 @@ inline bool Type::isAtomicType() const {
   return isa(CanonicalType);
 }
 
+inline bool Type::isUndeducedAutoType() const {
+  return isa(CanonicalType);
+}
+
 inline bool Type::isObjCQualifiedIdType() const {
   if (const auto *OPT = getAs())
 return OPT->isObjCQualifiedIdType();

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0a6f58a484ae..ac5a4953e00d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8760,6 +8760,8 @@ class Sema final {
   bool CheckARCMethodDecl(ObjCMethodDecl *method);
   bool inferObjCARCLifetime(ValueDecl *decl);
 
+  void deduceOpenCLAddressSpace(ValueDecl *decl);
+
   ExprResult
   HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
 Expr *BaseExpr,

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 3f722f8fd541..322b3a7fa740 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1814,7 +1814,7 @@ bool CastExpr::CastConsistency() const {
 auto Ty = getType();
 auto SETy = getSubExpr()->getType();
 assert(getValueKindForType(Ty) == Expr::getValueKindForType(SETy));
-if (/*isRValue()*/ !Ty->getPointeeType().isNull()) {
+if (isRValue()) {
   Ty = Ty->getPointeeType();
   SETy = SETy->getPointeeType();
 }

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6ea4923dc2ba..dffb460cedc9 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6117,6 +6117,22 @@ bool Sema::inferObjCARCLifetime(ValueDecl *decl) {
   return false;
 }
 
+void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
+  if (Decl->getType().getQualifiers().hasAddressSpace())
+return;
+  if (VarDecl *Var = dyn_cast(Decl)) {
+QualType Type = Var->getType();
+if (Type->isSamplerT() || Type->isVoidType())
+  return;
+LangAS ImplAS = LangAS::opencl_private;
+if ((getLangOpts().OpenCLCPlusPlus || getLangOpts().OpenCLVersion >= 200) 
&&
+Var->hasGlobalStorage())
+  ImplAS = LangAS::opencl_global;
+Type = Context.getAddrSpaceQualType(Type, ImplAS);
+Decl->setType(Type);
+  }
+}
+
 static void checkAttributesAfterMerging(Sema , NamedDecl ) {
   // Ensure that an auto decl is deduced otherwise the checks below might cache
   // the wrong linkage.
@@ -6474,6 +6490,105 @@ static bool isDeclExternC(const Decl *D) {
 
   llvm_unreachable("Unknown type of decl!");
 }
+/// Returns true if there hasn't been any invalid type diagnosed.
+static bool diagnoseOpenCLTypes(Scope *S, Sema , Declarator ,
+DeclContext *DC, QualType R) {
+  // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
+  // 

Re: r369749 - [Docs][OpenCL] Several corrections to C++ for OpenCL

2019-08-27 Thread Anastasia Stulova via cfe-commits
Hi Hans,


Can this be merged to the release, please?


Thank you,

Anastasia



From: cfe-commits  on behalf of Anastasia 
Stulova via cfe-commits 
Sent: 23 August 2019 12:43
To: cfe-commits@lists.llvm.org 
Subject: r369749 - [Docs][OpenCL] Several corrections to C++ for OpenCL

Author: stulova
Date: Fri Aug 23 04:43:49 2019
New Revision: 369749

URL: http://llvm.org/viewvc/llvm-project?rev=369749=rev
Log:
[Docs][OpenCL] Several corrections to C++ for OpenCL

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


Modified:
cfe/trunk/docs/LanguageExtensions.rst
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=369749=369748=369749=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Fri Aug 23 04:43:49 2019
@@ -1640,8 +1640,8 @@ OpenCL Features
 C++ for OpenCL
 --

-This functionality is built on top of OpenCL C v2.0 and C++17. Regular C++
-features can be used in OpenCL kernel code. All functionality from OpenCL C
+This functionality is built on top of OpenCL C v2.0 and C++17 enabling most of
+regular C++ features in OpenCL kernel code. Most functionality from OpenCL C
 is inherited. This section describes minor differences to OpenCL C and any
 limitations related to C++ support as well as interactions between OpenCL and
 C++ features that are not documented elsewhere.
@@ -1652,6 +1652,7 @@ Restrictions to C++17
 The following features are not supported:

 - Virtual functions
+- Exceptions
 - ``dynamic_cast`` operator
 - Non-placement ``new``/``delete`` operators
 - Standard C++ libraries. Currently there is no solution for alternative C++
@@ -1667,20 +1668,24 @@ Address space behavior
 Address spaces are part of the type qualifiers; many rules are just inherited
 from the qualifier behavior documented in OpenCL C v2.0 s6.5 and Embedded C
 extension ISO/IEC JTC1 SC22 WG14 N1021 s3.1. Note that since the address space
-behavior in C++ is not documented formally yet, Clang extends existing concept
+behavior in C++ is not documented formally, Clang extends the existing concept
 from C and OpenCL. For example conversion rules are extended from qualification
-conversion but the compatibility is determined using sets and overlapping from
-Embedded C (ISO/IEC JTC1 SC22 WG14 N1021 s3.1.3). For OpenCL it means that
-implicit conversions are allowed from named to ``__generic`` but not vice versa
-(OpenCL C v2.0 s6.5.5) except for ``__constant`` address space. Most of the
-rules are built on top of this behavior.
+conversion but the compatibility is determined using notation of sets and
+overlapping of address spaces from Embedded C (ISO/IEC JTC1 SC22 WG14 N1021
+s3.1.3). For OpenCL it means that implicit conversions are allowed from
+a named address space (except for ``__constant``) to ``__generic`` (OpenCL C
+v2.0 6.5.5). Reverse conversion is only allowed explicitly. The ``__constant``
+address space does not overlap with any other and therefore no valid conversion
+between ``__constant`` and other address spaces exists. Most of the rules
+follow this logic.

 **Casts**

-C style cast will follow OpenCL C v2.0 rules (s6.5.5). All cast operators will
-permit implicit conversion to ``__generic``. However converting from named
-address spaces to ``__generic`` can only be done using ``addrspace_cast``. Note
-that conversions between ``__constant`` and any other is still disallowed.
+C-style casts follow OpenCL C v2.0 rules (s6.5.5). All cast operators
+permit conversion to ``__generic`` implicitly. However converting from
+``__generic`` to named address spaces can only be done using 
``addrspace_cast``.
+Note that conversions between ``__constant`` and any other address space
+are disallowed.

 .. _opencl_cpp_addrsp_deduction:

@@ -1693,7 +1698,7 @@ Address spaces are not deduced for:
 - non-pointer/non-reference class members except for static data members that 
are
   deduced to ``__global`` address space.
 - non-pointer/non-reference alias declarations.
-- ``decltype`` expression.
+- ``decltype`` expressions.

 .. code-block:: c++

@@ -1722,7 +1727,7 @@ TODO: Add example for type alias and dec

 **References**

-References types can be qualified with an address space.
+Reference types can be qualified with an address space.

 .. code-block:: c++

@@ -1737,29 +1742,29 @@ rules from address space pointer convers
 **Default address space**

 All non-static member functions take an implicit object parameter ``this`` that
-is a pointer type. By default this pointer parameter is in ``__generic`` 
address
-space. All concrete objects passed as an argument to ``this`` parameter will be
-converted to ``__generic`` address space first if the conversion is valid.
-Therefore programs using objects in ``__constant`` address space won't

r369779 - [OpenCL] Renamed value of std flag in C++ mode.

2019-08-23 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Aug 23 10:10:33 2019
New Revision: 369779

URL: http://llvm.org/viewvc/llvm-project?rev=369779=rev
Log:
[OpenCL] Renamed value of std flag in C++ mode.
 
Clang should accept -std=clc++ (not -std=c++!) for OpenCL.

This was forgotten in r367008.


Modified:
cfe/trunk/include/clang/Basic/LangStandards.def
cfe/trunk/test/Driver/unknown-std.cl

Modified: cfe/trunk/include/clang/Basic/LangStandards.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangStandards.def?rev=369779=369778=369779=diff
==
--- cfe/trunk/include/clang/Basic/LangStandards.def (original)
+++ cfe/trunk/include/clang/Basic/LangStandards.def Fri Aug 23 10:10:33 2019
@@ -165,7 +165,7 @@ LANGSTANDARD(opencl12, "cl1.2",
 LANGSTANDARD(opencl20, "cl2.0",
  OpenCL, "OpenCL 2.0",
  LineComment | C99 | Digraphs | HexFloat | OpenCL)
-LANGSTANDARD(openclcpp, "c++",
+LANGSTANDARD(openclcpp, "clc++",
  OpenCL, "C++ for OpenCL",
  LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 
|
  Digraphs | HexFloat | OpenCL)

Modified: cfe/trunk/test/Driver/unknown-std.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/unknown-std.cl?rev=369779=369778=369779=diff
==
--- cfe/trunk/test/Driver/unknown-std.cl (original)
+++ cfe/trunk/test/Driver/unknown-std.cl Fri Aug 23 10:10:33 2019
@@ -10,7 +10,7 @@
 // CHECK-NEXT: note: use 'cl1.1' for 'OpenCL 1.1' standard
 // CHECK-NEXT: note: use 'cl1.2' for 'OpenCL 1.2' standard
 // CHECK-NEXT: note: use 'cl2.0' for 'OpenCL 2.0' standard
-// CHECK-NEXT: note: use 'c++' for 'C++ for OpenCL' standard
+// CHECK-NEXT: note: use 'clc++' for 'C++ for OpenCL' standard
 
 // Make sure that no other output is present.
 // CHECK-NOT: {{^.+$}}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r369749 - [Docs][OpenCL] Several corrections to C++ for OpenCL

2019-08-23 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Aug 23 04:43:49 2019
New Revision: 369749

URL: http://llvm.org/viewvc/llvm-project?rev=369749=rev
Log:
[Docs][OpenCL] Several corrections to C++ for OpenCL

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


Modified:
cfe/trunk/docs/LanguageExtensions.rst
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=369749=369748=369749=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Fri Aug 23 04:43:49 2019
@@ -1640,8 +1640,8 @@ OpenCL Features
 C++ for OpenCL
 --
 
-This functionality is built on top of OpenCL C v2.0 and C++17. Regular C++
-features can be used in OpenCL kernel code. All functionality from OpenCL C
+This functionality is built on top of OpenCL C v2.0 and C++17 enabling most of
+regular C++ features in OpenCL kernel code. Most functionality from OpenCL C
 is inherited. This section describes minor differences to OpenCL C and any
 limitations related to C++ support as well as interactions between OpenCL and
 C++ features that are not documented elsewhere.
@@ -1652,6 +1652,7 @@ Restrictions to C++17
 The following features are not supported:
 
 - Virtual functions
+- Exceptions
 - ``dynamic_cast`` operator
 - Non-placement ``new``/``delete`` operators
 - Standard C++ libraries. Currently there is no solution for alternative C++
@@ -1667,20 +1668,24 @@ Address space behavior
 Address spaces are part of the type qualifiers; many rules are just inherited
 from the qualifier behavior documented in OpenCL C v2.0 s6.5 and Embedded C
 extension ISO/IEC JTC1 SC22 WG14 N1021 s3.1. Note that since the address space
-behavior in C++ is not documented formally yet, Clang extends existing concept
+behavior in C++ is not documented formally, Clang extends the existing concept
 from C and OpenCL. For example conversion rules are extended from qualification
-conversion but the compatibility is determined using sets and overlapping from
-Embedded C (ISO/IEC JTC1 SC22 WG14 N1021 s3.1.3). For OpenCL it means that
-implicit conversions are allowed from named to ``__generic`` but not vice versa
-(OpenCL C v2.0 s6.5.5) except for ``__constant`` address space. Most of the
-rules are built on top of this behavior.
+conversion but the compatibility is determined using notation of sets and
+overlapping of address spaces from Embedded C (ISO/IEC JTC1 SC22 WG14 N1021
+s3.1.3). For OpenCL it means that implicit conversions are allowed from
+a named address space (except for ``__constant``) to ``__generic`` (OpenCL C
+v2.0 6.5.5). Reverse conversion is only allowed explicitly. The ``__constant``
+address space does not overlap with any other and therefore no valid conversion
+between ``__constant`` and other address spaces exists. Most of the rules
+follow this logic.
 
 **Casts**
 
-C style cast will follow OpenCL C v2.0 rules (s6.5.5). All cast operators will
-permit implicit conversion to ``__generic``. However converting from named
-address spaces to ``__generic`` can only be done using ``addrspace_cast``. Note
-that conversions between ``__constant`` and any other is still disallowed.
+C-style casts follow OpenCL C v2.0 rules (s6.5.5). All cast operators
+permit conversion to ``__generic`` implicitly. However converting from
+``__generic`` to named address spaces can only be done using 
``addrspace_cast``.
+Note that conversions between ``__constant`` and any other address space
+are disallowed.
 
 .. _opencl_cpp_addrsp_deduction:
 
@@ -1693,7 +1698,7 @@ Address spaces are not deduced for:
 - non-pointer/non-reference class members except for static data members that 
are
   deduced to ``__global`` address space.
 - non-pointer/non-reference alias declarations.
-- ``decltype`` expression.
+- ``decltype`` expressions.
 
 .. code-block:: c++
 
@@ -1722,7 +1727,7 @@ TODO: Add example for type alias and dec
 
 **References**
 
-References types can be qualified with an address space.
+Reference types can be qualified with an address space.
 
 .. code-block:: c++
 
@@ -1737,29 +1742,29 @@ rules from address space pointer convers
 **Default address space**
 
 All non-static member functions take an implicit object parameter ``this`` that
-is a pointer type. By default this pointer parameter is in ``__generic`` 
address
-space. All concrete objects passed as an argument to ``this`` parameter will be
-converted to ``__generic`` address space first if the conversion is valid.
-Therefore programs using objects in ``__constant`` address space won't be 
compiled
-unless address space is explicitly specified using address space qualifiers on
-member functions
+is a pointer type. By default this pointer parameter is in the ``__generic``
+address space. All concrete objects passed as an argument to ``this`` parameter
+will be converted to the 

Re: r369641 - [OpenCL] Fix declaration of enqueue_marker

2019-08-22 Thread Anastasia Stulova via cfe-commits
Hi Hans,


Can this still be merged into the release branch please.


Thanks in advance,

Anastasia



From: cfe-commits  on behalf of Yaxun Liu 
via cfe-commits 
Sent: 22 August 2019 12:18
To: cfe-commits@lists.llvm.org 
Subject: r369641 - [OpenCL] Fix declaration of enqueue_marker

Author: yaxunl
Date: Thu Aug 22 04:18:59 2019
New Revision: 369641

URL: http://llvm.org/viewvc/llvm-project?rev=369641=rev
Log:
[OpenCL] Fix declaration of enqueue_marker

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

Modified:
cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=369641=369640=369641=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Thu Aug 22 04:18:59 2019
@@ -15350,7 +15350,7 @@ ndrange_t __ovld ndrange_3D(const size_t
 ndrange_t __ovld ndrange_3D(const size_t[3], const size_t[3]);
 ndrange_t __ovld ndrange_3D(const size_t[3], const size_t[3], const size_t[3]);

-int __ovld enqueue_marker(queue_t, uint, const __private clk_event_t*, 
__private clk_event_t*);
+int __ovld enqueue_marker(queue_t, uint, const clk_event_t*, clk_event_t*);

 void __ovld retain_event(clk_event_t);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r369251 - [OpenCL] Fix addr space deduction for pointers/references to arrays.

2019-08-20 Thread Anastasia Stulova via cfe-commits

Hi Hans,

Is it still possible to port this fix to the release branch?

Thanks,
Anastasia


From: cfe-commits  on behalf of Anastasia 
Stulova via cfe-commits 
Sent: 19 August 2019 12:43
To: cfe-commits@lists.llvm.org 
Subject: r369251 - [OpenCL] Fix addr space deduction for pointers/references to 
arrays.

Author: stulova
Date: Mon Aug 19 04:43:16 2019
New Revision: 369251

URL: http://llvm.org/viewvc/llvm-project?rev=369251=rev
Log:
[OpenCL] Fix addr space deduction for pointers/references to arrays.

Rewrite the logic for detecting if we are deducing addr space of
a pointee type to take into account special logic for arrays. For
pointers/references to arrays we can have any number of parentheses
expressions as well as nested pointers.

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


Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=369251=369250=369251=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Aug 19 04:43:16 2019
@@ -7385,8 +7385,22 @@ static void deduceOpenCLImplicitAddrSpac
   bool IsPointee =
   ChunkIndex > 0 &&
   (D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Pointer ||
-   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer ||
-   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference);
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference ||
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer);
+  // For pointers/references to arrays the next chunk is always an array
+  // followed by any number of parentheses.
+  if (!IsPointee && ChunkIndex > 1) {
+auto AdjustedCI = ChunkIndex - 1;
+if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Array)
+  AdjustedCI--;
+// Skip over all parentheses.
+while (AdjustedCI > 0 &&
+   D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Paren)
+  AdjustedCI--;
+if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Pointer ||
+D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Reference)
+  IsPointee = true;
+  }
   bool IsFuncReturnType =
   ChunkIndex > 0 &&
   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Function;

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=369251=369250=369251=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Mon Aug 19 04:43:16 
2019
@@ -78,3 +78,25 @@ __kernel void test() {
   int foo[10];
   xxx([0]);
 }
+
+// Addr space for pointer/reference to an array
+//CHECK: FunctionDecl {{.*}} t1 'void (const __generic float (&)[2])'
+void t1(const float ()[2]);
+//CHECK: FunctionDecl {{.*}} t2 'void (const __generic float (*)[2])'
+void t2(const float (*fYZ)[2]);
+//CHECK: FunctionDecl {{.*}} t3 'void (__generic float (((*)))[2])'
+void t3(float(((*fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t4 'void (__generic float (((*__generic *)))[2])'
+void t4(float(((**fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t5 'void (__generic float (*__generic (*))[2])'
+void t5(float (*(*fYZ))[2]);
+
+__kernel void k() {
+  __local float x[2];
+  __local float(*p)[2];
+  t1(x);
+  t2();
+  t3();
+  t4();
+  t5();
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r369251 - [OpenCL] Fix addr space deduction for pointers/references to arrays.

2019-08-19 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Aug 19 04:43:16 2019
New Revision: 369251

URL: http://llvm.org/viewvc/llvm-project?rev=369251=rev
Log:
[OpenCL] Fix addr space deduction for pointers/references to arrays.

Rewrite the logic for detecting if we are deducing addr space of
a pointee type to take into account special logic for arrays. For
pointers/references to arrays we can have any number of parentheses
expressions as well as nested pointers.

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


Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=369251=369250=369251=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Aug 19 04:43:16 2019
@@ -7385,8 +7385,22 @@ static void deduceOpenCLImplicitAddrSpac
   bool IsPointee =
   ChunkIndex > 0 &&
   (D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Pointer ||
-   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer ||
-   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference);
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference ||
+   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer);
+  // For pointers/references to arrays the next chunk is always an array
+  // followed by any number of parentheses.
+  if (!IsPointee && ChunkIndex > 1) {
+auto AdjustedCI = ChunkIndex - 1;
+if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Array)
+  AdjustedCI--;
+// Skip over all parentheses.
+while (AdjustedCI > 0 &&
+   D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Paren)
+  AdjustedCI--;
+if (D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Pointer ||
+D.getTypeObject(AdjustedCI).Kind == DeclaratorChunk::Reference)
+  IsPointee = true;
+  }
   bool IsFuncReturnType =
   ChunkIndex > 0 &&
   D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Function;

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=369251=369250=369251=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Mon Aug 19 04:43:16 
2019
@@ -78,3 +78,25 @@ __kernel void test() {
   int foo[10];
   xxx([0]);
 }
+
+// Addr space for pointer/reference to an array
+//CHECK: FunctionDecl {{.*}} t1 'void (const __generic float (&)[2])'
+void t1(const float ()[2]);
+//CHECK: FunctionDecl {{.*}} t2 'void (const __generic float (*)[2])'
+void t2(const float (*fYZ)[2]);
+//CHECK: FunctionDecl {{.*}} t3 'void (__generic float (((*)))[2])'
+void t3(float(((*fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t4 'void (__generic float (((*__generic *)))[2])'
+void t4(float(((**fYZ)))[2]);
+//CHECK: FunctionDecl {{.*}} t5 'void (__generic float (*__generic (*))[2])'
+void t5(float (*(*fYZ))[2]);
+
+__kernel void k() {
+  __local float x[2];
+  __local float(*p)[2];
+  t1(x);
+  t2();
+  t3();
+  t4();
+  t5();
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r368552 - [OpenCL] Fix lang mode predefined macros for C++ mode.

2019-08-13 Thread Anastasia Stulova via cfe-commits
Hi Hans,


Can this be merged into the release 9.0 branch please?

Thank you!
Anastasia



From: cfe-commits  on behalf of Anastasia 
Stulova via cfe-commits 
Sent: 12 August 2019 11:44
To: cfe-commits@lists.llvm.org 
Subject: r368552 - [OpenCL] Fix lang mode predefined macros for C++ mode.

Author: stulova
Date: Mon Aug 12 03:44:07 2019
New Revision: 368552

URL: http://llvm.org/viewvc/llvm-project?rev=368552=rev
Log:
[OpenCL] Fix lang mode predefined macros for C++ mode.

In C++ mode we should only avoid adding __OPENCL_C_VERSION__,
all other predefined macros about the language mode are still
valid.

This change also fixes the language version check in the
headers accordingly.

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


Modified:
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Headers/opencl-c-base.h
cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=368552=368551=368552=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Aug 12 03:44:07 2019
@@ -437,17 +437,17 @@ static void InitializeStandardPredefined
   default:
 llvm_unreachable("Unsupported OpenCL version");
   }
-  Builder.defineMacro("CL_VERSION_1_0", "100");
-  Builder.defineMacro("CL_VERSION_1_1", "110");
-  Builder.defineMacro("CL_VERSION_1_2", "120");
-  Builder.defineMacro("CL_VERSION_2_0", "200");
+}
+Builder.defineMacro("CL_VERSION_1_0", "100");
+Builder.defineMacro("CL_VERSION_1_1", "110");
+Builder.defineMacro("CL_VERSION_1_2", "120");
+Builder.defineMacro("CL_VERSION_2_0", "200");

-  if (TI.isLittleEndian())
-Builder.defineMacro("__ENDIAN_LITTLE__");
+if (TI.isLittleEndian())
+  Builder.defineMacro("__ENDIAN_LITTLE__");

-  if (LangOpts.FastRelaxedMath)
-Builder.defineMacro("__FAST_RELAXED_MATH__");
-}
+if (LangOpts.FastRelaxedMath)
+  Builder.defineMacro("__FAST_RELAXED_MATH__");
   }
   // Not "standard" per se, but available even with the -undef flag.
   if (LangOpts.AsmPreprocessor)

Modified: cfe/trunk/lib/Headers/opencl-c-base.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c-base.h?rev=368552=368551=368552=diff
==
--- cfe/trunk/lib/Headers/opencl-c-base.h (original)
+++ cfe/trunk/lib/Headers/opencl-c-base.h Mon Aug 12 03:44:07 2019
@@ -126,7 +126,7 @@ typedef double double8 __attribute__((ex
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif

-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define NULL ((void*)0)
 #endif

@@ -276,7 +276,7 @@ typedef uint cl_mem_fence_flags;
  */
 #define CLK_GLOBAL_MEM_FENCE   0x02

-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)

 typedef enum memory_scope {
   memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
@@ -288,9 +288,6 @@ typedef enum memory_scope {
 #endif
 } memory_scope;

-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 /**
  * Queue a memory fence to ensure correct ordering of memory
  * operations between work-items of a work-group to
@@ -313,7 +310,7 @@ typedef enum memory_order
   memory_order_seq_cst = __ATOMIC_SEQ_CST
 } memory_order;

-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)

 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write 
Functions

@@ -389,14 +386,10 @@ typedef enum memory_order
 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0

 // OpenCL v2.0 s6.13.16 - Pipe Functions
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define CLK_NULL_RESERVE_ID (__builtin_astype(((void*)(__SIZE_MAX__)), 
reserve_id_t))
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
-

 // OpenCL v2.0 s6.13.17 - Enqueue Kernels
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
 #define CL_COMPLETE 0x0
 #define CL_RUNNING  0x1
 #define CL_SUBMITTED0x2
@@ -435,7 +428,7 @@ typedef struct {
   size_t localWorkSize[MAX_WORK_DIM];
 } ndrange_t;

-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#endif // defined(_

Re: r368561 - [OpenCL] Ignore parentheses for sampler initialization

2019-08-13 Thread Anastasia Stulova via cfe-commits
Hi Hans,


Can this be merged into the release 9.0 branch please?

Thank you!
Anastasia


From: cfe-commits  on behalf of Sven van 
Haastregt via cfe-commits 
Sent: 12 August 2019 13:44
To: cfe-commits@lists.llvm.org 
Subject: r368561 - [OpenCL] Ignore parentheses for sampler initialization

Author: svenvh
Date: Mon Aug 12 05:44:26 2019
New Revision: 368561

URL: http://llvm.org/viewvc/llvm-project?rev=368561=rev
Log:
[OpenCL] Ignore parentheses for sampler initialization

The sampler handling logic in SemaInit.cpp would inadvertently treat
parentheses around sampler arguments as an implicit cast, leading to
an unreachable "can't implicitly cast lvalue to rvalue with
this cast kind".  Fix by ignoring parentheses once we are in the
sampler initializer case.

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

Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaOpenCL/sampler_t.cl

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=368561=368560=368561=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Aug 12 05:44:26 2019
@@ -8248,7 +8248,7 @@ ExprResult InitializationSequence::Perfo
   // argument passing.
   assert(Step->Type->isSamplerT() &&
  "Sampler initialization on non-sampler type.");
-  Expr *Init = CurInit.get();
+  Expr *Init = CurInit.get()->IgnoreParens();
   QualType SourceType = Init->getType();
   // Case 1
   if (Entity.isParameterKind()) {

Modified: cfe/trunk/test/SemaOpenCL/sampler_t.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/sampler_t.cl?rev=368561=368560=368561=diff
==
--- cfe/trunk/test/SemaOpenCL/sampler_t.cl (original)
+++ cfe/trunk/test/SemaOpenCL/sampler_t.cl Mon Aug 12 05:44:26 2019
@@ -10,6 +10,9 @@
 #define CLK_FILTER_NEAREST  0x10
 #define CLK_FILTER_LINEAR   0x20

+typedef float float4 __attribute__((ext_vector_type(4)));
+float4 read_imagef(read_only image1d_t, sampler_t, float);
+
 constant sampler_t glb_smp = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
 constant sampler_t glb_smp2; // expected-error{{variable in constant address 
space must be initialized}}
 global sampler_t glb_smp3 = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST; // expected-error{{sampler 
type cannot be used with the __local and __global address space qualifiers}} 
expected-error {{global sampler requires a const or constant address space 
qualifier}}
@@ -74,3 +77,7 @@ void bar() {
   foo(smp1+1); //expected-error{{invalid operands to binary expression 
('sampler_t' and 'int')}}
 }

+void smp_args(read_only image1d_t image) {
+  // Test that parentheses around sampler arguments are ignored.
+  float4 res = read_imagef(image, (glb_smp10), 0.0f);
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r368552 - [OpenCL] Fix lang mode predefined macros for C++ mode.

2019-08-12 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Aug 12 03:44:07 2019
New Revision: 368552

URL: http://llvm.org/viewvc/llvm-project?rev=368552=rev
Log:
[OpenCL] Fix lang mode predefined macros for C++ mode.

In C++ mode we should only avoid adding __OPENCL_C_VERSION__,
all other predefined macros about the language mode are still
valid.

This change also fixes the language version check in the
headers accordingly.

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


Modified:
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Headers/opencl-c-base.h
cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=368552=368551=368552=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Aug 12 03:44:07 2019
@@ -437,17 +437,17 @@ static void InitializeStandardPredefined
   default:
 llvm_unreachable("Unsupported OpenCL version");
   }
-  Builder.defineMacro("CL_VERSION_1_0", "100");
-  Builder.defineMacro("CL_VERSION_1_1", "110");
-  Builder.defineMacro("CL_VERSION_1_2", "120");
-  Builder.defineMacro("CL_VERSION_2_0", "200");
+}
+Builder.defineMacro("CL_VERSION_1_0", "100");
+Builder.defineMacro("CL_VERSION_1_1", "110");
+Builder.defineMacro("CL_VERSION_1_2", "120");
+Builder.defineMacro("CL_VERSION_2_0", "200");
 
-  if (TI.isLittleEndian())
-Builder.defineMacro("__ENDIAN_LITTLE__");
+if (TI.isLittleEndian())
+  Builder.defineMacro("__ENDIAN_LITTLE__");
 
-  if (LangOpts.FastRelaxedMath)
-Builder.defineMacro("__FAST_RELAXED_MATH__");
-}
+if (LangOpts.FastRelaxedMath)
+  Builder.defineMacro("__FAST_RELAXED_MATH__");
   }
   // Not "standard" per se, but available even with the -undef flag.
   if (LangOpts.AsmPreprocessor)

Modified: cfe/trunk/lib/Headers/opencl-c-base.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c-base.h?rev=368552=368551=368552=diff
==
--- cfe/trunk/lib/Headers/opencl-c-base.h (original)
+++ cfe/trunk/lib/Headers/opencl-c-base.h Mon Aug 12 03:44:07 2019
@@ -126,7 +126,7 @@ typedef double double8 __attribute__((ex
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define NULL ((void*)0)
 #endif
 
@@ -276,7 +276,7 @@ typedef uint cl_mem_fence_flags;
  */
 #define CLK_GLOBAL_MEM_FENCE   0x02
 
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 
 typedef enum memory_scope {
   memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
@@ -288,9 +288,6 @@ typedef enum memory_scope {
 #endif
 } memory_scope;
 
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 /**
  * Queue a memory fence to ensure correct ordering of memory
  * operations between work-items of a work-group to
@@ -313,7 +310,7 @@ typedef enum memory_order
   memory_order_seq_cst = __ATOMIC_SEQ_CST
 } memory_order;
 
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
 
 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write 
Functions
 
@@ -389,14 +386,10 @@ typedef enum memory_order
 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
 // OpenCL v2.0 s6.13.16 - Pipe Functions
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define CLK_NULL_RESERVE_ID (__builtin_astype(((void*)(__SIZE_MAX__)), 
reserve_id_t))
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
 
 // OpenCL v2.0 s6.13.17 - Enqueue Kernels
-#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
-
 #define CL_COMPLETE 0x0
 #define CL_RUNNING  0x1
 #define CL_SUBMITTED0x2
@@ -435,7 +428,7 @@ typedef struct {
   size_t localWorkSize[MAX_WORK_DIM];
 } ndrange_t;
 
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
+#endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
 
 #ifdef cl_intel_device_side_avc_motion_estimation
 #pragma OPENCL EXTENSION cl_intel_device_side_avc_motion_estimation : begin

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=368552=368551=368552=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Mon Aug 12 03:44:07 2019
@@ -11,11 +11,11 @@
 
 #include 

Re: r367675 - [OpenCL] Allow OpenCL C style vector initialization in C++

2019-08-05 Thread Anastasia Stulova via cfe-commits
Hi Yvan,


Sorry for this, it should now be fixed  in r367823.


Thanks,

Anastasia



From: Yvan Roux 
Sent: 02 August 2019 14:09
To: Anastasia Stulova 
Cc: cfe-commits 
Subject: Re: r367675 - [OpenCL] Allow OpenCL C style vector initialization in 
C++

Hi Anastasia,

This commit broke ARMv8 bots, logs are available here:

http://lab.llvm.org:8011/builders/clang-cmake-armv8-quick/builds/14655/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Avector_literals_valid.cl

Thanks,
Yvan

On Fri, 2 Aug 2019 at 13:18, Anastasia Stulova via cfe-commits
 wrote:
>
> Author: stulova
> Date: Fri Aug  2 04:19:35 2019
> New Revision: 367675
>
> URL: http://llvm.org/viewvc/llvm-project?rev=367675=rev
> Log:
> [OpenCL] Allow OpenCL C style vector initialization in C++
>
> Allow creating vector literals from other vectors.
>
>  float4 a = (float4)(1.0f, 2.0f, 3.0f, 4.0f);
>  float4 v = (float4)(a.s23, a.s01);
>
> Differential revision: https://reviews.llvm.org/D65286
>
>
> Removed:
> cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl
> cfe/trunk/test/SemaOpenCL/vector_literals_const.cl
> Modified:
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl
> cfe/trunk/test/SemaCXX/vector.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=367675=367674=367675=diff
> ==
> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug  2 04:19:35 2019
> @@ -1289,7 +1289,16 @@ void InitListChecker::CheckSubElementTyp
>  // FIXME: Better EqualLoc?
>  InitializationKind Kind =
>  InitializationKind::CreateCopy(expr->getBeginLoc(), 
> SourceLocation());
> -InitializationSequence Seq(SemaRef, Entity, Kind, expr,
> +
> +// Vector elements can be initialized from other vectors in which case
> +// we need initialization entity with a type of a vector (and not a 
> vector
> +// element!) initializing multiple vector elements.
> +auto TmpEntity =
> +(ElemType->isExtVectorType() && !Entity.getType()->isExtVectorType())
> +? InitializedEntity::InitializeTemporary(ElemType)
> +: Entity;
> +
> +InitializationSequence Seq(SemaRef, TmpEntity, Kind, expr,
> /*TopLevelOfInitList*/ true);
>
>  // C++14 [dcl.init.aggr]p13:
> @@ -1300,8 +1309,7 @@ void InitListChecker::CheckSubElementTyp
>  // assignment-expression.
>  if (Seq || isa(expr)) {
>if (!VerifyOnly) {
> -ExprResult Result =
> -  Seq.Perform(SemaRef, Entity, Kind, expr);
> +ExprResult Result = Seq.Perform(SemaRef, TmpEntity, Kind, expr);
>  if (Result.isInvalid())
>hadError = true;
>
>
> Removed: cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl?rev=367674=auto
> ==
> --- cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl (original)
> +++ cfe/trunk/test/CodeGenOpenCL/vector_literals_nested.cl (removed)
> @@ -1,23 +0,0 @@
> -// RUN: %clang_cc1 %s -emit-llvm -O3 -o - | FileCheck %s
> -
> -typedef int int2 __attribute((ext_vector_type(2)));
> -typedef int int4 __attribute((ext_vector_type(4)));
> -
> -__constant const int4 itest1 = (int4)(1, 2, ((int2)(3, 4)));
> -// CHECK: constant <4 x i32> 
> -__constant const int4 itest2 = (int4)(1, 2, ((int2)(3)));
> -// CHECK: constant <4 x i32> 
> -
> -typedef float float2 __attribute((ext_vector_type(2)));
> -typedef float float4 __attribute((ext_vector_type(4)));
> -
> -void ftest1(float4 *p) {
> -  *p = (float4)(1.1f, 1.2f, ((float2)(1.3f, 1.4f)));
> -// CHECK: store <4 x float>  0x3FF34000, float 0x3FF4C000, float 0x3FF66000>
> -}
> -
> -float4 ftest2(float4 *p) {
> -   *p =  (float4)(1.1f, 1.2f, ((float2)(1.3f)));
> -// CHECK: store <4 x float>  0x3FF34000, float 0x3FF4C000, float 0x3FF4C000>
> -}
> -
>
> Modified: cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl?rev=367675=367674=367675=diff
> ==
> --- cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl (original)
> +++ cfe/trunk/test/CodeGenOpenCL/vector_literals_valid.cl Fri Aug  2 04:19:35 
> 

  1   2   3   4   5   6   >