Skip to content

Potential UB in diagnostics for LTO mode. #21282

@bader

Description

@bader

if ((IsDeviceOffloadAction &&
!JA.isDeviceOffloading(Action::OFK_OpenMP) && !Triple.isAMDGPU() &&
!IsUsingOffloadNewDriver) ||
(JA.isDeviceOffloading(Action::OFK_SYCL) && !IsSYCLLTOSupported)) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< Args.getLastArg(options::OPT_foffload_lto,
options::OPT_foffload_lto_EQ)
->getAsString(Args)
<< Triple.getTriple();
} else if (Triple.isNVPTX() && !IsRDCMode &&
JA.isDeviceOffloading(Action::OFK_Cuda)) {
D.Diag(diag::err_drv_unsupported_opt_for_language_mode)
<< Args.getLastArg(options::OPT_foffload_lto,
options::OPT_foffload_lto_EQ)
->getAsString(Args)
<< "-fno-gpu-rdc";
} else if (JA.isDeviceOffloading(Action::OFK_SYCL) &&
IsDeviceCodeSplitDisabled && LTOMode == LTOK_Thin) {
D.Diag(diag::err_drv_sycl_thinlto_split_off)
<< SYCLSplitMode->getAsString(Args)
<< Args.getLastArg(options::OPT_foffload_lto,
options::OPT_foffload_lto_EQ)
->getAsString(Args);
} else {

The pattern used in this code doesn't the pointer returned by Args.getLastArg(options::OPT_foffload_lto, options::OPT_foffload_lto_EQ) before dereferencing. This can be source of UB.

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions