Commit Graph

40 Commits

Author SHA1 Message Date
Eli Friedman 62f3ef2b53 [CGCall] Annotate references with "align" attribute.
If we're going to assume references are dereferenceable, we should also
assume they're aligned: otherwise, we can't actually dereference them.

See also D80072.

Differential Revision: https://reviews.llvm.org/D80166
2020-05-19 20:21:30 -07: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
Erik Pilkington de98cf92e3 [CodeGen] Add an alignment attribute to all sret parameters
This fixes a miscompile when the parameter is actually underaligned.
rdar://58316406

Differential revision: https://reviews.llvm.org/D74183
2020-03-24 15:31:57 -04:00
Sven van Haastregt df5a905aa8 [OpenCL] Add ExtVectorElementExpr constant evaluation (PR42387)
Add constexpr evaluation for ExtVectorElementExpr nodes by evaluating
the underlying vector expression.  Add basic folding for the case that
Evaluate does not return an LValue.

Differential Revision: https://reviews.llvm.org/D71133
2019-12-17 11:10:06 +00:00
Sven van Haastregt f3e6a61232 [OpenCL] Handle address space conversions for constexpr (PR44177)
The AST for the constexpr.cl test contains address space conversion
nodes to cast through the implicit generic address space.  These
caused the evaluator to reject the input as constexpr in C++ for
OpenCL mode, whereas the input was considered constexpr in plain C++
mode as the AST won't have address space cast nodes then.

Fixes PR44177.

Differential Revision: https://reviews.llvm.org/D71015
2019-12-09 11:09:16 +00:00
Sven van Haastregt 6236496561 [OpenCL] Fix address space for implicit conversion (PR43145)
Clang was creating a DerivedToBase ImplicitCastExpr that was also
casting between address spaces as part of the second step in the
standard conversion sequence.  Defer the address space conversion to
the third step in the sequence instead, such that we get a separate
ImplicitCastExpr for the address space conversion.

Differential Revision: https://reviews.llvm.org/D70605
2019-12-02 14:20:15 +00:00
Sven van Haastregt 35388dcbbc [OpenCL] Fix address space for base method call (PR43145)
Clang was creating an UncheckedDerivedToBase ImplicitCastExpr that was
also casting between address spaces.  Insert an ImplicitCastExpr node
for doing the address space conversion.

Differential Revision: https://reviews.llvm.org/D69810
2019-11-21 10:39:33 +00:00
Sven van Haastregt 6c5827975c [OpenCL] Fix FileCheck pattern
For this test, FileCheck is not run with the CHECK prefix; it seems
COMMON was intended here.
2019-11-04 15:08:53 +00:00
Sven van Haastregt 82888b78d4 [OpenCL] Fix address space for const method call from nonconst (PR43145)
Patch by Anastasia Stulova and Sven van Haastregt.

Differential Revision: https://reviews.llvm.org/D68781
2019-11-04 13:12:17 +00:00
Sven van Haastregt af6248cbb9 [OpenCL] Preserve addrspace in CGClass (PR43145)
PR43145 revealed two places where Clang was attempting to create a
bitcast without considering the address space of class types during
C++ class code generation.

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

llvm-svn: 375118
2019-10-17 14:12:51 +00:00
Erich Keane 61478ec6ac Make the CXXABIs respect the target's default calling convention.
SPIR targets need to have all functions be SPIR calling convention,
however the CXXABIs were just returning CC_C in all non-'this-CC' cases.

https://reviews.llvm.org/D65294

llvm-svn: 367103
2019-07-26 12:36:12 +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
Marco Antognini 8855963764 [OpenCL] Improve destructor support in C++ for OpenCL
This re-applies r366422 with a fix for Bug PR42665 and a new regression
test.

llvm-svn: 366670
2019-07-22 09:39:13 +00:00
Ilya Biryukov 4f8dc16fcd Revert r366422: [OpenCL] Improve destructor support in C++ for OpenCL
Reason: this commit causes crashes in the clang compiler when building
LLVM Support with libc++, see https://bugs.llvm.org/show_bug.cgi?id=42665
for details.

llvm-svn: 366429
2019-07-18 11:55:33 +00:00
Marco Antognini 83748cc5ab [OpenCL] Improve destructor support in C++ for OpenCL
Summary:
This patch does mainly three things:
 1. It fixes a false positive error detection in Sema that is similar to
    D62156. The error happens when explicitly calling an overloaded
    destructor for different address spaces.
 2. It selects the correct destructor when multiple overloads for
    address spaces are available.
 3. It inserts the expected address space cast when invoking a
    destructor, if needed, and therefore fixes a crash due to the unmet
    assertion in llvm::CastInst::Create.

