Commit Graph

64 Commits

Author SHA1 Message Date
Ole Strohm b102e6880a [OpenCL] Fix overloading resolution of addrspace constructors
This fixes the prioritization of address spaces when choosing a
constructor, stopping them from being considered equally good,
which made the construction of types that could be constructed
by more than one of the constructors.

It does this by preferring the most specific address space,
which is decided by seeing if one of the address spaces is
a superset of the other, and preferring the other.

Fixes: PR50329

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D102850
2021-06-11 11:12:33 +01:00
Ole Strohm 94b0aec0f5 [OpenCL] Fix ICE with invalid use of half
Because half is limited to the `cl_khr_fp16` extension being enabled,
`DefaultLvalueConversion` can fail when it's not enabled.
The original assumption that it will never fail is therefore wrong now.

Fixes: PR47976

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D103175
2021-06-01 13:43:07 +01:00
Ole Strohm 642d2f000b [OpenCL] Fix initialization of __constant constructors without arguments
This fixes the initialization of objects in the __constant
address space that occurs when declaring the object.

Fixes part of PR42566

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D102248
2021-05-18 10:59:53 +01:00
Ole Strohm 66b112d624 [OpenCL] Fix reinterpret_cast of vectors
Fixes issues with vectors in reinterpret_cast in C++ for OpenCL
and adds tests to make sure they both pass without errors and
generate the correct code.

