[all-commits] [llvm/llvm-project] 1c38c4: [clang-tidy] Make `P +- BS / sizeof(*P)` opt-outab...

whisperity via All-commits all-commits at lists.llvm.org
Tue Oct 15 05:43:19 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1c38c46b083315e3a621267c9a90e8a7750f3700
      https://github.com/llvm/llvm-project/commit/1c38c46b083315e3a621267c9a90e8a7750f3700
  Author: whisperity <whisperity at gmail.com>
  Date:   2024-10-15 (Tue, 15 Oct 2024)

  Changed paths:
    M clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
    M clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
    M clang-tools-extra/docs/ReleaseNotes.rst
    M clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
    A clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics-no-division.c
    M clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics.c

  Log Message:
  -----------
  [clang-tidy] Make `P +- BS / sizeof(*P)` opt-outable in `bugprone-sizeof-expression` (#111178)

In some cases and for projects that deal with a lot of low-level buffers, a
pattern often emerges that an array and its full size, not in the number of
"elements" but in "bytes", are known with no syntax-level connection between
the two values.
To access the array elements, the pointer arithmetic involved will have
to divide 'SizeInBytes' (a numeric value) with `sizeof(*Buffer)`.
Since the previous patch introduced this new warning, potential
false-positives were triggered from `bugprone-sizeof-expression`, as `sizeof`
appeared in pointer arithmetic where integers are scaled.

This patch adds a new check option, `WarnOnOffsetDividedBySizeOf`, which allows
users to opt out of warning about the division case.
In arbitrary projects, it might still be worthwhile to get these warnings until
an opt-out from the detection of scaling issues, especially if a project
might not be using low-level buffers intensively.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list