[analyzer] Fix assertion in simplifySymbolCast

Depends on D128068.
Added a new test code that fails an assertion in the baseline.
That is because `getAPSIntType` works only with integral types.

Differential Revision: https://reviews.llvm.org/D126779
This commit is contained in:
Gabor Marton
2022-06-01 16:29:51 +02:00
parent 5d7fa481cf
commit 2df120784a
2 changed files with 13 additions and 0 deletions

View File

@@ -1103,6 +1103,10 @@ nonloc::SymbolVal SValBuilder::simplifySymbolCast(nonloc::SymbolVal V,
SymbolRef RootSym = cast<SymbolCast>(SE)->getOperand();
QualType RT = RootSym->getType().getCanonicalType();
// FIXME support simplification from non-integers.
if (!RT->isIntegralOrEnumerationType())
return makeNonLoc(SE, T, CastTy);
BasicValueFactory &BVF = getBasicValueFactory();
APSIntType CTy = BVF.getAPSIntType(CastTy);
APSIntType TTy = BVF.getAPSIntType(T);

View File

@@ -11,6 +11,15 @@ using ullong = unsigned long long;
template <typename T>
void clang_analyzer_dump(T);
void test_double(int n) {
double D = n / 30;
clang_analyzer_dump(D); // expected-warning{{(double) ((reg_$0<int n>) / 30)}}
char C = D;
clang_analyzer_dump(C); // expected-warning{{(char) ((double) ((reg_$0<int n>) / 30))}}
int I = C; // assertion should not fail here!
clang_analyzer_dump(I); // expected-warning{{(int) ((char) ((double) ((reg_$0<int n>) / 30)))}}
}
void test_schar(schar x) {
clang_analyzer_dump(x); // expected-warning{{reg_$0<schar x>}}