Skip to content

Commit ced00e8

Browse files
committed
Update the way we handle -sycl-std= based on community review feedback
When upstreaming these changes, community asked for some simple modifications in https://reviews.llvm.org/D97717. This brings those changes back downstream for parity.
1 parent 92e4470 commit ced00e8

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

clang/include/clang/Driver/Options.td

+9-4
Original file line numberDiff line numberDiff line change
@@ -4295,10 +4295,6 @@ def fsycl : Flag<["-"], "fsycl">, Flags<[NoXarchOption, CoreOption]>, Group<sycl
42954295
HelpText<"Enables SYCL kernels compilation for device">;
42964296
def fno_sycl : Flag<["-"], "fno-sycl">, Flags<[NoXarchOption, CoreOption]>, Group<sycl_Group>,
42974297
HelpText<"Disables SYCL kernels compilation for device">;
4298-
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
4299-
HelpText<"SYCL language standard to compile for.">, Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
4300-
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, NormalizedValuesScope<"LangOptions">,
4301-
MarshallingInfoString<LangOpts<"SYCLVersion">, "SYCL_None">, AutoNormalizeEnum;
43024298
defm sycl_esimd: BoolFOption<"sycl-explicit-simd",
43034299
LangOpts<"SYCLExplicitSIMD">, DefaultFalse,
43044300
PosFlag<SetTrue, [CC1Option], "Enable">, NegFlag<SetFalse, [], "Disable">,
@@ -5520,6 +5516,15 @@ def fsycl_is_device : Flag<["-"], "fsycl-is-device">,
55205516
def fsycl_is_host : Flag<["-"], "fsycl-is-host">,
55215517
HelpText<"SYCL host compilation">,
55225518
MarshallingInfoFlag<LangOpts<"SYCLIsHost">>;
5519+
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>,
5520+
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
5521+
HelpText<"SYCL language standard to compile for.">,
5522+
Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
5523+
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>,
5524+
NormalizedValuesScope<"LangOptions">,
5525+
MarshallingInfoString<LangOpts<"SYCLVersion">, "SYCL_None">,
5526+
AutoNormalizeEnum,
5527+
ShouldParseIf<!strconcat(fsycl_is_device.KeyPath, "||", fsycl_is_host.KeyPath)>;
55235528
def fsycl_int_header : Separate<["-"], "fsycl-int-header">,
55245529
HelpText<"Generate SYCL integration header into this file.">,
55255530
MarshallingInfoString<LangOpts<"SYCLIntHeader">>;

clang/unittests/Frontend/CompilerInvocationTest.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -531,46 +531,40 @@ 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_2017);
534+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
535535

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

538538
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-device"))));
539539
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 -sycl-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=")));
540+
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
547541
}
548542

549543
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresent) {
550-
const char *Args[] = {"-fsycl"};
544+
const char *Args[] = {"-fsycl-is-host"};
551545

552546
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
553547

554-
ASSERT_TRUE(Diags->hasErrorOccurred());
548+
ASSERT_FALSE(Diags->hasErrorOccurred());
555549
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
556550

557551
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
558552

559-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
553+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-host")));
560554
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
561555
}
562556

563557
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagPresent) {
564-
const char *Args[] = {"-fsycl", "-sycl-std=2017"};
558+
const char *Args[] = {"-fsycl-is-device", "-sycl-std=2017"};
565559

566560
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
567561

568-
ASSERT_TRUE(Diags->hasErrorOccurred());
562+
ASSERT_FALSE(Diags->hasErrorOccurred());
569563
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
570564

571565
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
572566

573-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
567+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
574568
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-sycl-std=2017")));
575569
}
576570

0 commit comments

Comments
 (0)