<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hi <font style="font-size:11pt" face="Calibri, sans-serif" color="#000000">
Benjamin</font>,</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Thanks for reporting the issues, I think this should fix it:</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"></p>
<div>diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp<br>
index 1fe553000b..9ff631401f 100644<br>
--- a/lib/Sema/SemaType.cpp<br>
+++ b/lib/Sema/SemaType.cpp<br>
@@ -7201,7 +7201,7 @@ static void deduceOpenCLImplicitAddrSpace(TypeProcessingState &State,<br>
       (T->isVoidType() && !IsPointee))<br>
     return;<br>
 <br>
-  LangAS ImpAddr;<br>
+  LangAS ImpAddr = LangAS::Default;<br>
   // Put OpenCL automatic variable in private address space.<br>
   // OpenCL v1.2 s6.5:<br>
   // The default address space name for arguments to a function in a<br>
</div>
<div><br>
</div>
<div>I am trying to reproduce and test the problem now to commit the fix.</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Anastasia<br>
</div>
<p></p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> Benjamin Kramer <benny.kra@gmail.com><br>
<b>Sent:</b> 19 November 2018 11:08<br>
<b>To:</b> Anastasia Stulova<br>
<b>Cc:</b> cfe-commits<br>
<b>Subject:</b> Re: r347189 - [OpenCL] Fix address space deduction in template args.</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">clang gives me this:
<div><br>
</div>
<div>
<div>llvm/tools/clang/lib/Sema/SemaType.cpp:7230:11: error: variable 'ImpAddr' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]</div>
<div>      if (D.getContext() == DeclaratorContext::TemplateArgContext) {</div>
<div>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</div>
<div>llvm/tools/clang/lib/Sema/SemaType.cpp:7244:55: note: uninitialized use occurs here</div>
<div>  T = State.getSema().Context.getAddrSpaceQualType(T, ImpAddr);</div>
<div>                                                      ^~~~~~~</div>
<div>llvm/tools/clang/lib/Sema/SemaType.cpp:7230:7: note: remove the 'if' if its condition is always false</div>
<div>      if (D.getContext() == DeclaratorContext::TemplateArgContext) {</div>
<div>      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</div>
<div>llvm/tools/clang/lib/Sema/SemaType.cpp:7208:3: note: variable 'ImpAddr' is declared here</div>
<div>  LangAS ImpAddr;</div>
</div>
</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr">On Mon, Nov 19, 2018 at 12:02 PM Anastasia Stulova via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
Author: stulova<br>
Date: Mon Nov 19 03:00:14 2018<br>
New Revision: 347189<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=347189&view=rev" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=347189&view=rev</a><br>
Log:<br>
[OpenCL] Fix address space deduction in template args.<br>
<br>
Don't deduce address spaces for non-pointer-like types<br>
in template args.<br>
<br>
Fixes PR38603!<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D54634" rel="noreferrer" target="_blank">
https://reviews.llvm.org/D54634</a><br>
<br>
<br>
Added:<br>
    cfe/trunk/test/CodeGenOpenCLCXX/<a href="http://template-address-spaces.cl" rel="noreferrer" target="_blank">template-address-spaces.cl</a><br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaType.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347189&r1=347188&r2=347189&view=diff" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347189&r1=347188&r2=347189&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaType.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Nov 19 03:00:14 2018<br>
@@ -7227,7 +7227,9 @@ static void deduceOpenCLImplicitAddrSpac<br>
     if (IsPointee) {<br>
       ImpAddr = LangAS::opencl_generic;<br>
     } else {<br>
-      if (D.getContext() == DeclaratorContext::FileContext) {<br>
+      if (D.getContext() == DeclaratorContext::TemplateArgContext) {<br>
+        // Do not deduce address space for non-pointee type in template args<br>
+      } else if (D.getContext() == DeclaratorContext::FileContext) {<br>
         ImpAddr = LangAS::opencl_global;<br>
       } else {<br>
         if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||<br>
<br>
Added: cfe/trunk/test/CodeGenOpenCLCXX/<a href="http://template-address-spaces.cl" rel="noreferrer" target="_blank">template-address-spaces.cl</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl?rev=347189&view=auto" rel="noreferrer" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl?rev=347189&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenOpenCLCXX/<a href="http://template-address-spaces.cl" rel="noreferrer" target="_blank">template-address-spaces.cl</a> (added)<br>
+++ cfe/trunk/test/CodeGenOpenCLCXX/<a href="http://template-address-spaces.cl" rel="noreferrer" target="_blank">template-address-spaces.cl</a> Mon Nov 19 03:00:14 2018<br>
@@ -0,0 +1,31 @@<br>
+// RUN: %clang_cc1 -cl-std=c++ %s -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s<br>
+<br>
+template <typename T><br>
+struct S{<br>
+  T a;<br>
+  T foo();<br>
+};<br>
+<br>
+template<typename T><br>
+T S<T>::foo() { return a;}<br>
+<br>
+//CHECK: %struct.S = type { i32 }<br>
+//CHECK: %struct.S.0 = type { i32 addrspace(4)* }<br>
+//CHECK: %struct.S.1 = type { i32 addrspace(1)* }<br>
+<br>
+//CHECK: i32 @_ZN1SIiE3fooEv(%struct.S* %this)<br>
+//CHECK: i32 addrspace(4)* @_ZN1SIPU3AS4iE3fooEv(%struct.S.0* %this)<br>
+//CHECK: i32 addrspace(1)* @_ZN1SIPU3AS1iE3fooEv(%struct.S.1* %this)<br>
+<br>
+void bar(){<br>
+  S<int> sint;<br>
+  S<int*> sintptr;<br>
+  S<__global int*> sintptrgl;<br>
+  // FIXME: Preserve AS in TreeTransform<br>
+  //S<__global int> sintgl;<br>
+<br>
+  sint.foo();<br>
+  sintptr.foo();<br>
+  sintptrgl.foo();<br>
+  //sintgl.foo();<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>