[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:07 PST 2024


https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/79446

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.

>From 2a1bb37fef538ecfde67f10c50df07100cc3b69a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= <donat.nagy at ericsson.com>
Date: Thu, 25 Jan 2024 14:13:03 +0100
Subject: [PATCH] [analyzer] Avoid a crash in a debug printout function

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.
---
 clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

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) {



More information about the cfe-commits mailing list