]> granicus.if.org Git - clang/commitdiff
[OpenCL] Variables in the constant address space must be initialized.
authorJoey Gouly <joey.gouly@gmail.com>
Fri, 3 Jan 2014 14:16:55 +0000 (14:16 +0000)
committerJoey Gouly <joey.gouly@gmail.com>
Fri, 3 Jan 2014 14:16:55 +0000 (14:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198417 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/Misc/languageOptsOpenCL.cl
test/SemaOpenCL/event_t.cl
test/SemaOpenCL/invalid-kernel-attrs.cl

index f803ecbd52bb6eb302a49ca9ad5e5863d7a975a5..f7017bf315f51d8a5cf62431f71263f5fcfe6aab 100644 (file)
@@ -6714,6 +6714,8 @@ def err_opencl_global_invalid_addr_space : Error<
 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 {
index 42e1564fb5cb1f48e04e14d073959e09a5987958..532aa22177053e7788ff2209cefa65a63d24aabf 100644 (file)
@@ -8589,6 +8589,16 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl,
       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())
index c81db995808f1c80f9ff12a1945fb12a35e97a15..82a8f3614f378bace73b06c6365e0b7dc99f07df 100644 (file)
@@ -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];
+}
index 5ab5c1011a623d199d15cba49187bad423d66500..e09883948cc6d6af112f2ac8db34b5c6fba443cd 100644 (file)
@@ -4,7 +4,7 @@ event_t glb_evt; // expected-error {{the event_t type cannot be used to declare
 
 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}}
 
index 81ce1227cbbbfae9eb0938e361d508501b1c9933..83298369d3a7ca5fadc242bcc3407765ef46b44b 100644 (file)
@@ -20,11 +20,11 @@ __attribute__((work_group_size_hint(8,16,32))) void kernel9(){} // expected-erro
 
 __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}}