@@ -810,14 +810,6 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
810
810
return SYCLArg;
811
811
};
812
812
813
- // Emit an error if c-compilation is forced in -fsycl mode
814
- if (HasValidSYCLRuntime)
815
- for (StringRef XValue : C.getInputArgs ().getAllArgValues (options::OPT_x)) {
816
- if (XValue == " c" || XValue == " c-header" )
817
- C.getDriver ().Diag (clang::diag::err_drv_fsycl_with_c_type)
818
- << " -x " << XValue;
819
- }
820
-
821
813
Arg *SYCLTargets = getArgRequiringSYCLRuntime (options::OPT_fsycl_targets_EQ);
822
814
Arg *SYCLLinkTargets =
823
815
getArgRequiringSYCLRuntime (options::OPT_fsycl_link_targets_EQ);
@@ -2385,12 +2377,13 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2385
2377
// actually use it, so we warn about unused -x arguments.
2386
2378
types::ID InputType = types::TY_Nothing;
2387
2379
Arg *InputTypeArg = nullptr ;
2380
+ bool IsSYCL = Args.hasFlag (options::OPT_fsycl, options::OPT_fno_sycl, false );
2388
2381
2389
2382
// The last /TC or /TP option sets the input type to C or C++ globally.
2390
2383
if (Arg *TCTP = Args.getLastArgNoClaim (options::OPT__SLASH_TC,
2391
2384
options::OPT__SLASH_TP)) {
2392
2385
InputTypeArg = TCTP;
2393
- InputType = TCTP->getOption ().matches (options::OPT__SLASH_TC)
2386
+ InputType = TCTP->getOption ().matches (options::OPT__SLASH_TC) && !IsSYCL
2394
2387
? types::TY_C
2395
2388
: types::TY_CXX;
2396
2389
@@ -2423,6 +2416,11 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2423
2416
if (InputTypeArg)
2424
2417
InputTypeArg->claim ();
2425
2418
2419
+ types::ID CType = types::TY_C;
2420
+ // For SYCL, all source file inputs are considered C++.
2421
+ if (IsSYCL)
2422
+ CType = types::TY_CXX;
2423
+
2426
2424
// stdin must be handled specially.
2427
2425
if (memcmp (Value, " -" , 2 ) == 0 ) {
2428
2426
// If running with -E, treat as a C input (this changes the builtin
@@ -2433,7 +2431,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2433
2431
if (!Args.hasArgNoClaim (options::OPT_E) && !CCCIsCPP ())
2434
2432
Diag (IsCLMode () ? clang::diag::err_drv_unknown_stdin_type_clang_cl
2435
2433
: clang::diag::err_drv_unknown_stdin_type);
2436
- Ty = types::TY_C ;
2434
+ Ty = CType ;
2437
2435
} else {
2438
2436
// Otherwise lookup by extension.
2439
2437
// Fallback is C if invoked as C preprocessor, C++ if invoked with
@@ -2443,9 +2441,29 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2443
2441
if (const char *Ext = strrchr (Value, ' .' ))
2444
2442
Ty = TC.LookupTypeForExtension (Ext + 1 );
2445
2443
2444
+ // For SYCL, convert C-type sources to C++-type sources.
2445
+ if (IsSYCL) {
2446
+ switch (Ty) {
2447
+ case types::TY_C:
2448
+ Ty = types::TY_CXX;
2449
+ break ;
2450
+ case types::TY_CHeader:
2451
+ Ty = types::TY_CXXHeader;
2452
+ break ;
2453
+ case types::TY_PP_C:
2454
+ Ty = types::TY_PP_CXX;
2455
+ break ;
2456
+ case types::TY_PP_CHeader:
2457
+ Ty = types::TY_PP_CXXHeader;
2458
+ break ;
2459
+ default :
2460
+ break ;
2461
+ }
2462
+ }
2463
+
2446
2464
if (Ty == types::TY_INVALID) {
2447
2465
if (CCCIsCPP ())
2448
- Ty = types::TY_C ;
2466
+ Ty = CType ;
2449
2467
else if (IsCLMode () && Args.hasArgNoClaim (options::OPT_E))
2450
2468
Ty = types::TY_CXX;
2451
2469
else
@@ -2504,7 +2522,8 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2504
2522
if (DiagnoseInputExistence (Args, Value, types::TY_C,
2505
2523
/* TypoCorrect=*/ false )) {
2506
2524
Arg *InputArg = MakeInputArg (Args, Opts, A->getValue ());
2507
- Inputs.push_back (std::make_pair (types::TY_C, InputArg));
2525
+ Inputs.push_back (
2526
+ std::make_pair (IsSYCL ? types::TY_CXX : types::TY_C, InputArg));
2508
2527
}
2509
2528
A->claim ();
2510
2529
} else if (A->getOption ().matches (options::OPT__SLASH_Tp)) {
@@ -2532,6 +2551,11 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2532
2551
Diag (clang::diag::err_drv_unknown_language) << A->getValue ();
2533
2552
InputType = types::TY_Object;
2534
2553
}
2554
+ // Emit an error if c-compilation is forced in -fsycl mode
2555
+ if (IsSYCL && (InputType == types::TY_C || InputType == types::TY_PP_C ||
2556
+ InputType == types::TY_CHeader))
2557
+ Diag (clang::diag::err_drv_fsycl_with_c_type) << A->getAsString (Args);
2558
+
2535
2559
} else if (A->getOption ().getID () == options::OPT_U) {
2536
2560
assert (A->getNumValues () == 1 && " The /U option has one value." );
2537
2561
StringRef Val = A->getValue (0 );
0 commit comments