[clang] [analyzer] Avoid a crash in a debug printout function (PR #79446)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 25 05:35:41 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-static-analyzer-1
Author: None (NagyDonat)
<details>
<summary>Changes</summary>
Previously the function `RangeConstraintManager::printValue()` crashed when it encountered an empty rangeset (because `RangeSet::getBitwidth()` and `RangeSet::isUnsigned()` assert that the rangeset is not empty). This commit adds a special case that avoids this behavior.
As `printValue()` is only used by the checker debug.ExprInspection (and during manual debugging), the impacts of this commit are very limited.
---
Full diff: https://github.com/llvm/llvm-project/pull/79446.diff
1 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+6-2)
``````````diff
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 25d066c4652f2b..cc1cad1e002cdf 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -3270,8 +3270,12 @@ void RangeConstraintManager::printJson(raw_ostream &Out, ProgramStateRef State,
void RangeConstraintManager::printValue(raw_ostream &Out, ProgramStateRef State,
SymbolRef Sym) {
const RangeSet RS = getRange(State, Sym);
- Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
- RS.dump(Out);
+ if (RS.isEmpty()) {
+ Out << "<empty rangeset>";
+ } else {
+ Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
+ RS.dump(Out);
+ }
}
static std::string toString(const SymbolRef &Sym) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/79446
More information about the cfe-commits
mailing list