This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix the Z3 backend always generating unsigned APSInt
ClosedPublic

Authored by mikhail.ramalho on Jul 13 2018, 10:07 AM.

Details

Summary

In toAPSInt, the Z3 backend was not checking the variable Int's type and was always generating unsigned APSInts.

This was found by accident when I removed:

    llvm::APSInt ConvertedLHS, ConvertedRHS;
    QualType LTy, RTy;
    std::tie(ConvertedLHS, LTy) = fixAPSInt(*LHS);
    std::tie(ConvertedRHS, RTy) = fixAPSInt(*RHS);
-    doIntTypePromotion<llvm::APSInt, Z3ConstraintManager::castAPSInt>(
-        ConvertedLHS, LTy, ConvertedRHS, RTy);
    return BVF.evalAPSInt(BSE->getOpcode(), ConvertedLHS, ConvertedRHS);

And the BasicValueFactory started to complain about different signedness.

Diff Detail

Repository
rC Clang

Event Timeline

ddcc added a comment.Jul 13 2018, 10:13 AM

I recall that this problem extends beyond the Z3ConstraintManager. Have you looked at D28955, specifically the changes to BasicValueFactory.h?

I recall that this problem extends beyond the Z3ConstraintManager. Have you looked at D28955, specifically the changes to BasicValueFactory.h?

I did but the changes in this patch fix all the "wrong signedness" crashes in our regressions (when we remove the doIntTypeConversion call).

It doesn't solve all the issues though, as the CSA seems to ignore a number of type casts, but that's not the goal of this patch.

ddcc accepted this revision.Jul 13 2018, 10:23 AM
This revision is now accepted and ready to land.Jul 13 2018, 10:23 AM
This revision was automatically updated to reflect the committed changes.