This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix assertion failure in SMT conversion for unary operator on floats.
ClosedPublic

Authored by tomasz-kaminski-sonarsource on Jan 3 2023, 5:55 AM.

Details

Summary

In the handling of the Symbols from the RangExpr, the code assumed that the operands of the unary operators need to have integral type.
However, the CSA can create SymExpr with a floating point operand, when the integer value is cast into it, like (float)h == (float)l where both of h and l are integers.

This patch handles such situations, by using fromFloatUnOp instead of fromUnOp, when the operand have a floating point type.

I have investigated all other calls of fromUnOp, and for one in:

  • getZeroExpr is applied only on boolean types, so it correct
  • fromBinOp is not invoked for floating points
  • fromFloatUnOp I am uncertain about this case and I was not able to produce a test that would reach this point, as a negation of floating points numbers seem to produce Unknown symbols.,

This issue exists since the introduction of UnarySymExpr in https://reviews.llvm.org/D125318 and their handling for Z3 in https://reviews.llvm.org/D125547.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald Transcript
tomasz-kaminski-sonarsource requested review of this revision.Jan 3 2023, 5:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 5:55 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Jan 19 2023, 12:58 PM
This revision was landed with ongoing or failed builds.Jan 26 2023, 8:36 AM
This revision was automatically updated to reflect the committed changes.

I'm proposing to backport this fix to clang-16.
https://github.com/llvm/llvm-project/issues/61097