[CUDA] Make unattributed constexpr functions implicitly host+device.
authorJustin Lebar <jlebar@google.com>
Wed, 30 Mar 2016 23:30:21 +0000 (23:30 +0000)
committerJustin Lebar <jlebar@google.com>
Wed, 30 Mar 2016 23:30:21 +0000 (23:30 +0000)
commitba122ab42fe54aee3427dc61b765cc8a9dad9d85
treea8167ca817e1ce33986b9b601c5f725379de603b
parent0cda7644301dd0793f796681030b9425b227f157
[CUDA] Make unattributed constexpr functions implicitly host+device.

With this patch, by a constexpr function is implicitly host+device
unless:

 a) it's a variadic function (variadic functions are not allowed on the
    device side), or
 b) it's preceeded by a __device__ overload in a system header.

The restriction on overloading __host__ __device__ functions on the
basis of their CUDA attributes remains in place, but we use (b) to allow
us to define __device__ overloads for constexpr functions in cmath,
which would otherwise be __host__ __device__ and thus not overloadable.

You can disable this behavior with -fno-cuda-host-device-constexpr.

Reviewers: tra, rnk, rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18380

llvm-svn: 264964
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/CC1Options.td
clang/include/clang/Sema/Sema.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCUDA/Inputs/overload.h [new file with mode: 0644]
clang/test/SemaCUDA/host-device-constexpr.cu [new file with mode: 0644]
clang/test/SemaCUDA/no-host-device-constexpr.cu [new file with mode: 0644]