[clang] 9b71393 - [analyzer] Avoid a crash in a debug printout function (#79446)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 25 08:03:13 PST 2024


Author: NagyDonat
Date: 2024-01-25T17:03:09+01:00
New Revision: 9b71393569ae4508d78b8a21993c21530bfdccc5

URL: https://github.com/llvm/llvm-project/commit/9b71393569ae4508d78b8a21993c21530bfdccc5
DIFF: https://github.com/llvm/llvm-project/commit/9b71393569ae4508d78b8a21993c21530bfdccc5.diff

LOG: [analyzer] Avoid a crash in a debug printout function (#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.

---------

Co-authored-by: Balazs Benics <benicsbalazs at gmail.com>

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 25d066c4652f2b..2d8498e3601556 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -3270,6 +3270,10 @@ void RangeConstraintManager::printJson(raw_ostream &Out, ProgramStateRef State,
 void RangeConstraintManager::printValue(raw_ostream &Out, ProgramStateRef State,
                                         SymbolRef Sym) {
   const RangeSet RS = getRange(State, Sym);
+  if (RS.isEmpty()) {
+    Out << "<empty rangeset>";
+    return;
+  }
   Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
   RS.dump(Out);
 }


        


More information about the cfe-commits mailing list