Skip to content

Commit fc90edd

Browse files
committed
fix: Rename the new option as per review request
1 parent 4415aaf commit fc90edd

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
7171
WarnOnSizeOfPointerToAggregate(
7272
Options.get("WarnOnSizeOfPointerToAggregate", true)),
7373
WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)),
74-
WarnOnSizeOfPointerArithmeticWithDivisionScaled(Options.get(
75-
"WarnOnSizeOfPointerArithmeticWithDivisionScaled", true)) {}
74+
WarnOnArithmeticWithDivisionBySizeOf(
75+
Options.get("WarnOnArithmeticWithDivisionBySizeOf", true)) {}
7676

7777
void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
7878
Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -84,8 +84,8 @@ void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
8484
Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
8585
WarnOnSizeOfPointerToAggregate);
8686
Options.store(Opts, "WarnOnSizeOfPointer", WarnOnSizeOfPointer);
87-
Options.store(Opts, "WarnOnSizeOfPointerArithmeticWithDivisionScaled",
88-
WarnOnSizeOfPointerArithmeticWithDivisionScaled);
87+
Options.store(Opts, "WarnOnArithmeticWithDivisionBySizeOf",
88+
WarnOnArithmeticWithDivisionBySizeOf);
8989
}
9090

9191
void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -310,13 +310,10 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
310310
unaryExprOrTypeTraitExpr(ofKind(UETT_AlignOf)),
311311
offsetOfExpr()))
312312
.bind("sizeof-in-ptr-arithmetic-scale-expr");
313-
const auto PtrArithmeticIntegerScaleExprInterestingOperatorNames = [this] {
314-
if (WarnOnSizeOfPointerArithmeticWithDivisionScaled)
315-
return binaryOperator(hasAnyOperatorName("*", "/"));
316-
return binaryOperator(hasOperatorName("*"));
317-
};
318313
const auto PtrArithmeticIntegerScaleExpr = binaryOperator(
319-
PtrArithmeticIntegerScaleExprInterestingOperatorNames(),
314+
WarnOnArithmeticWithDivisionBySizeOf
315+
? binaryOperator(hasAnyOperatorName("*", "/"))
316+
: binaryOperator(hasOperatorName("*")),
320317
// sizeof(...) * sizeof(...) and sizeof(...) / sizeof(...) is handled
321318
// by this check on another path.
322319
hasOperands(expr(hasType(isInteger()), unless(SizeofLikeScaleExpr)),

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SizeofExpressionCheck : public ClangTidyCheck {
3131
const bool WarnOnSizeOfCompareToConstant;
3232
const bool WarnOnSizeOfPointerToAggregate;
3333
const bool WarnOnSizeOfPointer;
34-
const bool WarnOnSizeOfPointerArithmeticWithDivisionScaled;
34+
const bool WarnOnArithmeticWithDivisionBySizeOf;
3535
};
3636

3737
} // namespace clang::tidy::bugprone

clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ While scaling an integer up (multiplying) with ``sizeof`` is likely **always**
229229
an issue, a scaling down (division) is not always inherently dangerous, in case
230230
the developer is aware that the division happens between an appropriate number
231231
of _bytes_ and a ``sizeof`` value.
232-
Turning :option:`WarnOnSizeOfPointerArithmeticWithDivisionScaledInteger` off
233-
will restrict the warnings to the multiplication case.
232+
Turning :option:`WarnOnArithmeticWithDivisionBySizeOf` off will restrict the
233+
warnings to the multiplication case.
234234

235235
This case also checks suspicious ``alignof`` and ``offsetof`` usages in
236236
pointer arithmetic, as both return the "size" in bytes and not elements,
@@ -311,7 +311,7 @@ Options
311311
idiomatic expressions that are probably intentional and correct).
312312
This detects occurrences of CWE 467. Default is `false`.
313313

314-
.. option:: WarnOnSizeOfPointerArithmeticWithDivisionScaledInteger
314+
.. option:: WarnOnArithmeticWithDivisionBySizeOWarnOnArithmeticWithDivisionBySizeOf
315315

316316
When `true`, the check will warn on pointer arithmetic where the
317317
element count is obtained from a division with ``sizeof(...)``,

clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics-no-division.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %check_clang_tidy %s bugprone-sizeof-expression %t -- \
2-
// RUN: -config="{CheckOptions: [{key: bugprone-sizeof-expression.WarnOnSizeOfPointerArithmeticWithDivisionScaled, value: 0}]}"
2+
// RUN: -config='{CheckOptions: { \
3+
// RUN: bugprone-sizeof-expression.WarnOnArithmeticWithDivisionBySizeOf: false \
4+
// RUN: }}'
35

46
typedef __SIZE_TYPE__ size_t;
57

0 commit comments

Comments
 (0)