Skip to content

Commit

Permalink
[Driver][SYCL] Add diagnostic for bad argument with -fsycl-device-obj (
Browse files Browse the repository at this point in the history
…#15381)

When using -fsycl-device-obj, we would effectively ignore any bad
arguments and default to 'llvmir'. Add a diagnostic to inform the user
of the bad argument and what we are doing with our default behavior.
  • Loading branch information
mdtoguchi authored Sep 16, 2024
1 parent bc3a43e commit 81a9060
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ def warn_drv_no_floating_point_registers: Warning<
InGroup<UnsupportedABI>;
def warn_ignoring_ftabstop_value : Warning<
"ignoring invalid -ftabstop value '%0', using default value %1">;
def warn_ignoring_value_using_default : Warning<
"ignoring invalid '%0' value '%1', using default value '%2'">,
InGroup<UnusedCommandLineArgument>;
def warn_drv_overriding_option : Warning<
"overriding '%0' option with '%1'">,
InGroup<DiagGroup<"overriding-option">>;
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,19 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
C.getInputArgs().getLastArg(options::OPT_fsycl_range_rounding_EQ);
checkSingleArgValidity(RangeRoundingPreference, {"disable", "force", "on"});

// Evaluation of -fsycl-device-obj is slightly different, we will emit
// a warning and inform the user of the default behavior used.
// TODO: General usage of this option is to check for 'spirv' and fallthrough
// to using llvmir. This can be improved to be more obvious in usage.
if (Arg *DeviceObj = C.getInputArgs().getLastArgNoClaim(
options::OPT_fsycl_device_obj_EQ)) {
StringRef ArgValue(DeviceObj->getValue());
SmallVector<StringRef, 2> DeviceObjValues = {"spirv", "llvmir"};
if (llvm::find(DeviceObjValues, ArgValue) == DeviceObjValues.end())
Diag(clang::diag::warn_ignoring_value_using_default)
<< DeviceObj->getSpelling().split('=').first << ArgValue << "llvmir";
}

Arg *SYCLForceTarget =
getArgRequiringSYCLRuntime(options::OPT_fsycl_force_target_EQ);
if (SYCLForceTarget) {
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/sycl-offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
// RUN: | FileCheck -check-prefix=CHK-SYCL-TARGET %s
// CHK-SYCL-TARGET-NOT: error: SYCL target is invalid

/// -fsycl-device-obj argument check
// RUN: %clang -### -fsycl-device-obj=test -fsycl %s 2>&1 \
// RUN: | FileCheck -check-prefix=DEVICE_OBJ_WARN %s
// RUN: %clang_cl -### -fsycl-device-obj=test -fsycl %s 2>&1 \
// RUN: | FileCheck -check-prefix=DEVICE_OBJ_WARN %s
// DEVICE_OBJ_WARN: warning: ignoring invalid '-fsycl-device-obj' value 'test', using default value 'llvmir' [-Wunused-command-line-argument]

/// ###########################################################################

/// Check warning for duplicate offloading targets.
Expand Down

0 comments on commit 81a9060

Please sign in to comment.