def cl_uniform_work_group_size : Flag<["-"], "cl-uniform-work-group-size">, Group<opencl_Group>, Flags<[CC1Option]>,
HelpText<"OpenCL only. Defines that the global work-size be a multiple of the work-group size specified to clEnqueueNDRangeKernel">,
MarshallingInfoFlag<CodeGenOpts<"UniformWGSize">>;
+def cl_no_stdinc : Flag<["-"], "cl-no-stdinc">, Group<opencl_Group>,
+ HelpText<"OpenCL only. Disables all standard includes containing non-native compiler types and functions.">;
def client__name : JoinedOrSeparate<["-"], "client_name">;
def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, Unsupported]>;
def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
/// isObjC - Is this an "ObjC" input (Obj-C and Obj-C++ sources and headers).
bool isObjC(ID Id);
+ /// isOpenCL - Is this an "OpenCL" input.
+ bool isOpenCL(ID Id);
+
/// isFortran - Is this a Fortran input.
bool isFortran(ID Id);
}
}
-static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs) {
+static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs,
+ types::ID InputType) {
// cl-denorms-are-zero is not forwarded. It is translated into a generic flag
// for denormal flushing handling based on the target.
const unsigned ForwardedArguments[] = {
for (const auto &Arg : ForwardedArguments)
if (const auto *A = Args.getLastArg(Arg))
CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
+
+ // Only add the default headers if we are compiling OpenCL sources.
+ if ((types::isOpenCL(InputType) || Args.hasArg(options::OPT_cl_std_EQ)) &&
+ !Args.hasArg(options::OPT_cl_no_stdinc)) {
+ CmdArgs.push_back("-finclude-default-header");
+ CmdArgs.push_back("-fdeclare-opencl-builtins");
+ }
}
static void RenderARCMigrateToolOptions(const Driver &D, const ArgList &Args,
}
// Forward -cl options to -cc1
- RenderOpenCLOptions(Args, CmdArgs);
+ RenderOpenCLOptions(Args, CmdArgs, InputType);
if (IsHIP) {
if (Args.hasFlag(options::OPT_fhip_new_launch_api,
}
}
+bool types::isOpenCL(ID Id) { return Id == TY_CL; }
+
bool types::isCXX(ID Id) {
switch (Id) {
default:
--- /dev/null
+// RUN: %clang %s -Xclang -verify -fsyntax-only
+// RUN: %clang %s -cl-no-stdinc -Xclang -verify -DNOINC -fsyntax-only
+
+#ifndef NOINC
+//expected-no-diagnostics
+#endif
+
+void test() {
+int i = get_global_id(0);
+#ifdef NOINC
+//expected-error@-2{{implicit declaration of function 'get_global_id' is invalid in OpenCL}}
+#endif
+}
FileName = "input.cc";
break;
case Lang_OpenCL:
+ Args.push_back("-cl-no-stdinc");
FileName = "input.cl";
break;
case Lang_OBJCXX: