[Clang][Driver][NFC] Capture -foffload-lto Arg before dereferencing#181752
Open
srividya-sundaram wants to merge 1 commit intollvm:mainfrom
Open
[Clang][Driver][NFC] Capture -foffload-lto Arg before dereferencing#181752srividya-sundaram wants to merge 1 commit intollvm:mainfrom
srividya-sundaram wants to merge 1 commit intollvm:mainfrom
Conversation
Member
|
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Srividya Sundaram (srividya-sundaram) ChangesFull diff: https://github.com/llvm/llvm-project/pull/181752.diff 1 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index c16aa33f29ebb..efa8ab7d659f5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5233,23 +5233,19 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-emit-llvm-uselists");
if (IsUsingLTO) {
+ Arg *OffloadLTO = Args.getLastArg(options::OPT_foffload_lto,
+ options::OPT_foffload_lto_EQ);
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
!Args.hasFlag(options::OPT_offload_new_driver,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda)) &&
- !Triple.isAMDGPU()) {
+ !Triple.isAMDGPU() && OffloadLTO) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << Args.getLastArg(options::OPT_foffload_lto,
- options::OPT_foffload_lto_EQ)
- ->getAsString(Args)
- << Triple.getTriple();
+ << OffloadLTO->getAsString(Args) << Triple.getTriple();
} else if (Triple.isNVPTX() && !IsRDCMode &&
- JA.isDeviceOffloading(Action::OFK_Cuda)) {
+ JA.isDeviceOffloading(Action::OFK_Cuda) && OffloadLTO) {
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";
+ << OffloadLTO->getAsString(Args) << "-fno-gpu-rdc";
} else {
assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin);
CmdArgs.push_back(Args.MakeArgString(
|
jhuber6
reviewed
Feb 17, 2026
| CmdArgs.push_back("-emit-llvm-uselists"); | ||
|
|
||
| if (IsUsingLTO) { | ||
| Arg *OffloadLTO = Args.getLastArg(options::OPT_foffload_lto, |
Contributor
There was a problem hiding this comment.
Is this just for error handling? Do we have a test for this? Could just use getLastArgValue? That takes a default I believe so it would be sound if this was not passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Capture the pointer returned by
getLastArgfirst to ensure the argument exists before dereferencing.