Index: cfe/trunk/include/clang/Basic/LangOptions.def =================================================================== --- cfe/trunk/include/clang/Basic/LangOptions.def +++ cfe/trunk/include/clang/Basic/LangOptions.def @@ -162,6 +162,7 @@ LANGOPT(OpenMP , 1, 0, "OpenMP support") LANGOPT(CUDAIsDevice , 1, 0, "Compiling for CUDA device") LANGOPT(CUDAAllowHostCallsFromHostDevice, 1, 0, "Allow host device functions to call host functions") +LANGOPT(CUDADisableTargetCallChecks, 1, 0, "Disable checks for call targets (host, device, etc.)") LANGOPT(AssumeSaneOperatorNew , 1, 1, "implicit __attribute__((malloc)) for C++'s new operators") LANGOPT(SizedDeallocation , 1, 0, "enable sized deallocation functions") Index: cfe/trunk/include/clang/Driver/CC1Options.td =================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td +++ cfe/trunk/include/clang/Driver/CC1Options.td @@ -610,6 +610,9 @@ def fcuda_allow_host_calls_from_host_device : Flag<["-"], "fcuda-allow-host-calls-from-host-device">, HelpText<"Allow host device functions to call host functions">; +def fcuda_disable_target_call_checks : Flag<["-"], + "fcuda-disable-target-call-checks">, + HelpText<"Disable all cross-target (host, device, etc.) call checks in CUDA">; } // let Flags = [CC1Option] Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp =================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -1375,6 +1375,9 @@ if (Args.hasArg(OPT_fcuda_allow_host_calls_from_host_device)) Opts.CUDAAllowHostCallsFromHostDevice = 1; + if (Args.hasArg(OPT_fcuda_disable_target_call_checks)) + Opts.CUDADisableTargetCallChecks = 1; + if (Opts.ObjC1) { if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) { StringRef value = arg->getValue(); Index: cfe/trunk/lib/Sema/SemaCUDA.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaCUDA.cpp +++ cfe/trunk/lib/Sema/SemaCUDA.cpp @@ -62,6 +62,11 @@ bool Sema::CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) { + // The CUDADisableTargetCallChecks short-circuits this check: we assume all + // cross-target calls are valid. + if (getLangOpts().CUDADisableTargetCallChecks) + return false; + CUDAFunctionTarget CallerTarget = IdentifyCUDATarget(Caller), CalleeTarget = IdentifyCUDATarget(Callee); Index: cfe/trunk/test/SemaCUDA/function-target-disabled-check.cu =================================================================== --- cfe/trunk/test/SemaCUDA/function-target-disabled-check.cu +++ cfe/trunk/test/SemaCUDA/function-target-disabled-check.cu @@ -0,0 +1,26 @@ +// Test that we can disable cross-target call checks in Sema with the +// -fcuda-disable-target-call-checks flag. Without this flag we'd get a bunch +// of errors here, since there are invalid cross-target calls present. + +// RUN: %clang_cc1 -fsyntax-only -verify %s -fcuda-disable-target-call-checks +// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s -fcuda-disable-target-call-checks + +// expected-no-diagnostics + +#define __device__ __attribute__((device)) +#define __global__ __attribute__((global)) +#define __host__ __attribute__((host)) + +__attribute__((host)) void h1(); + +__attribute__((device)) void d1() { + h1(); +} + +__attribute__((host)) void h2() { + d1(); +} + +__attribute__((global)) void g1() { + h2(); +}