r198417 - [OpenCL] Variables in the constant address space must be initialized.
Joey Gouly
joey.gouly at gmail.com
Fri Jan 3 06:16:55 PST 2014
Author: joey
Date: Fri Jan 3 08:16:55 2014
New Revision: 198417
URL: http://llvm.org/viewvc/llvm-project?rev=198417&view=rev
Log:
[OpenCL] Variables in the constant address space must be initialized.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Misc/languageOptsOpenCL.cl
cfe/trunk/test/SemaOpenCL/event_t.cl
cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=198417&r1=198416&r2=198417&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jan 3 08:16:55 2014
@@ -6714,6 +6714,8 @@ def err_opencl_global_invalid_addr_space
def err_opencl_no_main : Error<"%select{function|kernel}0 cannot be called 'main'">;
def err_opencl_kernel_attr :
Error<"attribute %0 can only be applied to a kernel function">;
+def err_opencl_constant_no_init : Error<
+ "variable in constant address space must be initialized">;
} // end of sema category
let CategoryName = "OpenMP Issue" in {
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=198417&r1=198416&r2=198417&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan 3 08:16:55 2014
@@ -8589,6 +8589,16 @@ void Sema::ActOnUninitializedDecl(Decl *
return;
}
+ // OpenCL v1.1 s6.5.3: variables declared in the constant address space must
+ // be initialized.
+ if (!Var->isInvalidDecl() &&
+ Var->getType().getAddressSpace() == LangAS::opencl_constant &&
+ !Var->getInit()) {
+ Diag(Var->getLocation(), diag::err_opencl_constant_no_init);
+ Var->setInvalidDecl();
+ return;
+ }
+
switch (Var->isThisDeclarationADefinition()) {
case VarDecl::Definition:
if (!Var->isStaticDataMember() || !Var->getAnyInitializer())
Modified: cfe/trunk/test/Misc/languageOptsOpenCL.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/languageOptsOpenCL.cl?rev=198417&r1=198416&r2=198417&view=diff
==============================================================================
--- cfe/trunk/test/Misc/languageOptsOpenCL.cl (original)
+++ cfe/trunk/test/Misc/languageOptsOpenCL.cl Fri Jan 3 08:16:55 2014
@@ -3,17 +3,19 @@
// Test the forced language options for OpenCL are set correctly.
-__constant int v0[(sizeof(int) == 4) -1];
-__constant int v1[(__alignof(int) == 4) -1];
-__constant int v2[(sizeof(long) == 8) -1];
-__constant int v3[(__alignof(long) == 8) -1];
-__constant int v4[(sizeof(long long) == 16) -1];
-__constant int v5[(__alignof(long long) == 16) -1];
-__constant int v6[(sizeof(float) == 4) -1];
-__constant int v7[(__alignof(float) == 4) -1];
+kernel void test() {
+ int v0[(sizeof(int) == 4) - 1];
+ int v1[(__alignof(int)== 4) - 1];
+ int v2[(sizeof(long) == 8) - 1];
+ int v3[(__alignof(long)== 8) - 1];
+ int v4[(sizeof(long long) == 16) - 1];
+ int v5[(__alignof(long long)== 16) - 1];
+ int v6[(sizeof(float) == 4) - 1];
+ int v7[(__alignof(float)== 4) - 1];
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-__constant int v8[(sizeof(double)==8) -1];
-__constant int v9[(__alignof(double)==8) -1];
+ int v8[(sizeof(double) == 8) - 1];
+ int v9[(__alignof(double)== 8) - 1];
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
-__constant int v10[(sizeof(half) == 2) -1];
-__constant int v11[(__alignof(half) == 2) -1];
+ int v10[(sizeof(half) == 2) - 1];
+ int v11[(__alignof(half) == 2) - 1];
+}
Modified: cfe/trunk/test/SemaOpenCL/event_t.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/event_t.cl?rev=198417&r1=198416&r2=198417&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/event_t.cl (original)
+++ cfe/trunk/test/SemaOpenCL/event_t.cl Fri Jan 3 08:16:55 2014
@@ -4,7 +4,7 @@ event_t glb_evt; // expected-error {{the
constant struct evt_s {
event_t evt; // expected-error {{the event_t type cannot be used to declare a structure or union field}}
-} evt_str;
+} evt_str = {0};
void foo(event_t evt); // expected-note {{passing argument to parameter 'evt' here}}
Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl?rev=198417&r1=198416&r2=198417&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl Fri Jan 3 08:16:55 2014
@@ -20,11 +20,11 @@ __attribute__((work_group_size_hint(8,16
__attribute__((vec_type_hint(char))) void kernel10(){} // expected-error {{attribute 'vec_type_hint' can only be applied to a kernel}}
-constant int foo1 __attribute__((reqd_work_group_size(8,16,32))); // expected-error {{'reqd_work_group_size' attribute only applies to functions}}
+constant int foo1 __attribute__((reqd_work_group_size(8,16,32))) = 0; // expected-error {{'reqd_work_group_size' attribute only applies to functions}}
-constant int foo2 __attribute__((work_group_size_hint(8,16,32))); // expected-error {{'work_group_size_hint' attribute only applies to functions}}
+constant int foo2 __attribute__((work_group_size_hint(8,16,32))) = 0; // expected-error {{'work_group_size_hint' attribute only applies to functions}}
-constant int foo3 __attribute__((vec_type_hint(char))); // expected-error {{'vec_type_hint' attribute only applies to functions}}
+constant int foo3 __attribute__((vec_type_hint(char))) = 0; // expected-error {{'vec_type_hint' attribute only applies to functions}}
void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' attribute only applies to functions}}
int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}}
More information about the cfe-commits
mailing list