Skip to content

Commit 0ea5a5b

Browse files
committed
More modifications to see if I can get tests to pass.
1 parent 2208322 commit 0ea5a5b

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

clang/include/clang/Driver/Options.td

+4-5
Original file line numberDiff line numberDiff line change
@@ -4271,6 +4271,10 @@ def fsycl : Flag<["-"], "fsycl">, Flags<[NoXarchOption, CoreOption]>, Group<sycl
42714271
HelpText<"Enables SYCL kernels compilation for device">;
42724272
def fno_sycl : Flag<["-"], "fno-sycl">, Flags<[NoXarchOption, CoreOption]>, Group<sycl_Group>,
42734273
HelpText<"Disables SYCL kernels compilation for device">;
4274+
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
4275+
HelpText<"SYCL language standard to compile for.">, Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
4276+
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, NormalizedValuesScope<"LangOptions">,
4277+
MarshallingInfoString<LangOpts<"SYCLVersion">, "SYCL_None">, AutoNormalizeEnum;
42744278
defm sycl_esimd: OptInFFlag<"sycl-explicit-simd", "Enable", "Disable", " SYCL explicit SIMD extension.", [CC1Option,CoreOption], LangOpts<"SYCLExplicitSIMD">>;
42754279
defm sycl_early_optimizations : OptOutFFlag<"sycl-early-optimizations", "Enable", "Disable", " standard optimization pipeline for SYCL device compiler", [CoreOption]>;
42764280
def fsycl_dead_args_optimization : Flag<["-"], "fsycl-dead-args-optimization">,
@@ -5482,11 +5486,6 @@ def fsycl_is_device : Flag<["-"], "fsycl-is-device">,
54825486
def fsycl_is_host : Flag<["-"], "fsycl-is-host">,
54835487
HelpText<"SYCL host compilation">,
54845488
MarshallingInfoFlag<LangOpts<"SYCLIsHost">>;
5485-
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
5486-
HelpText<"SYCL language standard to compile for.">, Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
5487-
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, NormalizedValuesScope<"LangOptions">,
5488-
MarshallingInfoString<LangOpts<"SYCLVersion">, "SYCL_None">,
5489-
ShouldParseIf<!strconcat(fsycl_is_device.KeyPath, "||", fsycl_is_host.KeyPath)>, AutoNormalizeEnum;
54905489
def fsycl_int_header : Separate<["-"], "fsycl-int-header">,
54915490
HelpText<"Generate SYCL integration header into this file.">,
54925491
MarshallingInfoString<LangOpts<"SYCLIntHeader">>;

clang/lib/Driver/Driver.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,8 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
797797
// If -fsycl is supplied without any of these we will assume SPIR-V.
798798
// Use of -fsycl-device-only overrides -fsycl.
799799
bool HasValidSYCLRuntime =
800-
C.getInputArgs().hasArg(options::OPT_fsycl) ||
800+
C.getInputArgs().hasFlag(options::OPT_fsycl, options::OPT_fno_sycl,
801+
false) ||
801802
C.getInputArgs().hasArg(options::OPT_fsycl_device_only);
802803

803804
// A mechanism for retrieving SYCL-specific options, erroring out
@@ -2390,7 +2391,8 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
23902391
// actually use it, so we warn about unused -x arguments.
23912392
types::ID InputType = types::TY_Nothing;
23922393
Arg *InputTypeArg = nullptr;
2393-
bool IsSYCL = Args.hasArg(options::OPT_fsycl) ||
2394+
bool IsSYCL =
2395+
Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) ||
23942396
Args.hasArg(options::OPT_fsycl_device_only);
23952397

23962398
// The last /TC or /TP option sets the input type to C or C++ globally.
@@ -2777,7 +2779,7 @@ static bool IsSYCLDeviceLibObj(std::string ObjFilePath, bool isMSVCEnv) {
27772779
bool Driver::checkForOffloadStaticLib(Compilation &C,
27782780
DerivedArgList &Args) const {
27792781
// Check only if enabled with -fsycl or -fopenmp-targets
2780-
if (!Args.hasArg(options::OPT_fsycl) &&
2782+
if (!Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) &&
27812783
!Args.hasArg(options::OPT_fopenmp_targets_EQ))
27822784
return false;
27832785

@@ -4391,7 +4393,8 @@ class OffloadingActionBuilder final {
43914393
Arg *SYCLTargets =
43924394
C.getInputArgs().getLastArg(options::OPT_fsycl_targets_EQ);
43934395
Arg *SYCLAddTargets = Args.getLastArg(options::OPT_fsycl_add_targets_EQ);
4394-
bool HasValidSYCLRuntime = C.getInputArgs().hasArg(options::OPT_fsycl);
4396+
bool HasValidSYCLRuntime = C.getInputArgs().hasFlag(
4397+
options::OPT_fsycl, options::OPT_fno_sycl, false);
43954398
bool SYCLfpgaTriple = false;
43964399
if (SYCLTargets || SYCLAddTargets) {
43974400
if (SYCLTargets) {

clang/lib/Driver/ToolChains/Clang.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -5862,8 +5862,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
58625862
// Forward -cl options to -cc1
58635863
RenderOpenCLOptions(Args, CmdArgs);
58645864

5865-
// Forward -sycl-std option to -cc1
5866-
Args.AddLastArg(CmdArgs, options::OPT_sycl_std_EQ);
5865+
// Forward -sycl-std option to -cc1 only if -fsycl is enabled.
5866+
if (Args.hasArg(options::OPT_fsycl))
5867+
Args.AddLastArg(CmdArgs, options::OPT_sycl_std_EQ);
58675868

58685869
if (IsHIP) {
58695870
if (Args.hasFlag(options::OPT_fhip_new_launch_api,

clang/unittests/Frontend/CompilerInvocationTest.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,19 @@ TEST_F(CommandLineTest, ConditionalParsingIfFalseFlagPresent) {
531531
ASSERT_FALSE(Diags->hasErrorOccurred());
532532
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsDevice);
533533
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
534-
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
534+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
535535

536536
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
537537

538-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
539-
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
538+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-device"))));
539+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));
540+
541+
// FIXME: generateCC1CommandLine is only used by the unit test system and
542+
// cannot handle this case. It passes along the -scyl-std because the option
543+
// definition does not specify that it relies on -fsycl any longer (because
544+
// there is no syntax I could find that would allow it). However, the option
545+
// is handled properly on a real invocation. See: Clang::ConstructJob().
546+
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=")));
540547
}
541548

542549
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresent) {
@@ -559,12 +566,12 @@ TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagPresent) {
559566
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
560567

561568
ASSERT_TRUE(Diags->hasErrorOccurred());
562-
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
569+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
563570

564571
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
565572

566573
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
567-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-sycl-std=2017"))));
574+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-sycl-std=2017")));
568575
}
569576

570577
// Wide integer option.

0 commit comments

Comments
 (0)