r357684 - [PR41157][OpenCL] Prevent implicit init of local addr space var in C++ mode.
Anastasia Stulova via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 4 04:08:51 PDT 2019
Author: stulova
Date: Thu Apr 4 04:08:51 2019
New Revision: 357684
URL: http://llvm.org/viewvc/llvm-project?rev=357684&view=rev
Log:
[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
Added:
cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=357684&r1=357683&r2=357684&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Apr 4 04:08:51 2019
@@ -11682,7 +11682,11 @@ void Sema::ActOnUninitializedDecl(Decl *
setFunctionHasBranchProtectedScope();
}
}
-
+ // In OpenCL, we can't initialize objects in the __local address space,
+ // even implicitly, so don't synthesize an implicit initializer.
+ if (getLangOpts().OpenCL &&
+ Var->getType().getAddressSpace() == LangAS::opencl_local)
+ return;
// C++03 [dcl.init]p9:
// If no initializer is specified for an object, and the
// object is of (possibly cv-qualified) non-POD class type (or
Modified: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl?rev=357684&r1=357683&r2=357684&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl (original)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl Thu Apr 4 04:08:51 2019
@@ -150,15 +150,13 @@ __kernel void test__global() {
TEST(__local)
// COMMON-LABEL: _Z11test__localv
-// EXPL: @__cxa_guard_acquire
-// Test the address space of 'this' when invoking a constructor for an object in non-default address space
-// EXPL: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
+// Test that we don't initialize an object in local address space.
+// EXPL-NOT: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
// Test the address space of 'this' when invoking a method.
// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
-
// Test the address space of 'this' when invoking copy-constructor.
// COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
// EXPL: call void @_ZNU3AS41CC1ERU3AS4KS_(%class.C addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
Added: cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl?rev=357684&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl (added)
+++ cfe/trunk/test/CodeGenOpenCLCXX/local_addrspace_init.cl Thu Apr 4 04:08:51 2019
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -triple spir -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s
+
+// Test that we don't initialize local address space objects.
+//CHECK: @_ZZ4testvE1i = internal addrspace(3) global i32 undef
+//CHECK: @_ZZ4testvE2ii = internal addrspace(3) global %class.C undef
+class C {
+ int i;
+};
+
+kernel void test() {
+ __local int i;
+ __local C ii;
+ // FIXME: In OpenCL C we don't accept initializers for local
+ // address space variables. User defined initialization could
+ // make sense, but would it mean that all work items need to
+ // execute it? Potentially disallowing any initialization would
+ // make things easier and assingments can be used to set specific
+ // values. This rules should make it consistent with OpenCL C.
+ //__local C c();
+}
More information about the cfe-commits
mailing list