Debian Codegraph @

external/llvm/releases/12.0.0/patches_external/OpenCL-Fix-default-address-space-in-template-argumen.patch

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 From 0c65993be186640463ac90415113474d35889dbb Mon Sep 17 00:00:00 2001
10 From: Anastasia Stulova <[email protected]>
11 Date: Thu, 4 Feb 2021 13:46:11 +0000
12 Subject: [PATCH] [OpenCL] Fix default address space in template argument
13 deduction.
14
15 When deducing a reference type for forwarding references prevent
16 adding default address space of a template argument if it is given.
17
18 This got reported in PR48896 because in OpenCL all parameters are
19 in private address space and therefore when we initialize a
20 forwarding reference with a parameter we should just inherit the
21 address space from it i.e. keep __private instead of __generic.
22
23 Tags: #clang
24
25 Differential Revision: https://reviews.llvm.org/D95624
26 ---
27 clang/lib/Sema/SemaTemplateDeduction.cpp | 2 +-
28 .../SemaOpenCLCXX/address-space-templates.cl | 17 +++++++++++++++--
29 2 files changed, 16 insertions(+), 3 deletions(-)
30
31 diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
32 index ee4316e7a632..6336f3b99452 100644
33 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp
34 +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
35 @@ -3869,7 +3869,7 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
36 // "lvalue reference to A" is used in place of A for type deduction.
37 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
38 Arg->isLValue()) {
39 - if (S.getLangOpts().OpenCL)
40 + if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace())
41 ArgType = S.Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
42 ArgType = S.Context.getLValueReferenceType(ArgType);
43 }
44 diff --git a/clang/test/SemaOpenCLCXX/address-space-templates.cl b/clang/test/SemaOpenCLCXX/address-space-templates.cl
45 index be187de5684b..b7db0e6de3d2 100644
46 --- a/clang/test/SemaOpenCLCXX/address-space-templates.cl
47 +++ b/clang/test/SemaOpenCLCXX/address-space-templates.cl
48 @@ -1,4 +1,4 @@
49 -//RUN: %clang_cc1 %s -cl-std=clc++ -pedantic -verify -fsyntax-only
50 +//RUN: %clang_cc1 %s -cl-std=clc++ -pedantic -verify -ast-dump | FileCheck %s
51
52 template <typename T>
53 struct S {
54 @@ -28,8 +28,10 @@ template <class _Tp> struct as_pointer {
55 typedef typename remove_reference<_Tp>::type* type;
56 };
57
58 +// Check address space deduction in template parameter deduction.
59 struct rep {
60 - // CHECK |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep &__private) __generic'
61 + // When there is no address space on a reference use __generic.
62 + // CHECK: |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep &__private) __generic'
63 template<class U, class = typename as_pointer<U>::type>
64 rep(U&& v) {}
65 };
66 @@ -39,11 +41,22 @@ struct rep_outer : private rep {
67 : rep(0) {}
68 };
69
70 +
71 +template<class T, class F>
72 +void foo4(T t, F f){
73 + f(t);
74 +}
75 +
76 void bar() {
77 S<const __global int> sintgl; // expected-note{{in instantiation of template class 'S<const __global int>' requested here}}
78
79 foo1<__local int>(1); // expected-error{{no matching function for call to 'foo1'}}
80 foo2<__global int>(0);
81 foo3<__global int>(); // expected-note{{in instantiation of function template specialization 'foo3<__global int>' requested here}}
82 +
83 rep_outer r;
84 + int i;
85 + // Preserve the address space of the type in forwarding reference.
86 + // CHECK: CXXMethodDecl {{.*}} operator() 'void (__private int &__private) const __generic'
87 + foo4(i, [](auto&& x){;});
88 }
89 --
90 2.25.1
91