[PATCH] D43741: [Analyzer] More accurate modeling about the increment operator of the operand with type bool.

Henry Wong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 25 06:05:30 PST 2018


MTC created this revision.
MTC added reviewers: alexshap, NoQ, dcoughlin.
Herald added subscribers: cfe-commits, a.sidorin, szepet, xazax.hun.
Herald added a reviewer: george.karpenkov.

There is a problem with analyzer that a wrong value is given when modeling the increment operator of the operand with type bool. After `rL307604` is applied, a unsigned overflow may occur.

Example:

  void func() {
    bool b = true;
    // unsigned overflow occur, 2 -> 0 U1b
    b++;
  }

The use of an operand of type bool with the ++ operators is deprecated but valid untill C++17. And if the operand of the increment operator is of type bool, it is set to true.

This patch includes two parts:

- If the operand of the increment operator is of type bool, set to true.
- Modify `BasicValueFactory::getTruthValue()`, use `getIntWidth()` instead `getTypeSize()` and use `unsigned` instead `signed`.


Repository:
  rC Clang

https://reviews.llvm.org/D43741

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  test/Analysis/bool.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43741.135820.patch
Type: text/x-patch
Size: 3857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180225/cf75406b/attachment.bin>


More information about the cfe-commits mailing list