[PATCH] D118935: [SYCL] Disallow explicit casts between mismatching address spaces
Mariya Podchishchaeva via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 3 11:54:54 PST 2022
Fznamznon created this revision.
Fznamznon added a reviewer: bader.
Herald added subscribers: Naghasan, Anastasia, ebevhan, yaxunl.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118935
Files:
clang/lib/Sema/SemaCast.cpp
clang/test/CodeGenSYCL/address-space-conversions.cpp
clang/test/SemaSYCL/address-space-conversions.cpp
Index: clang/test/SemaSYCL/address-space-conversions.cpp
===================================================================
--- clang/test/SemaSYCL/address-space-conversions.cpp
+++ clang/test/SemaSYCL/address-space-conversions.cpp
@@ -55,6 +55,9 @@
baz(NoAS); // expected-error {{no matching function for call to 'baz'}}
__attribute__((opencl_local)) int *l = NoAS; // expected-error {{cannot initialize a variable of type '__local int *' with an lvalue of type 'int *'}}
+ // Explicit casts between disjoint address spaces are disallowed
+ GLOB = (__attribute__((opencl_global)) int *)PRIV; // expected-error {{C-style cast from '__private int *' to '__global int *' converts between mismatching address spaces}}
+
(void)static_cast<int *>(GLOB);
(void)static_cast<void *>(GLOB);
int *i = GLOB;
Index: clang/test/CodeGenSYCL/address-space-conversions.cpp
===================================================================
--- clang/test/CodeGenSYCL/address-space-conversions.cpp
+++ clang/test/CodeGenSYCL/address-space-conversions.cpp
@@ -35,7 +35,7 @@
__attribute__((opencl_global_host)) int *GLOBHOST;
// Explicit conversions
- // From names address spaces to default address space
+ // From named address spaces to default address space
// CHECK-DAG: [[GLOB_LOAD:%[a-zA-Z0-9]+]] = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(4)* [[GLOB]].ascast
// CHECK-DAG: [[GLOB_CAST:%[a-zA-Z0-9]+]] = addrspacecast i32 addrspace(1)* [[GLOB_LOAD]] to i32 addrspace(4)*
// CHECK-DAG: store i32 addrspace(4)* [[GLOB_CAST]], i32 addrspace(4)* addrspace(4)* [[NoAS]].ascast
Index: clang/lib/Sema/SemaCast.cpp
===================================================================
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2545,7 +2545,7 @@
static TryCastResult TryAddressSpaceCast(Sema &Self, ExprResult &SrcExpr,
QualType DestType, bool CStyle,
unsigned &msg, CastKind &Kind) {
- if (!Self.getLangOpts().OpenCL)
+ if (!Self.getLangOpts().OpenCL && !Self.getLangOpts().SYCLIsDevice)
// FIXME: As compiler doesn't have any information about overlapping addr
// spaces at the moment we have to be permissive here.
return TC_NotApplicable;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118935.405733.patch
Type: text/x-patch
Size: 2333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220203/e8e54020/attachment.bin>
More information about the cfe-commits
mailing list