The following is a reproducer of the three issues:

    struct MyType {
      ~MyType() {}
      ~MyType() __constant {}
    };

    __constant MyType myGlobal{};

    kernel void foo() {
      myGlobal.~MyType(); // 1 and 2.
      // 1. error: cannot initialize object parameter of type
      //    '__generic MyType' with an expression of type '__constant MyType'
      // 2. error: no matching member function for call to '~MyType'
    }

    kernel void bar() {
      // 3. The implicit call to the destructor crashes due to:
      //    Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.
      //    in llvm::CastInst::Create.
      MyType myLocal;
    }

The added test depends on D62413 and covers a few more things than the
above reproducer.

Subscribers: yaxunl, Anastasia, cfe-commits

Tags: #clang

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

llvm-svn: 366422
2019-07-18 10:04:18 +00:00
Anastasia Stulova 960ff0810d [OpenCL][PR41727] Prevent ICE on global dtors
Pass NULL to pointer arg of __cxa_atexit if addr space
is not matching with its param. This doesn't align yet
with how dtors are generated that should be changed too.

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

llvm-svn: 366059
2019-07-15 11:58:10 +00:00
Vyacheslav Zakharin de811d1f51 [clang] Preserve names of addrspacecast'ed values.
Differential Revision: https://reviews.llvm.org/D63846

llvm-svn: 365666
2019-07-10 17:10:05 +00:00
Anastasia Stulova c25ea86d43 [Sema] Diagnose addr space mismatch while constructing objects
If we construct an object in some arbitrary non-default addr space
it should fail unless either:
- There is an implicit conversion from the address space to default
/generic address space.
- There is a matching ctor qualified with an address space that is
either exactly matching or convertible to the address space of an
object.

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

llvm-svn: 363944
2019-06-20 16:23:28 +00:00
Johannes Doerfert 40107ce753 Introduce Value::stripPointerCastsSameRepresentation
This patch allows current users of Value::stripPointerCasts() to force
the result of the function to have the same representation as the value
it was called on. This is useful in various cases, e.g., (non-)null
checks.

In this patch only a single call site was adjusted to fix an existing
misuse that would cause nonnull where they may be wrong. Uses in
attribute deduction and other areas, e.g., D60047, are to be expected.

For a discussion on this topic, please see [0].

[0] http://lists.llvm.org/pipermail/llvm-dev/2018-December/128423.html

Reviewers: hfinkel, arsenm, reames

Subscribers: wdng, hiraditya, bollu, llvm-commits

Tags: #llvm

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

llvm-svn: 362545
2019-06-04 20:21:46 +00:00
Anastasia Stulova 5099aef869 [PR41567][Sema] Fixed cast kind in addr space conversions
This change sets missing cast kind correctly in the address
space conversion case.

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

llvm-svn: 362409
2019-06-03 15:42:36 +00:00
Anastasia Stulova e6cf6c78f8 [OpenCL] Make global ctor init function a kernel
We need to be able to enqueue internal function that initializes
global constructors on the host side. Therefore it has to be
converted to a kernel.

This change factors out common logic for adding kernel metadata
and moves it from CodeGenFunction to CodeGenModule in order to
make it accessible for the extra use case.

Differential revision: https://reviews.llvm.org/D61488

llvm-svn: 360342
2019-05-09 13:55:44 +00:00
Anastasia Stulova 933e305ed9 [OpenCL] Switched CXX mode to be derived from C++17
Differential revision: https://reviews.llvm.org/D61506

llvm-svn: 360330
2019-05-09 11:55:24 +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 26e095e84f [OpenCL] Fix initialisation of this via pointer.
When the expression used to initialise 'this' has a pointer type,
check the address space of the pointee type instead of the pointer
type to decide whether an address space cast is required.
It is the pointee type that carries the address space qualifier.

Fixing PR41674.

Patch by kpet (Kevin Petit)!

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

llvm-svn: 359798
2019-05-02 16:10:50 +00:00
Anastasia Stulova 9b4c6b8c7b [PR41157][OpenCL] Prevent implicit init of local addr space var in C++ mode.
Prevent adding initializers implicitly to variables declared in
local address space. This happens when they get converted into
global variables and therefore theoretically have to be default
initialized in C++.

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

llvm-svn: 357684
2019-04-04 11:08:51 +00:00
Anastasia Stulova 4ce581e5a9 [Sema] Adjust addr space of reference operand in compound assignment
When we create overloads for the builtin compound assignment operators
we need to preserve address space for the reference operand taking it
from the argument that is passed in.

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

llvm-svn: 356475
2019-03-19 16:50:21 +00:00
Anastasia Stulova 6f7c536e08 [Sema] Change addr space diagnostics in casts to follow C++ style.
This change adds a new diagnostic for mismatching address spaces
to be used for C++ casts (only enabled in C style cast for now,
the rest will follow!).

The change extends C-style cast rules to account for address spaces.
It also adds a separate function for address space cast checking that
can be used to map from a separate address space cast operator
addrspace_cast (to be added as a follow up patch).

