[all-commits] [llvm/llvm-project] 25b969: [analyzer] Upstream BitwiseShiftChecker

DonatNagyE via All-commits all-commits at lists.llvm.org
Fri Aug 18 01:48:20 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 25b9696b61e53a958e217bb3d0eab66350dc187f
      https://github.com/llvm/llvm-project/commit/25b9696b61e53a958e217bb3d0eab66350dc187f
  Author: DonĂ¡t Nagy <donat.nagy at ericsson.com>
  Date:   2023-08-18 (Fri, 18 Aug 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/docs/analyzer/checkers.rst
    M clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
    A clang/lib/StaticAnalyzer/Checkers/BitwiseShiftChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
    M clang/test/Analysis/analyzer-config.c
    M clang/test/Analysis/analyzer-enabled-checkers.c
    M clang/test/Analysis/bitwise-ops-nocrash.c
    M clang/test/Analysis/bitwise-ops.c
    A clang/test/Analysis/bitwise-shift-common.c
    A clang/test/Analysis/bitwise-shift-pedantic.c
    A clang/test/Analysis/bitwise-shift-sanity-checks.c
    A clang/test/Analysis/bitwise-shift-state-update.c
    M clang/test/Analysis/casts.c
    M clang/test/Analysis/diagnostics/track_subexpressions.cpp
    M clang/test/Analysis/left-shift-cxx2a.cpp
    M clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
    M clang/test/Analysis/symbol-simplification-nonloc-loc.cpp

  Log Message:
  -----------
  [analyzer] Upstream BitwiseShiftChecker

This commit releases a checker that was developed to a stable level in
the Ericsson-internal fork of Clang Static Analyzer.

Note that the functionality of this checker overlaps with
core.UndefinedBinaryOperatorResult ("UBOR"), but there are several
differences between them:
(1) UBOR is only triggered when the constant folding performed by the
Clang Static Analyzer engine determines that the value of a binary
operator expression is undefined; this checker can report issues where
the operands are not constants.
(2) UBOR has unrelated checks for handling other binary operators, this
checker only examines bitwise shifts.
(3) This checker has a Pedantic flag and by default does not report
expressions (e.g. -2 << 2) that're undefined by the standard but
consistently supported in practice.
(4) UBOR exhibits buggy behavior in code that involves cast expressions,
e.g.
    void foo(unsigned short s) {
      if (s == 2) {
        (void) ((unsigned int) s) << 16;
      }
    }

Later it would be good to eliminate this overlap (perhaps by deprecating
and then eliminating the bitwise shift handling in UBOR), but in my
opinion that belongs to separate commits.

Differential Revision: https://reviews.llvm.org/D156312

Co-authored-by: Endre Fulop <endre.fulop at sigmatechnology.se>




More information about the All-commits mailing list