diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp index f827f43eaa7d..4fe828bdf768 100644 --- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -598,9 +598,11 @@ SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val, APSIntType ToType(getContext().getTypeSize(castTy), castTy->isUnsignedIntegerType()); llvm::APSInt ToTypeMax = ToType.getMaxValue(); - - NonLoc ToTypeMaxVal = makeIntVal(ToTypeMax); - + NonLoc ToTypeMaxVal = + makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue() + : ToTypeMax.getSExtValue(), + castTy) + .castAs(); // Check the range of the symbol being casted against the maximum value of the // target type. NonLoc FromVal = val.castAs(); diff --git a/clang/test/Analysis/bitint-no-crash.c b/clang/test/Analysis/bitint-no-crash.c deleted file mode 100644 index 6fa041974a3c..000000000000 --- a/clang/test/Analysis/bitint-no-crash.c +++ /dev/null @@ -1,11 +0,0 @@ - // RUN: %clang_analyze_cc1 -analyzer-checker=core \ - // RUN: -analyzer-checker=debug.ExprInspection \ - // RUN: -verify %s - -// Don't crash when using _BitInt() -// expected-no-diagnostics -_BitInt(256) a; -_BitInt(129) b; -void c() { - b = a; -}