diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ b/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.