[PATCH] D21567: [OpenCL] Generate struct type for sampler_t and function call for the initializer

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 19 11:24:39 PDT 2016


yaxunl added inline comments.

================
Comment at: lib/Sema/SemaInit.cpp:6917-6929
@@ -6915,4 +6916,15 @@
             << SourceType;
-      } else if (Entity.getKind() != InitializedEntity::EK_Variable) {
-        llvm_unreachable("Invalid EntityKind!");
+          break;
+        } else if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Init)) {
+          auto Var = cast<VarDecl>(DRE->getDecl());
+          if (!Var->hasGlobalStorage()) {
+            CurInit = ImplicitCastExpr::Create(S.Context, Step->Type,
+                                               CK_LValueToRValue, CurInit.get(),
+                                               /*BasePath=*/nullptr, VK_RValue);
+            break;
+          }
+          Init = cast<ImplicitCastExpr>(const_cast<Expr*>(
+            Var->getInit()))->getSubExpr();
+          SourceType = Init->getType();
+        }
       }
----------------
Anastasia wrote:
> It would be nice to put some comments here summarizing your description!
> 
> Btw, I don't think it's covered in testing yet, isn't it?
Added detailed comments.

I only missed passing sampler parameter as function call argument. Now added.

================
Comment at: lib/Sema/SemaInit.cpp:6918
@@ +6917,3 @@
+          break;
+        } else if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Init)) {
+          auto Var = cast<VarDecl>(DRE->getDecl());
----------------
Anastasia wrote:
> I don't get why this level of indirection is added? Should the variable initialization be handled elsewhere?
For global variables, since we cannot initialize them with a function call `__translate_sampler_initializer`, we have to take their initializer and pass them to a function call.

================
Comment at: test/SemaOpenCL/sampler_t.cl:55
@@ -30,2 +54,2 @@
 
-sampler_t bad(); //expected-error{{declaring function return value of type 'sampler_t' is not allowed}}
+sampler_t bad(void); //expected-error{{declaring function return value of type 'sampler_t' is not allowed}}
----------------
Anastasia wrote:
> Why was this change required?
Since i added a run with spir triple, there is an extra error msg emitted:

function with no prototype cannot use the spir_function calling convention

adding void argument suppresses this error msg.


https://reviews.llvm.org/D21567





More information about the cfe-commits mailing list