Fixes: PR47977

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D101519
2021-05-17 12:42:21 +01:00
Anastasia Stulova e994e74bca [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
2021-05-05 14:58:23 +01:00
Anastasia Stulova 6a92c19f3b [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
2021-04-27 13:04:25 +01:00
Anastasia Stulova 362958ac73 [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
2021-04-22 15:28:04 +01:00
Anastasia Stulova 6e46f0b628 [OpenCL] Fix AST check in address-space-templates test
Differential Revision: https://reviews.llvm.org/D99258
2021-03-26 14:24:30 +00:00
Marek Kurdej 0620e6f4b7 [clang] [C++2b] [P1102] Accept lambdas without parameter list ().
As an extension, accept such lambdas in previous standards with a warning.

* http://eel.is/c++draft/expr.prim.lambda
* http://wg21.link/P1102

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D98433
2021-03-24 14:42:27 +01:00
Anastasia Stulova d1c8a151df [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
2021-03-24 13:07:04 +00:00
Sven van Haastregt 2bbc9bccf0 [OpenCL] Support template parameters for as_type
Implement the TreeTransform for AsTypeExpr.  Split `BuildAsTypeExpr`
out of `ActOnAsTypeExpr`, such that we can call the Build method from
the TreeTransform.

Fixes PR47979.

Differential Revision: https://reviews.llvm.org/D98855
2021-03-22 11:59:05 +00:00
Anastasia Stulova 0c65993be1 [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
2021-02-04 13:51:53 +00:00
Anastasia Stulova e635feb15a [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
2021-02-03 12:48:21 +00:00
Anastasia Stulova 844f01fc95 Fixed failing OpenCL test 2021-02-02 16:19:28 +00:00
Anastasia Stulova 5bbf39704c [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
2021-02-02 15:07:40 +00:00
Anastasia Stulova 4fde2b6a0c [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
2021-01-06 20:39:57 +00:00
Sven van Haastregt 29d375f5ff [OpenCL][NFC] Improve OpenCL test file naming
Change "negative" into "invalid" and put "invalid" at the beginning of
the file name, following the bulk of the invalid tests in the
SemaOpenCL directory.

Use the "invalid-" prefix only for tests that contain only invalid
constructs.

Drop the "valid" suffix for CodeGen tests, as inputs in this directory
are supposed to be valid anyway.
2021-01-06 14:16:44 +00:00
Anastasia Stulova 6f770292a0 [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
2021-01-05 13:32:18 +00:00
Erich Keane a72f11ee20 Fix a pair of tests that would fail on a win32 box
The tests don't specify a triple in some cases, since they shouldn't be
necessary, so I've updated the tests to detect via macro when they are
running on win32 to give the slightly altered diagnostic.
2020-11-17 14:28:52 -08:00
Erich Keane 6976fef05b Update 'note-candiate' functions to skip lambda-conversion-op-overloads
In the wake of https://reviews.llvm.org/D89559, we discovered that a
couple of tests (the ones modified below to have additional triple
versions) would fail on Win32, for 1 of two reasons.  We seem to not
have a win32 buildbot anymore, so the triple is to make sure this
doesn't get broken in the future.

First, two of the three 'note-candidate' functions weren't appropriately
skipping the remaining conversion functions.

Second, in 1 situation (note surrogate candidates) we actually print the
type of the conversion operator.  The two tests that ran into that
needed updating to make sure it printed the proper one in the win32
case.
2020-11-17 05:49:31 -08:00
Anastasia Stulova 92fa91bb40 [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
2020-07-27 15:18:49 +01:00
Anastasia Stulova 6050c156ab [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
2020-07-13 11:44:38 +01:00
Haojian Wu 58ea1059df [AST][RecoveryExpr] Build recovery expressions by default for C++.
Reland https://reviews.llvm.org/D76696
All known crashes have been fixed, another attemption.

We have rolled out this to all internal users for a while, didn't see
big issues, we consider it is stable enough.

Reviewed By: sammccall

Subscribers: rsmith, hubert.reinterpretcast, ebevhan, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78350
2020-06-12 15:21:38 +02:00
Anastasia Stulova a6a237f204 [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
2020-05-18 12:07:54 +01:00
Anastasia Stulova fe667e8522 [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.
2020-04-28 12:46:36 +01:00
Haojian Wu 62dea6e9be Revert "[AST] Build recovery expressions by default for C++."
This reverts commit 0788acbccb.
This reverts commit c2d7a1f79cedfc9fcb518596aa839da4de0adb69:  Revert "[clangd] Add test for FindTarget+RecoveryExpr (which already works). NFC"

It causes a crash on invalid code:

class X {
  decltype(unresolved()) foo;
};
constexpr int s = sizeof(X);
2020-03-26 16:25:32 +01:00
Haojian Wu 0788acbccb [AST] Build recovery expressions by default for C++.
Update the existing tests.

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76696
2020-03-25 09:00:48 +01:00
Anastasia Stulova 6064f426a1 [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
2020-02-07 12:04:35 +00:00
Hans Wennborg 698d1cd3b8 Make address-space-lambda.cl pass on 32-bit Windows
Member functions will have the thiscall attribute on them.
2020-01-24 20:35:25 +01:00
Richard Smith 9a6f4d451c Clean up and slightly generalize implementation of composite pointer
type computation, in preparation for P0388R4, which adds another few
cases here.

We now properly handle forming multi-level composite pointer types
involving nested Objective-C pointer types (as is consistent with
including them as part of the notion of 'similar types' on which this
rule is based). We no longer lose non-CVR qualifiers on nested pointer
types.
2020-01-10 16:12:00 -08:00
Anastasia Stulova 869d17d851 [OpenCL] Pretty print __private addr space
Add printing of __private address space to TypePrinter to allow
it appears in diagnostics and AST dumps as all other language
addr spaces.

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71272
2019-12-27 13:42:07 +00:00
Anastasia Stulova ed8dadb37c [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/D71111
2019-12-13 12:35:18 +00:00
Anastasia Stulova e6522a96f5 [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
2019-12-04 12:25:20 +00:00
Anastasia Stulova 980133a209 [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
2019-12-03 16:07:18 +00:00
Anastasia Stulova a29aa47106 [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
2019-11-27 12:44:42 +00:00
Aaron Ballman 99178faf59 Quote the token being diagnosed for C11 extensions.
llvm-svn: 370059
2019-08-27 13:47:51 +00:00
Aaron Ballman 72797ba072 Updating a test case that was missed in r369957.
llvm-svn: 369968
2019-08-26 20:55:43 +00:00
Aaron Ballman 774bd6ef1c Diagnose use of _Thread_local as an extension when not in C11 mode.
llvm-svn: 369954
2019-08-26 19:44:07 +00:00
Anastasia Stulova eb801abd58 [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

llvm-svn: 369251
2019-08-19 11:43:16 +00:00
Anastasia Stulova 88ed70e247 [OpenCL] Rename lang mode flag for C++ mode
Rename lang mode flag to -cl-std=clc++/-cl-std=CLC++
or -std=clc++/-std=CLC++.

This aligns with OpenCL C conversion and removes ambiguity
with OpenCL C++. 

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

llvm-svn: 367008
2019-07-25 11:04:29 +00:00
Anastasia Stulova 46b55fa58d [OpenCL] Update comments/diagnostics to refer to C++ for OpenCL
Clang doesn't implement OpenCL C++, change the comments to
reflect that.

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

llvm-svn: 366421
2019-07-18 10:02:35 +00:00
Anastasia Stulova 36d9e8358a [OpenCL][PR42033] Fix addr space deduction with template parameters
If dependent types appear in pointers or references we allow addr
space deduction because the addr space in template argument will
belong to the pointee and not the pointer or reference itself.

We also don't diagnose addr space on a function return type after
template instantiation. If any addr space for the return type was
provided on a template parameter this will be diagnosed during the
parsing of template definition.

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

llvm-svn: 366417
2019-07-18 09:12:49 +00:00
Reid Kleckner 9304e59c01 Fix OpenCLCXX test on 32-bit Windows where thiscall is present
llvm-svn: 366284
2019-07-16 23:44:33 +00:00
Anastasia Stulova d6f34bf4d4 [OpenCL] Deduce addr space for pointee of dependent types in instantiation.
Since pointee doesn't require context sensitive addr space deduction
it's easier to handle pointee of dependent types during templ
instantiation.

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

llvm-svn: 366063
2019-07-15 13:02:21 +00:00
Sven van Haastregt 1006a068c6 [OpenCL] Improve diagnostic for placement new
Without an explicit declaration for placement new, clang would reject
uses of placement new with "'default new' is not supported in OpenCL
C++".  This may mislead users into thinking that placement new is not
supported, see e.g. PR42060.

Clarify that placement new requires an explicit declaration.

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

llvm-svn: 364423
2019-06-26 13:31:24 +00:00
Anastasia Stulova 3562edb9c4 [Sema] Fix diagnostic for addr spaces in reference binding
Extend reference binding behavior to account for address spaces.

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

llvm-svn: 364032
2019-06-21 11:36:15 +00:00
Anastasia Stulova 7ca9b978c4 [OpenCL][PR42031] Prevent deducing addr space in type alias.
Similar to typedefs we shouldn't deduce addr space in
type alias.
 
Differential Revision: https://reviews.llvm.org/D62591

llvm-svn: 362611
2019-06-05 14:50:01 +00:00
Anastasia Stulova 5145b1e442 [Sema] Prevent binding incompatible addr space ref to temporaries
References to arbitrary address spaces can't always be bound to
temporaries. This change extends the reference binding logic to
check that the address space of a temporary can be implicitly
converted to the address space in a reference when temporary
materialization is performed.

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

llvm-svn: 362604
2019-06-05 14:03:34 +00:00
Anastasia Stulova d6865b7d71 [OpenCL] Prevent mangling kernel functions.
Kernel function names have to be preserved as in the original
source to be able to access them from the host API side. 

This commit also adds restriction to kernels that prevents them
from being used in overloading, templates, etc.

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

llvm-svn: 360152
2019-05-07 14:22:34 +00:00
Anastasia Stulova 44bb0aa994 [OpenCL] Deduce static data members to __global addr space.
Similarly to static variables in OpenCL, static class data
members should be deduced to __global addr space.

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

llvm-svn: 359789
2019-05-02 14:40:40 +00:00