-
Notifications
You must be signed in to change notification settings - Fork 769
[Driver][SYCL] For SYCL compilations, force C++ source even with .c #2491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -810,14 +810,6 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C, | |
return SYCLArg; | ||
}; | ||
|
||
// Emit an error if c-compilation is forced in -fsycl mode | ||
if (HasValidSYCLRuntime) | ||
for (StringRef XValue : C.getInputArgs().getAllArgValues(options::OPT_x)) { | ||
if (XValue == "c" || XValue == "c-header") | ||
C.getDriver().Diag(clang::diag::err_drv_fsycl_with_c_type) | ||
<< "-x " << XValue; | ||
} | ||
|
||
Arg *SYCLTargets = getArgRequiringSYCLRuntime(options::OPT_fsycl_targets_EQ); | ||
Arg *SYCLLinkTargets = | ||
getArgRequiringSYCLRuntime(options::OPT_fsycl_link_targets_EQ); | ||
|
@@ -2385,12 +2377,13 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, | |
// actually use it, so we warn about unused -x arguments. | ||
types::ID InputType = types::TY_Nothing; | ||
Arg *InputTypeArg = nullptr; | ||
bool IsSYCL = Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false); | ||
|
||
// The last /TC or /TP option sets the input type to C or C++ globally. | ||
if (Arg *TCTP = Args.getLastArgNoClaim(options::OPT__SLASH_TC, | ||
options::OPT__SLASH_TP)) { | ||
InputTypeArg = TCTP; | ||
InputType = TCTP->getOption().matches(options::OPT__SLASH_TC) | ||
InputType = TCTP->getOption().matches(options::OPT__SLASH_TC) && !IsSYCL | ||
? types::TY_C | ||
: types::TY_CXX; | ||
|
||
|
@@ -2423,6 +2416,11 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, | |
if (InputTypeArg) | ||
InputTypeArg->claim(); | ||
|
||
types::ID CType = types::TY_C; | ||
// For SYCL, all source file inputs are considered C++. | ||
if (IsSYCL) | ||
CType = types::TY_CXX; | ||
|
||
// stdin must be handled specially. | ||
if (memcmp(Value, "-", 2) == 0) { | ||
// 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, | |
if (!Args.hasArgNoClaim(options::OPT_E) && !CCCIsCPP()) | ||
Diag(IsCLMode() ? clang::diag::err_drv_unknown_stdin_type_clang_cl | ||
: clang::diag::err_drv_unknown_stdin_type); | ||
Ty = types::TY_C; | ||
Ty = CType; | ||
} else { | ||
// Otherwise lookup by extension. | ||
// Fallback is C if invoked as C preprocessor, C++ if invoked with | ||
|
@@ -2443,9 +2441,29 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, | |
if (const char *Ext = strrchr(Value, '.')) | ||
Ty = TC.LookupTypeForExtension(Ext + 1); | ||
|
||
// For SYCL, convert C-type sources to C++-type sources. | ||
if (IsSYCL) { | ||
switch (Ty) { | ||
case types::TY_C: | ||
Ty = types::TY_CXX; | ||
break; | ||
case types::TY_CHeader: | ||
Ty = types::TY_CXXHeader; | ||
break; | ||
case types::TY_PP_C: | ||
Ty = types::TY_PP_CXX; | ||
break; | ||
case types::TY_PP_CHeader: | ||
Ty = types::TY_PP_CXXHeader; | ||
break; | ||
default: | ||
break; | ||
} | ||
Comment on lines
+2446
to
+2461
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never thought I'd say this as a Python hater, but it's a shame we don't have something really analogous to a Python dict :D Take any alternative like a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C++23 I hope the pattern matching proposal https://wg21.link/p1371 will be voted in! |
||
} | ||
|
||
if (Ty == types::TY_INVALID) { | ||
if (CCCIsCPP()) | ||
Ty = types::TY_C; | ||
Ty = CType; | ||
else if (IsCLMode() && Args.hasArgNoClaim(options::OPT_E)) | ||
Ty = types::TY_CXX; | ||
else | ||
|
@@ -2504,7 +2522,8 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, | |
if (DiagnoseInputExistence(Args, Value, types::TY_C, | ||
/*TypoCorrect=*/false)) { | ||
Arg *InputArg = MakeInputArg(Args, Opts, A->getValue()); | ||
Inputs.push_back(std::make_pair(types::TY_C, InputArg)); | ||
Inputs.push_back( | ||
std::make_pair(IsSYCL ? types::TY_CXX : types::TY_C, InputArg)); | ||
} | ||
A->claim(); | ||
} else if (A->getOption().matches(options::OPT__SLASH_Tp)) { | ||
|
@@ -2532,6 +2551,11 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, | |
Diag(clang::diag::err_drv_unknown_language) << A->getValue(); | ||
InputType = types::TY_Object; | ||
} | ||
// Emit an error if c-compilation is forced in -fsycl mode | ||
if (IsSYCL && (InputType == types::TY_C || InputType == types::TY_PP_C || | ||
InputType == types::TY_CHeader)) | ||
Diag(clang::diag::err_drv_fsycl_with_c_type) << A->getAsString(Args); | ||
|
||
} else if (A->getOption().getID() == options::OPT_U) { | ||
assert(A->getNumValues() == 1 && "The /U option has one value."); | ||
StringRef Val = A->getValue(0); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// When -fsycl is used, C++ source is the default | ||
// REQUIRES: clang-driver | ||
|
||
// RUN: %clang -c -fsycl %s -### 2>&1 \ | ||
// RUN: | FileCheck -check-prefix=CXX_TYPE_CHECK %s | ||
// RUN: %clangxx -c -fsycl %s -### 2>&1 \ | ||
// RUN: | FileCheck -check-prefix=CXX_TYPE_CHECK %s | ||
// RUN: %clang_cl -c -fsycl %s -### 2>&1 \ | ||
// RUN: | FileCheck -check-prefix=CXX_TYPE_CHECK %s | ||
// RUN: %clang_cl -c -fsycl /TC %s -### 2>&1 \ | ||
// RUN: | FileCheck -check-prefix=CXX_TYPE_CHECK %s | ||
// RUN: %clang_cl -c -fsycl /Tc%s -### 2>&1 \ | ||
// RUN: | FileCheck -check-prefix=CXX_TYPE_CHECK %s | ||
// CXX_TYPE_CHECK: "-x" "c++" | ||
// CXX_TYPE_CHECK-NOT: "-x" "c" | ||
|
||
// RUN: %clang -c -fsycl -std=c99 %s -### 2>&1 \ | ||
// RUN: | FileCheck -check-prefix=C_SYCL_ERROR_CHECK %s | ||
// C_SYCL_ERROR_CHECK: error: invalid argument '-std=c99' not allowed with '-fsycl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a switch instead? I would fear this getting unwieldy otherwise in pulldown/etc or if this got any more complicated.