Note, that after this change clang will no longer allows arbitrary
address space conversions in reinterpret_casts because they can lead
to accidental errors. The implicit safe conversions would still be
allowed.

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

llvm-svn: 355609
2019-03-07 17:06:30 +00:00
Anastasia Stulova 27e5c212ee [PR40778][Sema] Adjust addr space of operands in builtin operators.
Adjust address space for references and pointer operands of builtin operators.

Currently this change only fixes addr space in assignment (= and |=) operator,
that is needed for the test case reported in the bug. Wider support for all
other operations will follow.

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

llvm-svn: 355608
2019-03-07 16:43:41 +00:00
Anastasia Stulova 9404955416 [PR40778] Preserve addr space in Derived to Base cast.
The address space for the Base class pointer when up-casting
from Derived should be taken from the Derived class pointer.

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

llvm-svn: 355606
2019-03-07 16:23:15 +00:00
Anastasia Stulova d3ae87ee0d [PR40778] Add addr space conversion when binding reference to a temporary.
This change fixes temporary materialization to happen in the right
(default) address space when binding to it a reference of different type.

It adds address space conversion afterwards to match the addr space
of a reference.

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

llvm-svn: 355499
2019-03-06 13:02:41 +00:00
Anastasia Stulova eb71ff34e1 [OpenCL] Add generic addr space to the return of implicit assignment.
When creating the prototype of implicit assignment operators the
returned reference to the class should be qualified with the same
addr space as 'this' (i.e. __generic in OpenCL).

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

llvm-svn: 352617
2019-01-30 11:18:08 +00:00
Anastasia Stulova 5cffa45401 [OpenCL] Allow address spaces as method qualifiers.
Methods can now be qualified with address spaces to prevent
undesirable conversions to generic or to provide custom 
implementation to be used if the object is located in certain
memory segments.

This commit extends parsing and standard C++ overloading to
work for an address space of a method (i.e. implicit 'this'
parameter).

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

llvm-svn: 351747
2019-01-21 16:01:38 +00:00
Anastasia Stulova d1986d1b5a [OpenCL] Set generic addr space of 'this' in special class members.
Set address spaces of 'this' param correctly for implicit special
class members.

This also changes initialization conversion sequence to separate
address space conversion from other qualifiers in case of binding
reference to a temporary. In this case address space conversion  
should happen after the binding (unlike for other quals). This is
needed to materialize it correctly in the alloca address space.

Initial patch by Mikael Nilssoni!

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

llvm-svn: 351053
2019-01-14 11:44:22 +00:00
Mikael Nilsson 9d2872db74 [OpenCL] Add generic AS to 'this' pointer
Address spaces are cast into generic before invoking the constructor.

Added support for a trailing Qualifiers object in FunctionProtoType.

Note: This recommits the previously reverted patch, 
      but now it is commited together with a fix for lldb.

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

llvm-svn: 349019
2018-12-13 10:15:27 +00:00
Mikael Nilsson 90646732bf Revert "[OpenCL] Add generic AS to 'this' pointer"
Reverting because the patch broke lldb.

llvm-svn: 348931
2018-12-12 15:06:16 +00:00
Mikael Nilsson 78de84719b [OpenCL] Add generic AS to 'this' pointer
Address spaces are cast into generic before invoking the constructor.

Added support for a trailing Qualifiers object in FunctionProtoType.

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

llvm-svn: 348927
2018-12-12 14:11:59 +00:00
Andrew Savonichev 87a7e436c0 [OpenCL] Fix for TBAA information of pointer after addresspacecast
Summary: When addresspacecast is generated resulting pointer should preserve TBAA information from original value.

Reviewers: rjmccall, yaxunl, Anastasia

Reviewed By: rjmccall

Subscribers: asavonic, kosarev, cfe-commits, llvm-commits

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

llvm-svn: 348919
2018-12-12 09:51:23 +00:00
Anastasia Stulova 6a4c34689e [OpenCL] Improve diags for addr spaces in templates
Fix ICEs on template instantiations that were leading to
the creation of invalid code patterns with address spaces.

Incorrect cases are now diagnosed properly.

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

llvm-svn: 347865
2018-11-29 14:11:15 +00:00
Anastasia Stulova 7eb6938c48 [OpenCL] Fix address space deduction in template args.
Don't deduce address spaces for non-pointer-like types
in template args.

Fixes PR38603!

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

llvm-svn: 347189
2018-11-19 11:00:14 +00:00
Anastasia Stulova 04307941e2 [OpenCL] Enable address spaces for references in C++
Added references to the addr spaces deduction and enabled
CL2.0 features (program scope variables and storage class
qualifiers) to work in C++ mode too.

Fixed several address space conversion issues in CodeGen 
for references.

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

llvm-svn: 347059
2018-11-16 16:22:56 +00:00