Author: Mariya Podchishchaeva Date: 2022-02-07T11:57:30+03:00 New Revision: 1cee9608982a866688434223bee44c878ea489b1
URL: https://github.com/llvm/llvm-project/commit/1cee9608982a866688434223bee44c878ea489b1 DIFF: https://github.com/llvm/llvm-project/commit/1cee9608982a866688434223bee44c878ea489b1.diff LOG: [SYCL] Disallow explicit casts between mismatching address spaces Reviewed By: bader Differential Revision: https://reviews.llvm.org/D118935 Added: Modified: clang/lib/Sema/SemaCast.cpp clang/test/CodeGenSYCL/address-space-conversions.cpp clang/test/SemaSYCL/address-space-conversions.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 7ef1732496c21..e9c1116257d66 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -2545,7 +2545,7 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, 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; diff --git a/clang/test/CodeGenSYCL/address-space-conversions.cpp b/clang/test/CodeGenSYCL/address-space-conversions.cpp index e2fb755a29a6c..4f0484443d191 100644 --- a/clang/test/CodeGenSYCL/address-space-conversions.cpp +++ b/clang/test/CodeGenSYCL/address-space-conversions.cpp @@ -35,7 +35,7 @@ void usages() { __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 diff --git a/clang/test/SemaSYCL/address-space-conversions.cpp b/clang/test/SemaSYCL/address-space-conversions.cpp index d2e19b6f901d5..d8758248499de 100644 --- a/clang/test/SemaSYCL/address-space-conversions.cpp +++ b/clang/test/SemaSYCL/address-space-conversions.cpp @@ -55,6 +55,9 @@ void usages() { 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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits