[PATCH] D75529: [analyzer] Limit UCharMax to min of max uchar or max int

Vince Bridgers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 3 08:06:08 PST 2020


vabridgers created this revision.
vabridgers added reviewers: martong, Szelethus, NoQ.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, kristof.beyls, xazax.hun.
Herald added a project: clang.

This change is a follow up to commit 536456a7e93d73b9ff4e92f3e51d1aa1c72628fe <https://reviews.llvm.org/rG536456a7e93d73b9ff4e92f3e51d1aa1c72628fe>
and limits UCharMax to the min of the maximum values for the
architecture's maximum unsigned char or maximum int values. This is
required for architectures where these values are different than the
most commonly supported architectures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75529

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -510,8 +510,13 @@
   const RangeInt LongMax = BVF.getMaxValue(LongTy).getLimitedValue();
   const RangeInt LongLongMax = BVF.getMaxValue(LongLongTy).getLimitedValue();
 
-  const RangeInt UCharMax =
-      BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue();
+  // Set UCharMax to min of int or uchar maximum value.
+  // The C standard states that functions like isalpha must be representable
+  // as an unsigned char. Their type is 'int', so the max value of the
+  // argument should be min(UCharMax, IntMax). This just happen to be true
+  // for commonly used and well tested ISAs, but not for others. 
+  const RangeInt UCharMax = std::min(
+      BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue(), IntMax);
 
   // The platform dependent value of EOF.
   // Try our best to parse this from the Preprocessor, otherwise fallback to -1.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75529.247907.patch
Type: text/x-patch
Size: 1131 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200303/edeeda04/attachment.bin>


More information about the cfe-commits mailing list