summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Liao <michael.hliao@gmail.com>2019-09-19 21:26:18 +0000
committerMichael Liao <michael.hliao@gmail.com>2019-09-19 21:26:18 +0000
commit095b0e84abfea76c8c5d58468e2b0de5c7835f0b (patch)
tree7cd739d70e8d8c49b5bb3131cde2de9a9e7df7a4
parentd5b8a7c61f35256c09c45a6ce9937c836617ea05 (diff)
downloadclang-095b0e84abfea76c8c5d58468e2b0de5c7835f0b.tar.gz
[CUDA][HIP] Re-apply part of r372318.
- r372318 causes violation of `use-of-uninitialized-value` detected by MemorySanitizer. Once `Viable` field is set to false, `FailureKind` needs setting as well as it will be checked during destruction if `Viable` is not true. - Revert the part trying to skip `std::vector` erasing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372356 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaOverload.cpp6
-rw-r--r--test/SemaCUDA/function-overload.cu17
-rw-r--r--test/SemaCUDA/implicit-member-target-collision-cxx11.cu6
3 files changed, 25 insertions, 4 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 9cf778f934..6887cdd7ee 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -9422,13 +9422,15 @@ OverloadCandidateSet::BestViableFunction(Sema &S, SourceLocation Loc,
const FunctionDecl *Caller = dyn_cast<FunctionDecl>(S.CurContext);
bool ContainsSameSideCandidate =
llvm::any_of(Candidates, [&](OverloadCandidate *Cand) {
- return Cand->Function &&
+ // Check viable function only.
+ return Cand->Viable && Cand->Function &&
S.IdentifyCUDAPreference(Caller, Cand->Function) ==
Sema::CFP_SameSide;
});
if (ContainsSameSideCandidate) {
auto IsWrongSideCandidate = [&](OverloadCandidate *Cand) {
- return Cand->Function &&
+ // Check viable function only to avoid unnecessary data copying/moving.
+ return Cand->Viable && Cand->Function &&
S.IdentifyCUDAPreference(Caller, Cand->Function) ==
Sema::CFP_WrongSide;
};
diff --git a/test/SemaCUDA/function-overload.cu b/test/SemaCUDA/function-overload.cu
index 1d78636a70..b9efd1c09e 100644
--- a/test/SemaCUDA/function-overload.cu
+++ b/test/SemaCUDA/function-overload.cu
@@ -402,3 +402,20 @@ __host__ void test_host_template_overload() {
__device__ void test_device_template_overload() {
template_overload(1); // OK. Attribute-based overloading picks __device__ variant.
}
+
+// Two classes with `operator-` defined. One of them is device only.
+struct C1;
+struct C2;
+__device__
+int operator-(const C1 &x, const C1 &y);
+int operator-(const C2 &x, const C2 &y);
+
+template <typename T>
+__host__ __device__ int constexpr_overload(const T &x, const T &y) {
+ return x - y;
+}
+
+// Verify that function overloading doesn't prune candidate wrongly.
+int test_constexpr_overload(C2 &x, C2 &y) {
+ return constexpr_overload(x, y);
+}
diff --git a/test/SemaCUDA/implicit-member-target-collision-cxx11.cu b/test/SemaCUDA/implicit-member-target-collision-cxx11.cu
index 7aa1dd3f20..06015ed0d6 100644
--- a/test/SemaCUDA/implicit-member-target-collision-cxx11.cu
+++ b/test/SemaCUDA/implicit-member-target-collision-cxx11.cu
@@ -74,11 +74,13 @@ struct B4_with_device_copy_ctor {
struct C4_with_collision : A4_with_host_copy_ctor, B4_with_device_copy_ctor {
};
-// expected-note@-3 {{copy constructor of 'C4_with_collision' is implicitly deleted because base class 'B4_with_device_copy_ctor' has no copy constructor}}
+// expected-note@-3 {{candidate constructor (the implicit copy constructor) not viable: call to invalid function from __host__ function}}
+// expected-note@-4 {{implicit copy constructor inferred target collision: call to both __host__ and __device__ members}}
+// expected-note@-5 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
void hostfoo4() {
C4_with_collision c;
- C4_with_collision c2 = c; // expected-error {{call to implicitly-deleted copy constructor of 'C4_with_collision'}}
+ C4_with_collision c2 = c; // expected-error {{no matching constructor for initialization of 'C4_with_collision'}}
}
//------------------------------------------------------------------------------