<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="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="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>