r347189 - [OpenCL] Fix address space deduction in template args.

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 19 03:08:16 PST 2018


clang gives me this:

llvm/tools/clang/lib/Sema/SemaType.cpp:7230:11: error: variable 'ImpAddr'
is used uninitialized whenever 'if' condition is true
[-Werror,-Wsometimes-uninitialized]
      if (D.getContext() == DeclaratorContext::TemplateArgContext) {
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
llvm/tools/clang/lib/Sema/SemaType.cpp:7244:55: note: uninitialized use
occurs here
  T = State.getSema().Context.getAddrSpaceQualType(T, ImpAddr);
                                                      ^~~~~~~
llvm/tools/clang/lib/Sema/SemaType.cpp:7230:7: note: remove the 'if' if its
condition is always false
      if (D.getContext() == DeclaratorContext::TemplateArgContext) {
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
llvm/tools/clang/lib/Sema/SemaType.cpp:7208:3: note: variable 'ImpAddr' is
declared here
  LangAS ImpAddr;

On Mon, Nov 19, 2018 at 12:02 PM Anastasia Stulova via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: stulova
> Date: Mon Nov 19 03:00:14 2018
> New Revision: 347189
>
> URL: http://llvm.org/viewvc/llvm-project?rev=347189&view=rev
> Log:
> [OpenCL] Fix address space deduction in template args.
>
> Don't deduce address spaces for non-pointer-like types
> in template args.
>
> Fixes PR38603!
>
> Differential Revision: https://reviews.llvm.org/D54634
>
>
> Added:
>     cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl
> Modified:
>     cfe/trunk/lib/Sema/SemaType.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347189&r1=347188&r2=347189&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Nov 19 03:00:14 2018
> @@ -7227,7 +7227,9 @@ static void deduceOpenCLImplicitAddrSpac
>      if (IsPointee) {
>        ImpAddr = LangAS::opencl_generic;
>      } else {
> -      if (D.getContext() == DeclaratorContext::FileContext) {
> +      if (D.getContext() == DeclaratorContext::TemplateArgContext) {
> +        // Do not deduce address space for non-pointee type in template
> args
> +      } else if (D.getContext() == DeclaratorContext::FileContext) {
>          ImpAddr = LangAS::opencl_global;
>        } else {
>          if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static
> ||
>
> Added: cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl?rev=347189&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl (added)
> +++ cfe/trunk/test/CodeGenOpenCLCXX/template-address-spaces.cl Mon Nov 19
> 03:00:14 2018
> @@ -0,0 +1,31 @@
> +// RUN: %clang_cc1 -cl-std=c++ %s -emit-llvm -o - -O0 -triple
> spir-unknown-unknown | FileCheck %s
> +
> +template <typename T>
> +struct S{
> +  T a;
> +  T foo();
> +};
> +
> +template<typename T>
> +T S<T>::foo() { return a;}
> +
> +//CHECK: %struct.S = type { i32 }
> +//CHECK: %struct.S.0 = type { i32 addrspace(4)* }
> +//CHECK: %struct.S.1 = type { i32 addrspace(1)* }
> +
> +//CHECK: i32 @_ZN1SIiE3fooEv(%struct.S* %this)
> +//CHECK: i32 addrspace(4)* @_ZN1SIPU3AS4iE3fooEv(%struct.S.0* %this)
> +//CHECK: i32 addrspace(1)* @_ZN1SIPU3AS1iE3fooEv(%struct.S.1* %this)
> +
> +void bar(){
> +  S<int> sint;
> +  S<int*> sintptr;
> +  S<__global int*> sintptrgl;
> +  // FIXME: Preserve AS in TreeTransform
> +  //S<__global int> sintgl;
> +
> +  sint.foo();
> +  sintptr.foo();
> +  sintptrgl.foo();
> +  //sintgl.foo();
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181119/cdc82639/attachment-0001.html>


More information about the cfe-commits mailing list