diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp index 4fe828bdf7681f..f827f43eaa7da6 100644 --- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -598,11 +598,9 @@ SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val, APSIntType ToType(getContext().getTypeSize(castTy), castTy->isUnsignedIntegerType()); llvm::APSInt ToTypeMax = ToType.getMaxValue(); - NonLoc ToTypeMaxVal = - makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue() - : ToTypeMax.getSExtValue(), - castTy) - .castAs(); + + NonLoc ToTypeMaxVal = makeIntVal(ToTypeMax); + // 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 new file mode 100644 index 00000000000000..6fa041974a3c98 --- /dev/null +++ b/clang/test/Analysis/bitint-no-crash.c @@ -0,0 +1,11 @@ + // 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; +}