Skip to content

Commit 86c4e63

Browse files
author
Justin Lebar
committedJan 5, 2017
[CUDA] Let NVPTX inherit the host's calling conventions.
Summary: When compiling device code, we may still see host code with explicit calling conventions. NVPTX needs to claim that it supports these CCs, so that (a) we don't raise noisy warnings, and (b) we don't break existing code which relies on the existence of these CCs when specializing templates. (If a CC doesn't exist, clang ignores it, so two template specializations which are different only insofar as one specifies a CC are considered identical and therefore are an error if that CC is not supported.) Reviewers: tra Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28323 llvm-svn: 291136
1 parent b662659 commit 86c4e63

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
 

‎clang/lib/Basic/Targets.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,16 @@ class NVPTXTargetInfo : public TargetInfo {
19621962
Opts.support("cl_khr_local_int32_base_atomics");
19631963
Opts.support("cl_khr_local_int32_extended_atomics");
19641964
}
1965+
1966+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
1967+
// CUDA compilations support all of the host's calling conventions.
1968+
//
1969+
// TODO: We should warn if you apply a non-default CC to anything other than
1970+
// a host function.
1971+
if (HostTarget)
1972+
return HostTarget->checkCallingConvention(CC);
1973+
return CCCR_Warning;
1974+
}
19651975
};
19661976

19671977
const Builtin::Info NVPTXTargetInfo::BuiltinInfo[] = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang_cc1 -std=c++11 -triple i386-windows-msvc \
2+
// RUN: -aux-triple nvptx-nvidia-cuda -fsyntax-only -verify %s
3+
4+
// RUN: %clang_cc1 -std=c++11 -triple nvptx-nvidia-cuda \
5+
// RUN: -aux-triple i386-windows-msvc -fsyntax-only \
6+
// RUN: -fcuda-is-device -verify %s
7+
8+
// RUN: %clang_cc1 -std=c++11 -triple nvptx-nvidia-cuda \
9+
// RUN: -aux-triple x86_64-linux-gnu -fsyntax-only \
10+
// RUN: -fcuda-is-device -verify -verify-ignore-unexpected=note \
11+
// RUN: -DEXPECT_ERR %s
12+
13+
// CUDA device code should inherit the host's calling conventions.
14+
15+
template <class T>
16+
struct Foo;
17+
18+
template <class T>
19+
struct Foo<T()> {};
20+
21+
// On x86_64-linux-gnu, this is a redefinition of the template, because the
22+
// __fastcall calling convention doesn't exist (and is therefore ignored).
23+
#ifndef EXPECT_ERR
24+
// expected-no-diagnostics
25+
#else
26+
// expected-error@+4 {{redefinition of 'Foo}}
27+
// expected-warning@+3 {{calling convention '__fastcall' ignored}}
28+
#endif
29+
template <class T>
30+
struct Foo<T __fastcall()> {};

0 commit comments

Comments
 (0)
Please sign in to comment.