Skip to content

Commit 81a9060

Browse files
authored
[Driver][SYCL] Add diagnostic for bad argument with -fsycl-device-obj (#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.
1 parent bc3a43e commit 81a9060

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ def warn_drv_no_floating_point_registers: Warning<
522522
InGroup<UnsupportedABI>;
523523
def warn_ignoring_ftabstop_value : Warning<
524524
"ignoring invalid -ftabstop value '%0', using default value %1">;
525+
def warn_ignoring_value_using_default : Warning<
526+
"ignoring invalid '%0' value '%1', using default value '%2'">,
527+
InGroup<UnusedCommandLineArgument>;
525528
def warn_drv_overriding_option : Warning<
526529
"overriding '%0' option with '%1'">,
527530
InGroup<DiagGroup<"overriding-option">>;

clang/lib/Driver/Driver.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,19 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11591159
C.getInputArgs().getLastArg(options::OPT_fsycl_range_rounding_EQ);
11601160
checkSingleArgValidity(RangeRoundingPreference, {"disable", "force", "on"});
11611161

1162+
// Evaluation of -fsycl-device-obj is slightly different, we will emit
1163+
// a warning and inform the user of the default behavior used.
1164+
// TODO: General usage of this option is to check for 'spirv' and fallthrough
1165+
// to using llvmir. This can be improved to be more obvious in usage.
1166+
if (Arg *DeviceObj = C.getInputArgs().getLastArgNoClaim(
1167+
options::OPT_fsycl_device_obj_EQ)) {
1168+
StringRef ArgValue(DeviceObj->getValue());
1169+
SmallVector<StringRef, 2> DeviceObjValues = {"spirv", "llvmir"};
1170+
if (llvm::find(DeviceObjValues, ArgValue) == DeviceObjValues.end())
1171+
Diag(clang::diag::warn_ignoring_value_using_default)
1172+
<< DeviceObj->getSpelling().split('=').first << ArgValue << "llvmir";
1173+
}
1174+
11621175
Arg *SYCLForceTarget =
11631176
getArgRequiringSYCLRuntime(options::OPT_fsycl_force_target_EQ);
11641177
if (SYCLForceTarget) {

clang/test/Driver/sycl-offload.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@
6969
// RUN: | FileCheck -check-prefix=CHK-SYCL-TARGET %s
7070
// CHK-SYCL-TARGET-NOT: error: SYCL target is invalid
7171

72+
/// -fsycl-device-obj argument check
73+
// RUN: %clang -### -fsycl-device-obj=test -fsycl %s 2>&1 \
74+
// RUN: | FileCheck -check-prefix=DEVICE_OBJ_WARN %s
75+
// RUN: %clang_cl -### -fsycl-device-obj=test -fsycl %s 2>&1 \
76+
// RUN: | FileCheck -check-prefix=DEVICE_OBJ_WARN %s
77+
// DEVICE_OBJ_WARN: warning: ignoring invalid '-fsycl-device-obj' value 'test', using default value 'llvmir' [-Wunused-command-line-argument]
78+
7279
/// ###########################################################################
7380

7481
/// Check warning for duplicate offloading targets.

0 commit comments

Comments
 (0)