[Analyzer] Infer 0 value when the divisible is 0 (bug fix)
authorGabor Marton <gabor.marton@ericsson.com>
Thu, 25 Mar 2021 14:29:41 +0000 (15:29 +0100)
committerGabor Marton <gabor.marton@ericsson.com>
Thu, 25 Mar 2021 17:25:06 +0000 (18:25 +0100)
commit015c39882ebc1771713a7523ae76903ebae83288
treedc476815f4abe7d28bd774bf1b4bdd6e4d5eb410
parent0324b46cd873abc4fabe19f4bd468d10398ffd0d
[Analyzer] Infer 0 value when the divisible is 0 (bug fix)

Currently, we infer 0 if the divisible of the modulo op is 0:
  int a = x < 0; // a can be 0
  int b = a % y; // b is either 1 % sym or 0
However, we don't when the op is / :
  int a = x < 0; // a can be 0
  int b = a / y; // b is either 1 / sym or 0 / sym

This commit fixes the discrepancy.

Differential Revision: https://reviews.llvm.org/D99343
clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
clang/test/Analysis/zero-operands.c [new file with mode: 0644]