[PATCH] D18380: [CUDA] Implement -fcuda-relaxed-constexpr, and enable it by default.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 24 11:10:31 PDT 2016

rsmith accepted this revision.
rsmith added a reviewer: rsmith.
rsmith added a comment.

The change to allow `__host__ __device__` functions to be overloaded with other combinations of target attributes appears to be separable from the `constexpr` change; please split it out and commit it first.

Comment at: include/clang/Basic/LangOptions.def:175
@@ -174,2 +174,3 @@
 LANGOPT(CUDAAllowVariadicFunctions, 1, 0, "Allow variadic functions in CUDA device code")
+LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "Treat unattributed constexpr functions as __host__ __device__")
This should be a noun phrase -- this string appears in contexts like "support for %0 is enabled" -- so this should be "treating unattributed [...]".

Comment at: lib/Sema/SemaDecl.cpp:8015-8017
@@ +8014,5 @@
+  // allowed, so we just treat those as host-only.
+  if (getLangOpts().CUDA && getLangOpts().CUDAHostDeviceConstexpr &&
+      NewFD->isConstexpr() && !NewFD->isVariadic() &&
+      !NewFD->hasAttr<CUDAHostAttr>() && !NewFD->hasAttr<CUDADeviceAttr>() &&
+      !NewFD->hasAttr<CUDAGlobalAttr>()) {
`constexpr` functions can return `void` in a couple of different ways (in C++11, if they're template specializations with dependent return types that instantiate to `void`, and in C++14 there is no restriction on `constexpr` functions returning `void`).


More information about the cfe-commits mailing list