[clang] [clang][DependencyScanning] Return failure upon CompilerInstanceWithContext failure to create target (PR #211607)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 23 13:02:36 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ian Li (ianayl)
<details>
<summary>Changes</summary>
Further review of this PR would be appreciated! Admittedly I am not the most familiar with this part of the code. But to the best of my knowledge, this could potentially be a problem.
This was first pointed out by a Coverity static analysis scan: Success/failure results from `CompilerInstance::createTarget` in `CompilerInstanceWithContext::initialize` is currently being discarded.
AFAICT, `initialize` should have failed if `CompilerInstance::createTarget` failed, as I noticed that calls in `CompilerInstanceWithContext::computeDependencies` (which is ran right after `initialize`) contains function calls (i.e. `CI.loadModule`) that make references to `CompilerInstance::getTarget`: `getTarget` then tries to obtain a reference to the very `TargetInfo` instance that the earlier `CompilerInstance::createTarget` call failed to create.
AFAIK `createTarget` doesn't actually seem to fail currently, but I haven't been able to find a good reason as for why success/failure from `CompilerInstance::createTarget` should be ignored even if it failed. But please let me know if I am not seeing something here!
---
Full diff: https://github.com/llvm/llvm-project/pull/211607.diff
1 Files Affected:
- (modified) clang/lib/Tooling/DependencyScanningTool.cpp (+1-3)
``````````diff
diff --git a/clang/lib/Tooling/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanningTool.cpp
index b435e42af28b4..4072244f33fc3 100644
--- a/clang/lib/Tooling/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanningTool.cpp
@@ -500,9 +500,7 @@ bool CompilerInstanceWithContext::initialize(
// once here, and the information is reused for all computeDependencies calls.
// We do not need to call createTarget explicitly if we go through
// CompilerInstance::ExecuteAction to perform scanning.
- CI.createTarget();
-
- return true;
+ return CI.createTarget();
}
bool CompilerInstanceWithContext::computeDependencies(
``````````
</details>
https://github.com/llvm/llvm-project/pull/211607
More information about the cfe-commits
mailing list