llvm-project/clang/test/Parser/cuda-force-host-device-templates.cu
Justin Lebar d3fd70dedd [CUDA] Rework tests now that we emit deferred diagnostics during sema. Test-only change.
Summary:
Previously we had to split out a lot of our tests into a test that
checked only immediate errors and a test that checked only deferred
errors.  This was because, if you emitted any immediate errors, we
wouldn't run codegen, where the deferred errors were emitted.

We've fixed this, and now emit deferred errors during sema.  This lets
us merge a bunch of tests, and lets us convert some other tests to
-fsyntax-only.

Reviewers: tra

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25755

llvm-svn: 284553
2016-10-19 00:06:49 +00:00

41 lines
1.2 KiB
Plaintext

// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify -fcuda-is-device %s
// Check how the force_cuda_host_device pragma interacts with template
// instantiations.
template <typename T>
auto foo() { // expected-note {{declared here}}
return T();
}
template <typename T>
struct X {
void foo(); // expected-note {{declared here}}
};
#pragma clang force_cuda_host_device begin
__attribute__((host)) __attribute__((device)) void test() {
int n = foo<int>(); // expected-error {{reference to __host__ function 'foo<int>'}}
X<int>().foo(); // expected-error {{reference to __host__ function 'foo'}}
}
#pragma clang force_cuda_host_device end
// Same thing as above, but within a force_cuda_host_device block without a
// corresponding end.
template <typename T>
T bar() { // expected-note {{declared here}}
return T();
}
template <typename T>
struct Y {
void bar(); // expected-note {{declared here}}
};
#pragma clang force_cuda_host_device begin
__attribute__((host)) __attribute__((device)) void test2() {
int n = bar<int>(); // expected-error {{reference to __host__ function 'bar<int>'}}
Y<int>().bar(); // expected-error {{reference to __host__ function 'bar'}}
}