Skip to content

Commit e878f1d

Browse files
Blower, Melanievladimirlaz
Blower, Melanie
authored andcommitted
[SYCL] Add option fsycl-allow-func-ptr which defaults to false
Signed-off-by: Vladimir Lazarev <[email protected]> Signed-off-by: Blower, Melanie <[email protected]>
1 parent 02f6d68 commit e878f1d

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
219219

220220
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")
221221
LANGOPT(SYCLUseBitcode , 1, 0, "Generate bitcode for SYCL")
222+
LANGOPT(SYCLAllowFuncPtr , 1, 0, "Allow function pointers in SYCL device code")
222223

223224
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
224225
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")

clang/include/clang/Driver/CC1Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,9 @@ def fsycl_int_header : Separate<["-"], "fsycl-int-header">,
849849
HelpText<"Generate SYCL integration header into this file.">;
850850
def fsycl_int_header_EQ : Joined<["-"], "fsycl-int-header=">,
851851
Alias<fsycl_int_header>;
852+
def fsycl_allow_func_ptr : Flag<["-"], "fsycl-allow-func-ptr">,
853+
HelpText<"Allow function pointers in SYCL device.">;
854+
def fno_sycl_allow_func_ptr : Flag<["-"], "fno-sycl-allow-func-ptr">;
852855

853856
} // let Flags = [CC1Option]
854857

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
35503550
options::OPT_fno_sycl_use_bitcode, true)) {
35513551
CmdArgs.push_back("-fsycl-use-bitcode");
35523552
}
3553+
if (Args.hasFlag(options::OPT_fsycl_allow_func_ptr,
3554+
options::OPT_fno_sycl_allow_func_ptr, false)) {
3555+
CmdArgs.push_back("-fsycl-allow-func-ptr");
3556+
}
35533557
}
35543558

35553559
if (IsOpenMPDevice) {

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
28932893
Opts.SYCLIsDevice = Args.hasArg(options::OPT_fsycl_is_device);
28942894
Opts.SYCLUseBitcode = Args.hasFlag(options::OPT_fsycl_use_bitcode,
28952895
options::OPT_fno_sycl_use_bitcode, false);
2896+
Opts.SYCLAllowFuncPtr = Args.hasFlag(options::OPT_fsycl_allow_func_ptr,
2897+
options::OPT_fno_sycl_allow_func_ptr, false);
28962898

28972899
// Set CUDA mode for OpenMP target NVPTX if specified in options
28982900
Opts.OpenMPCUDAMode = Opts.OpenMPIsDevice && T.isNVPTX() &&

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
113113
SemaRef.AddSyclKernel(Def);
114114
}
115115
}
116-
} else {
116+
} else if (!SemaRef.getLangOpts().SYCLAllowFuncPtr)
117117
SemaRef.Diag(e->getExprLoc(), diag::err_sycl_restrict) <<
118118
KernelCallFunctionPointer;
119-
}
120119
return true;
121120
}
122121

clang/test/SemaSYCL/sycl-restrict.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %clang_cc1 -fcxx-exceptions -fsycl-is-device -Wno-return-type -verify -fsyntax-only -x c++ -emit-llvm-only -std=c++17 %s
2+
// RUN: %clang_cc1 -fcxx-exceptions -fsycl-is-device -fno-sycl-allow-func-ptr -Wno-return-type -verify -fsyntax-only -x c++ -emit-llvm-only -std=c++17 %s
3+
// RUN: %clang_cc1 -fcxx-exceptions -fsycl-is-device -DALLOW_FP=1 -fsycl-allow-func-ptr -Wno-return-type -verify -fsyntax-only -x c++ -emit-llvm-only -std=c++17 %s
24

35

46
namespace std {
@@ -104,7 +106,11 @@ void usage( myFuncDef functionPtr ) {
104106

105107
eh_not_ok();
106108

107-
// expected-error@+1 {{SYCL kernel cannot call through a function pointer}}
109+
#if ALLOW_FP
110+
// No error message for function pointer.
111+
#else
112+
// expected-error@+2 {{SYCL kernel cannot call through a function pointer}}
113+
#endif
108114
if ((*functionPtr)(1,2))
109115
// expected-note@+3{{used here}}
110116
// expected-error@+2 {{SYCL kernel cannot use a global variable}}

0 commit comments

Comments
 (0)