llvm-project
103 строки · 4.3 Кб
1// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify=dev,com %s \
2// RUN: -std=c++11 -fgpu-defer-diag
3// RUN: %clang_cc1 -fsyntax-only -verify=host,com %s \
4// RUN: -std=c++11 -fgpu-defer-diag
5// RUN: %clang_cc1 -fopenmp -fsyntax-only -verify=host,com %s \
6// RUN: -std=c++11 -fgpu-defer-diag
7
8// With -fgpu-defer-diag, clang defers overloading resolution induced
9// diagnostics when the full candidates set include host device
10// functions or wrong-sided candidates. This roughly matches nvcc's
11// behavior.
12
13#include "Inputs/cuda.h"
14
15// When callee is called by a host function with integer arguments, there is an error for ambiguity.
16// It should be deferred since it involves wrong-sided candidates.
17__device__ void callee(int);
18__host__ void callee(float); // host-note {{candidate function}}
19__host__ void callee(double); // host-note {{candidate function}}
20
21// When callee2 is called by a device function without arguments, there is an error for 'no matching function'.
22// It should be deferred since it involves wrong-sided candidates.
23__host__ void callee2(); // dev-note{{candidate function not viable: call to __host__ function from __device__ function}}
24
25// When callee3 is called by a device function without arguments, there is an error for 'no matching function'.
26// It should be deferred since it involves wrong-sided candidates.
27__host__ void callee3(); // dev-note{{candidate function not viable: call to __host__ function from __device__ function}}
28__device__ void callee3(int); // dev-note{{candidate function not viable: requires 1 argument, but 0 were provided}}
29
30// When callee4 is called by a host or device function without arguments, there is an error for 'no matching function'.
31// It should be immediate since it involves no wrong-sided candidates (it is not a viable candiate due to signature).
32__host__ void callee4(int); // com-note 2{{candidate function not viable: requires 1 argument, but 0 were provided}}
33
34// When callee5 is called by a host function with integer arguments, there is an error for ambiguity.
35// It should be immediate since it involves no wrong-sided candidates.
36__host__ void callee5(float); // com-note {{candidate function}}
37__host__ void callee5(double); // com-note {{candidate function}}
38
39// When '<<` operator is called by a device function, there is error for 'invalid operands'.
40// It should be deferred since it involves wrong-sided candidates.
41struct S {
42__host__ S &operator <<(int i); // dev-note {{candidate function not viable}}
43};
44
45__host__ void hf() {
46callee(1); // host-error {{call to 'callee' is ambiguous}}
47callee2();
48callee3();
49callee4(); // com-error {{no matching function for call to 'callee4'}}
50callee5(1); // com-error {{call to 'callee5' is ambiguous}}
51S s;
52s << 1;
53undeclared_func(); // com-error {{use of undeclared identifier 'undeclared_func'}}
54}
55
56__device__ void df() {
57callee(1);
58callee2(); // dev-error {{no matching function for call to 'callee2'}}
59callee3(); // dev-error {{no matching function for call to 'callee3'}}
60callee4(); // com-error {{no matching function for call to 'callee4'}}
61S s;
62s << 1; // dev-error {{invalid operands to binary expression}}
63}
64
65struct A { int x; typedef int isA; };
66struct B { int x; };
67
68// This function is invalid for A and B by SFINAE.
69// This fails to substitue for A but no diagnostic
70// should be emitted.
71template<typename T, typename T::foo* = nullptr>
72__host__ __device__ void sfinae(T t) { // host-note {{candidate template ignored: substitution failure [with T = B]}}
73t.x = 1;
74}
75
76// This function is defined for A only by SFINAE.
77// Calling it with A should succeed, with B should fail.
78// The error should not be deferred since it happens in
79// file scope.
80
81template<typename T, typename T::isA* = nullptr>
82__host__ __device__ void sfinae(T t) { // host-note {{candidate template ignored: substitution failure [with T = B]}}
83t.x = 1;
84}
85
86void test_sfinae() {
87sfinae(A());
88sfinae(B()); // host-error{{no matching function for call to 'sfinae'}}
89}
90
91// Make sure throw is diagnosed in OpenMP parallel region in host function.
92void test_openmp() {
93#pragma omp parallel for
94for (int i = 0; i < 10; i++) {
95throw 1;
96}
97}
98
99// If a syntax error causes a function not declared, it cannot
100// be deferred.
101
102inline __host__ __device__ void bad_func() { // com-note {{to match this '{'}}
103// com-error {{expected '}'}}
104