From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- tools/clang-tidy/config.yaml | 327 +++++++++++++++++++++ .../clang-tidy/test/bugprone-argument-comment.cpp | 6 + .../clang-tidy/test/bugprone-argument-comment.json | 13 + .../test/bugprone-assert-side-effect.cpp | 8 + .../test/bugprone-assert-side-effect.json | 8 + .../bugprone-bool-pointer-implicit-conversion.cpp | 20 ++ .../bugprone-bool-pointer-implicit-conversion.json | 8 + .../bugprone-forward-declaration-namespace.cpp | 3 + .../bugprone-forward-declaration-namespace.json | 8 + .../test/bugprone-incorrect-roundings.cpp | 7 + .../test/bugprone-incorrect-roundings.json | 8 + .../clang-tidy/test/bugprone-integer-division.cpp | 5 + .../clang-tidy/test/bugprone-integer-division.json | 8 + .../clang-tidy/test/bugprone-macro-parentheses.cpp | 5 + .../test/bugprone-macro-parentheses.json | 28 ++ .../test/bugprone-macro-repeated-side-effects.cpp | 28 ++ .../test/bugprone-macro-repeated-side-effects.json | 8 + .../test/bugprone-misplaced-widening-cast.cpp | 3 + .../test/bugprone-misplaced-widening-cast.json | 8 + .../test/bugprone-move-forwarding-reference.cpp | 25 ++ .../test/bugprone-move-forwarding-reference.json | 8 + .../test/bugprone-multiple-statement-macro.cpp | 10 + .../test/bugprone-multiple-statement-macro.json | 7 + .../clang-tidy/test/bugprone-sizeof-expression.cpp | 3 + .../test/bugprone-sizeof-expression.json | 8 + .../test/bugprone-string-constructor.cpp | 17 ++ .../test/bugprone-string-constructor.json | 18 ++ .../test/bugprone-string-integer-assignment.cpp | 28 ++ .../test/bugprone-string-integer-assignment.json | 13 + .../test/bugprone-suspicious-memset-usage.cpp | 22 ++ .../test/bugprone-suspicious-memset-usage.json | 18 ++ .../test/bugprone-suspicious-missing-comma.cpp | 9 + .../test/bugprone-suspicious-missing-comma.json | 8 + .../test/bugprone-suspicious-semicolon.cpp | 8 + .../test/bugprone-suspicious-semicolon.json | 8 + .../test/bugprone-suspicious-string-compare.cpp | 8 + .../test/bugprone-suspicious-string-compare.json | 8 + .../clang-tidy/test/bugprone-swapped-arguments.cpp | 26 ++ .../test/bugprone-swapped-arguments.json | 23 ++ .../test/bugprone-too-small-loop-variable.cpp | 4 + .../test/bugprone-too-small-loop-variable.json | 8 + tools/clang-tidy/test/bugprone-unused-raii.cpp | 25 ++ tools/clang-tidy/test/bugprone-unused-raii.json | 8 + tools/clang-tidy/test/bugprone-use-after-move.cpp | 62 ++++ tools/clang-tidy/test/bugprone-use-after-move.json | 4 + .../test/clang-analyzer-core.CallAndMessage.cpp | 10 + .../test/clang-analyzer-core.CallAndMessage.json | 8 + .../test/clang-analyzer-core.DivideZero.cpp | 4 + .../test/clang-analyzer-core.DivideZero.json | 4 + .../clang-analyzer-core.NonNullParamChecker.cpp | 6 + .../clang-analyzer-core.NonNullParamChecker.json | 8 + .../test/clang-analyzer-core.NullDereference.cpp | 9 + .../test/clang-analyzer-core.NullDereference.json | 8 + ...analyzer-core.UndefinedBinaryOperatorResult.cpp | 4 + ...nalyzer-core.UndefinedBinaryOperatorResult.json | 8 + .../clang-analyzer-core.uninitialized.Assign.cpp | 4 + .../clang-analyzer-core.uninitialized.Assign.json | 8 + .../clang-analyzer-core.uninitialized.Branch.cpp | 6 + .../clang-analyzer-core.uninitialized.Branch.json | 8 + .../test/clang-analyzer-cplusplus.Move.cpp | 10 + .../test/clang-analyzer-cplusplus.Move.json | 8 + .../test/clang-analyzer-cplusplus.NewDelete.cpp | 50 ++++ .../test/clang-analyzer-cplusplus.NewDelete.json | 23 ++ .../clang-analyzer-cplusplus.NewDeleteLeaks.cpp | 6 + .../clang-analyzer-cplusplus.NewDeleteLeaks.json | 8 + .../test/clang-analyzer-deadcode.DeadStores.cpp | 6 + .../test/clang-analyzer-deadcode.DeadStores.json | 8 + .../clang-analyzer-optin.performance.Padding.cpp | 6 + .../clang-analyzer-optin.performance.Padding.json | 8 + .../clang-analyzer-security.FloatLoopCounter.cpp | 3 + .../clang-analyzer-security.FloatLoopCounter.json | 8 + ...alyzer-security.insecureAPI.UncheckedReturn.cpp | 5 + ...lyzer-security.insecureAPI.UncheckedReturn.json | 8 + .../clang-analyzer-security.insecureAPI.bcmp.cpp | 5 + .../clang-analyzer-security.insecureAPI.bcmp.json | 8 + .../clang-analyzer-security.insecureAPI.bcopy.cpp | 5 + .../clang-analyzer-security.insecureAPI.bcopy.json | 8 + .../clang-analyzer-security.insecureAPI.bzero.cpp | 5 + .../clang-analyzer-security.insecureAPI.bzero.json | 8 + .../clang-analyzer-security.insecureAPI.getpw.cpp | 6 + .../clang-analyzer-security.insecureAPI.getpw.json | 8 + .../clang-analyzer-security.insecureAPI.gets.cpp | 6 + .../clang-analyzer-security.insecureAPI.gets.json | 1 + ...clang-analyzer-security.insecureAPI.mkstemp.cpp | 5 + ...lang-analyzer-security.insecureAPI.mkstemp.json | 8 + .../clang-analyzer-security.insecureAPI.mktemp.cpp | 5 + ...clang-analyzer-security.insecureAPI.mktemp.json | 8 + .../clang-analyzer-security.insecureAPI.rand.cpp | 4 + .../clang-analyzer-security.insecureAPI.rand.json | 1 + .../clang-analyzer-security.insecureAPI.strcpy.cpp | 7 + ...clang-analyzer-security.insecureAPI.strcpy.json | 1 + .../clang-analyzer-security.insecureAPI.vfork.cpp | 5 + .../clang-analyzer-security.insecureAPI.vfork.json | 8 + .../clang-tidy/test/clang-analyzer-unix.Malloc.cpp | 37 +++ .../test/clang-analyzer-unix.Malloc.json | 20 ++ .../clang-analyzer-unix.cstring.BadSizeArg.cpp | 9 + .../clang-analyzer-unix.cstring.BadSizeArg.json | 8 + .../test/clang-analyzer-unix.cstring.NullArg.cpp | 14 + .../test/clang-analyzer-unix.cstring.NullArg.json | 8 + .../cppcoreguidelines-narrowing-conversions.cpp | 4 + .../cppcoreguidelines-narrowing-conversions.json | 8 + .../cppcoreguidelines-pro-type-member-init.cpp | 7 + .../cppcoreguidelines-pro-type-member-init.json | 8 + .../clang-tidy/test/misc-non-copyable-objects.cpp | 5 + .../clang-tidy/test/misc-non-copyable-objects.json | 8 + .../clang-tidy/test/misc-redundant-expression.cpp | 3 + .../clang-tidy/test/misc-redundant-expression.json | 8 + tools/clang-tidy/test/misc-unused-alias-decls.cpp | 18 ++ tools/clang-tidy/test/misc-unused-alias-decls.json | 13 + tools/clang-tidy/test/misc-unused-using-decls.cpp | 4 + tools/clang-tidy/test/misc-unused-using-decls.json | 4 + tools/clang-tidy/test/modernize-avoid-bind.cpp | 6 + tools/clang-tidy/test/modernize-avoid-bind.json | 4 + .../test/modernize-concat-nested-namespaces.cpp | 5 + .../test/modernize-concat-nested-namespaces.json | 8 + .../test/modernize-deprecated-ios-base-aliases.cpp | 18 ++ .../modernize-deprecated-ios-base-aliases.json | 8 + tools/clang-tidy/test/modernize-loop-convert.cpp | 7 + tools/clang-tidy/test/modernize-loop-convert.json | 4 + .../test/modernize-raw-string-literal.cpp | 1 + .../test/modernize-raw-string-literal.json | 8 + .../test/modernize-redundant-void-arg.cpp | 5 + .../test/modernize-redundant-void-arg.json | 1 + tools/clang-tidy/test/modernize-shrink-to-fit.cpp | 10 + tools/clang-tidy/test/modernize-shrink-to-fit.json | 13 + tools/clang-tidy/test/modernize-use-auto.cpp | 11 + tools/clang-tidy/test/modernize-use-auto.json | 1 + .../test/modernize-use-bool-literals.cpp | 5 + .../test/modernize-use-bool-literals.json | 23 ++ .../test/modernize-use-equals-default.cpp | 6 + .../test/modernize-use-equals-default.json | 13 + .../test/modernize-use-equals-delete.cpp | 7 + .../test/modernize-use-equals-delete.json | 23 ++ tools/clang-tidy/test/modernize-use-nullptr.cpp | 5 + tools/clang-tidy/test/modernize-use-nullptr.json | 1 + tools/clang-tidy/test/modernize-use-override.cpp | 8 + tools/clang-tidy/test/modernize-use-override.json | 1 + tools/clang-tidy/test/modernize-use-using.cpp | 5 + tools/clang-tidy/test/modernize-use-using.json | 5 + .../test/performance-faster-string-find.cpp | 6 + .../test/performance-faster-string-find.json | 8 + .../clang-tidy/test/performance-for-range-copy.cpp | 30 ++ .../test/performance-for-range-copy.json | 8 + .../performance-implicit-conversion-in-loop.cpp | 43 +++ .../performance-implicit-conversion-in-loop.json | 8 + .../test/performance-inefficient-algorithm.cpp | 30 ++ .../test/performance-inefficient-algorithm.json | 8 + ...erformance-inefficient-string-concatenation.cpp | 13 + ...rformance-inefficient-string-concatenation.json | 8 + .../performance-inefficient-vector-operation.cpp | 10 + .../performance-inefficient-vector-operation.json | 8 + .../clang-tidy/test/performance-move-const-arg.cpp | 33 +++ .../test/performance-move-const-arg.json | 8 + .../test/performance-move-constructor-init.cpp | 11 + .../test/performance-move-constructor-init.json | 8 + .../test/performance-noexcept-move-constructor.cpp | 4 + .../performance-noexcept-move-constructor.json | 13 + .../test/performance-type-promotion-in-math-fn.cpp | 7 + .../performance-type-promotion-in-math-fn.json | 8 + ...performance-unnecessary-copy-initialization.cpp | 7 + ...erformance-unnecessary-copy-initialization.json | 8 + .../test/performance-unnecessary-value-param.cpp | 4 + .../test/performance-unnecessary-value-param.json | 8 + .../test/readability-braces-around-statements.cpp | 38 +++ .../test/readability-braces-around-statements.json | 13 + .../test/readability-const-return-type.cpp | 5 + .../test/readability-const-return-type.json | 8 + .../test/readability-container-size-empty.cpp | 7 + .../test/readability-container-size-empty.json | 8 + .../test/readability-delete-null-pointer.cpp | 6 + .../test/readability-delete-null-pointer.json | 8 + .../test/readability-else-after-return.cpp | 10 + .../test/readability-else-after-return.json | 8 + .../test/readability-implicit-bool-conversion.cpp | 55 ++++ .../test/readability-implicit-bool-conversion.json | 102 +++++++ ...ity-inconsistent-declaration-parameter-name.cpp | 6 + ...ty-inconsistent-declaration-parameter-name.json | 8 + .../test/readability-isolate-declaration.cpp | 7 + .../test/readability-isolate-declaration.json | 8 + .../clang-tidy/test/readability-magic-numbers.cpp | 4 + .../clang-tidy/test/readability-magic-numbers.json | 8 + .../test/readability-misleading-indentation.cpp | 20 ++ .../test/readability-misleading-indentation.json | 8 + .../test/readability-non-const-parameter.cpp | 5 + .../test/readability-non-const-parameter.json | 8 + .../clang-tidy/test/readability-qualified-auto.cpp | 6 + .../test/readability-qualified-auto.json | 8 + .../test/readability-redundant-control-flow.cpp | 5 + .../test/readability-redundant-control-flow.json | 8 + .../test/readability-redundant-preprocessor.cpp | 5 + .../test/readability-redundant-preprocessor.json | 8 + .../test/readability-redundant-smartptr-get.cpp | 19 ++ .../test/readability-redundant-smartptr-get.json | 8 + .../test/readability-redundant-string-cstr.cpp | 7 + .../test/readability-redundant-string-cstr.json | 4 + .../test/readability-redundant-string-init.cpp | 5 + .../test/readability-redundant-string-init.json | 8 + .../test/readability-simplify-boolean-expr.cpp | 2 + .../test/readability-simplify-boolean-expr.json | 8 + ...eadability-static-accessed-through-instance.cpp | 11 + ...adability-static-accessed-through-instance.json | 8 + .../test/readability-uniqueptr-delete-release.cpp | 6 + .../test/readability-uniqueptr-delete-release.json | 8 + tools/clang-tidy/test/structures.h | 108 +++++++ 204 files changed, 2548 insertions(+) create mode 100644 tools/clang-tidy/config.yaml create mode 100644 tools/clang-tidy/test/bugprone-argument-comment.cpp create mode 100644 tools/clang-tidy/test/bugprone-argument-comment.json create mode 100644 tools/clang-tidy/test/bugprone-assert-side-effect.cpp create mode 100644 tools/clang-tidy/test/bugprone-assert-side-effect.json create mode 100644 tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.cpp create mode 100644 tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.json create mode 100644 tools/clang-tidy/test/bugprone-forward-declaration-namespace.cpp create mode 100644 tools/clang-tidy/test/bugprone-forward-declaration-namespace.json create mode 100644 tools/clang-tidy/test/bugprone-incorrect-roundings.cpp create mode 100644 tools/clang-tidy/test/bugprone-incorrect-roundings.json create mode 100644 tools/clang-tidy/test/bugprone-integer-division.cpp create mode 100644 tools/clang-tidy/test/bugprone-integer-division.json create mode 100644 tools/clang-tidy/test/bugprone-macro-parentheses.cpp create mode 100644 tools/clang-tidy/test/bugprone-macro-parentheses.json create mode 100644 tools/clang-tidy/test/bugprone-macro-repeated-side-effects.cpp create mode 100644 tools/clang-tidy/test/bugprone-macro-repeated-side-effects.json create mode 100644 tools/clang-tidy/test/bugprone-misplaced-widening-cast.cpp create mode 100644 tools/clang-tidy/test/bugprone-misplaced-widening-cast.json create mode 100644 tools/clang-tidy/test/bugprone-move-forwarding-reference.cpp create mode 100644 tools/clang-tidy/test/bugprone-move-forwarding-reference.json create mode 100644 tools/clang-tidy/test/bugprone-multiple-statement-macro.cpp create mode 100644 tools/clang-tidy/test/bugprone-multiple-statement-macro.json create mode 100644 tools/clang-tidy/test/bugprone-sizeof-expression.cpp create mode 100644 tools/clang-tidy/test/bugprone-sizeof-expression.json create mode 100644 tools/clang-tidy/test/bugprone-string-constructor.cpp create mode 100644 tools/clang-tidy/test/bugprone-string-constructor.json create mode 100644 tools/clang-tidy/test/bugprone-string-integer-assignment.cpp create mode 100644 tools/clang-tidy/test/bugprone-string-integer-assignment.json create mode 100644 tools/clang-tidy/test/bugprone-suspicious-memset-usage.cpp create mode 100644 tools/clang-tidy/test/bugprone-suspicious-memset-usage.json create mode 100644 tools/clang-tidy/test/bugprone-suspicious-missing-comma.cpp create mode 100644 tools/clang-tidy/test/bugprone-suspicious-missing-comma.json create mode 100644 tools/clang-tidy/test/bugprone-suspicious-semicolon.cpp create mode 100644 tools/clang-tidy/test/bugprone-suspicious-semicolon.json create mode 100644 tools/clang-tidy/test/bugprone-suspicious-string-compare.cpp create mode 100644 tools/clang-tidy/test/bugprone-suspicious-string-compare.json create mode 100644 tools/clang-tidy/test/bugprone-swapped-arguments.cpp create mode 100644 tools/clang-tidy/test/bugprone-swapped-arguments.json create mode 100644 tools/clang-tidy/test/bugprone-too-small-loop-variable.cpp create mode 100644 tools/clang-tidy/test/bugprone-too-small-loop-variable.json create mode 100644 tools/clang-tidy/test/bugprone-unused-raii.cpp create mode 100644 tools/clang-tidy/test/bugprone-unused-raii.json create mode 100644 tools/clang-tidy/test/bugprone-use-after-move.cpp create mode 100644 tools/clang-tidy/test/bugprone-use-after-move.json create mode 100644 tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.json create mode 100644 tools/clang-tidy/test/clang-analyzer-core.DivideZero.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-core.DivideZero.json create mode 100644 tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.json create mode 100644 tools/clang-tidy/test/clang-analyzer-core.NullDereference.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-core.NullDereference.json create mode 100644 tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.json create mode 100644 tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.json create mode 100644 tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.json create mode 100644 tools/clang-tidy/test/clang-analyzer-cplusplus.Move.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-cplusplus.Move.json create mode 100644 tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.json create mode 100644 tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.json create mode 100644 tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.json create mode 100644 tools/clang-tidy/test/clang-analyzer-optin.performance.Padding.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-optin.performance.Padding.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.json create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.json create mode 100644 tools/clang-tidy/test/clang-analyzer-unix.Malloc.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-unix.Malloc.json create mode 100644 tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.json create mode 100644 tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.cpp create mode 100644 tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.json create mode 100644 tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.cpp create mode 100644 tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.json create mode 100644 tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.cpp create mode 100644 tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.json create mode 100644 tools/clang-tidy/test/misc-non-copyable-objects.cpp create mode 100644 tools/clang-tidy/test/misc-non-copyable-objects.json create mode 100644 tools/clang-tidy/test/misc-redundant-expression.cpp create mode 100644 tools/clang-tidy/test/misc-redundant-expression.json create mode 100644 tools/clang-tidy/test/misc-unused-alias-decls.cpp create mode 100644 tools/clang-tidy/test/misc-unused-alias-decls.json create mode 100644 tools/clang-tidy/test/misc-unused-using-decls.cpp create mode 100644 tools/clang-tidy/test/misc-unused-using-decls.json create mode 100644 tools/clang-tidy/test/modernize-avoid-bind.cpp create mode 100644 tools/clang-tidy/test/modernize-avoid-bind.json create mode 100644 tools/clang-tidy/test/modernize-concat-nested-namespaces.cpp create mode 100644 tools/clang-tidy/test/modernize-concat-nested-namespaces.json create mode 100644 tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.cpp create mode 100644 tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.json create mode 100644 tools/clang-tidy/test/modernize-loop-convert.cpp create mode 100644 tools/clang-tidy/test/modernize-loop-convert.json create mode 100644 tools/clang-tidy/test/modernize-raw-string-literal.cpp create mode 100644 tools/clang-tidy/test/modernize-raw-string-literal.json create mode 100644 tools/clang-tidy/test/modernize-redundant-void-arg.cpp create mode 100644 tools/clang-tidy/test/modernize-redundant-void-arg.json create mode 100644 tools/clang-tidy/test/modernize-shrink-to-fit.cpp create mode 100644 tools/clang-tidy/test/modernize-shrink-to-fit.json create mode 100644 tools/clang-tidy/test/modernize-use-auto.cpp create mode 100644 tools/clang-tidy/test/modernize-use-auto.json create mode 100644 tools/clang-tidy/test/modernize-use-bool-literals.cpp create mode 100644 tools/clang-tidy/test/modernize-use-bool-literals.json create mode 100644 tools/clang-tidy/test/modernize-use-equals-default.cpp create mode 100644 tools/clang-tidy/test/modernize-use-equals-default.json create mode 100644 tools/clang-tidy/test/modernize-use-equals-delete.cpp create mode 100644 tools/clang-tidy/test/modernize-use-equals-delete.json create mode 100644 tools/clang-tidy/test/modernize-use-nullptr.cpp create mode 100644 tools/clang-tidy/test/modernize-use-nullptr.json create mode 100644 tools/clang-tidy/test/modernize-use-override.cpp create mode 100644 tools/clang-tidy/test/modernize-use-override.json create mode 100644 tools/clang-tidy/test/modernize-use-using.cpp create mode 100644 tools/clang-tidy/test/modernize-use-using.json create mode 100644 tools/clang-tidy/test/performance-faster-string-find.cpp create mode 100644 tools/clang-tidy/test/performance-faster-string-find.json create mode 100644 tools/clang-tidy/test/performance-for-range-copy.cpp create mode 100644 tools/clang-tidy/test/performance-for-range-copy.json create mode 100644 tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp create mode 100644 tools/clang-tidy/test/performance-implicit-conversion-in-loop.json create mode 100644 tools/clang-tidy/test/performance-inefficient-algorithm.cpp create mode 100644 tools/clang-tidy/test/performance-inefficient-algorithm.json create mode 100644 tools/clang-tidy/test/performance-inefficient-string-concatenation.cpp create mode 100644 tools/clang-tidy/test/performance-inefficient-string-concatenation.json create mode 100644 tools/clang-tidy/test/performance-inefficient-vector-operation.cpp create mode 100644 tools/clang-tidy/test/performance-inefficient-vector-operation.json create mode 100644 tools/clang-tidy/test/performance-move-const-arg.cpp create mode 100644 tools/clang-tidy/test/performance-move-const-arg.json create mode 100644 tools/clang-tidy/test/performance-move-constructor-init.cpp create mode 100644 tools/clang-tidy/test/performance-move-constructor-init.json create mode 100644 tools/clang-tidy/test/performance-noexcept-move-constructor.cpp create mode 100644 tools/clang-tidy/test/performance-noexcept-move-constructor.json create mode 100644 tools/clang-tidy/test/performance-type-promotion-in-math-fn.cpp create mode 100644 tools/clang-tidy/test/performance-type-promotion-in-math-fn.json create mode 100644 tools/clang-tidy/test/performance-unnecessary-copy-initialization.cpp create mode 100644 tools/clang-tidy/test/performance-unnecessary-copy-initialization.json create mode 100644 tools/clang-tidy/test/performance-unnecessary-value-param.cpp create mode 100644 tools/clang-tidy/test/performance-unnecessary-value-param.json create mode 100644 tools/clang-tidy/test/readability-braces-around-statements.cpp create mode 100644 tools/clang-tidy/test/readability-braces-around-statements.json create mode 100644 tools/clang-tidy/test/readability-const-return-type.cpp create mode 100644 tools/clang-tidy/test/readability-const-return-type.json create mode 100644 tools/clang-tidy/test/readability-container-size-empty.cpp create mode 100644 tools/clang-tidy/test/readability-container-size-empty.json create mode 100644 tools/clang-tidy/test/readability-delete-null-pointer.cpp create mode 100644 tools/clang-tidy/test/readability-delete-null-pointer.json create mode 100644 tools/clang-tidy/test/readability-else-after-return.cpp create mode 100644 tools/clang-tidy/test/readability-else-after-return.json create mode 100644 tools/clang-tidy/test/readability-implicit-bool-conversion.cpp create mode 100644 tools/clang-tidy/test/readability-implicit-bool-conversion.json create mode 100644 tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.cpp create mode 100644 tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.json create mode 100644 tools/clang-tidy/test/readability-isolate-declaration.cpp create mode 100644 tools/clang-tidy/test/readability-isolate-declaration.json create mode 100644 tools/clang-tidy/test/readability-magic-numbers.cpp create mode 100644 tools/clang-tidy/test/readability-magic-numbers.json create mode 100644 tools/clang-tidy/test/readability-misleading-indentation.cpp create mode 100644 tools/clang-tidy/test/readability-misleading-indentation.json create mode 100644 tools/clang-tidy/test/readability-non-const-parameter.cpp create mode 100644 tools/clang-tidy/test/readability-non-const-parameter.json create mode 100644 tools/clang-tidy/test/readability-qualified-auto.cpp create mode 100644 tools/clang-tidy/test/readability-qualified-auto.json create mode 100644 tools/clang-tidy/test/readability-redundant-control-flow.cpp create mode 100644 tools/clang-tidy/test/readability-redundant-control-flow.json create mode 100644 tools/clang-tidy/test/readability-redundant-preprocessor.cpp create mode 100644 tools/clang-tidy/test/readability-redundant-preprocessor.json create mode 100644 tools/clang-tidy/test/readability-redundant-smartptr-get.cpp create mode 100644 tools/clang-tidy/test/readability-redundant-smartptr-get.json create mode 100644 tools/clang-tidy/test/readability-redundant-string-cstr.cpp create mode 100644 tools/clang-tidy/test/readability-redundant-string-cstr.json create mode 100644 tools/clang-tidy/test/readability-redundant-string-init.cpp create mode 100644 tools/clang-tidy/test/readability-redundant-string-init.json create mode 100644 tools/clang-tidy/test/readability-simplify-boolean-expr.cpp create mode 100644 tools/clang-tidy/test/readability-simplify-boolean-expr.json create mode 100644 tools/clang-tidy/test/readability-static-accessed-through-instance.cpp create mode 100644 tools/clang-tidy/test/readability-static-accessed-through-instance.json create mode 100644 tools/clang-tidy/test/readability-uniqueptr-delete-release.cpp create mode 100644 tools/clang-tidy/test/readability-uniqueptr-delete-release.json create mode 100644 tools/clang-tidy/test/structures.h (limited to 'tools/clang-tidy') diff --git a/tools/clang-tidy/config.yaml b/tools/clang-tidy/config.yaml new file mode 100644 index 0000000000..36053d7870 --- /dev/null +++ b/tools/clang-tidy/config.yaml @@ -0,0 +1,327 @@ +--- +target: obj-x86_64-pc-linux-gnu +# It is used by 'mach static-analysis' and 'phabricator static-analysis bot' +# in order to have consistency across the used checkers. +# All the clang checks used by the static-analysis tools. +# +# To add a new checker: +# 1. Add it in this file +# 2. Create a C/C++ test case in tools/clang-tidy/test/ reproducing the +# warning/error that the checker will detect +# 3. Run './mach static-analysis autotest -d' to create the reference +# 4. Check the json file in tools/clang-tidy/test/ +# 5. Commit this file + the .cpp test case + the json result +platforms: + - linux64 + - macosx64 + - win32 + - win64 +# Minimum clang-tidy version that is required for all the following checkers +# to work properly. +# This is also used by 'mach clang-format' +package_version: "16.0.4" +clang_checkers: + - name: -* + publish: !!bool no + - name: bugprone-argument-comment + reliability: high + - name: bugprone-assert-side-effect + reliability: high + - name: bugprone-bool-pointer-implicit-conversion + reliability: low + - name: bugprone-forward-declaration-namespace + reliability: high + - name: bugprone-incorrect-roundings + reliability: high + - name: bugprone-integer-division + reliability: high + - name: bugprone-macro-parentheses + reliability: medium + - name: bugprone-macro-repeated-side-effects + reliability: high + - name: bugprone-misplaced-widening-cast + reliability: high + - name: bugprone-move-forwarding-reference + reliability: high + - name: bugprone-multiple-statement-macro + # Incompatible with our code base, see bug 1496379. + publish: !!bool no + reliability: high + - name: bugprone-sizeof-expression + reliability: high + - name: bugprone-string-constructor + reliability: high + - name: bugprone-string-integer-assignment + reliability: high + - name: bugprone-suspicious-memset-usage + reliability: high + - name: bugprone-suspicious-missing-comma + reliability: high + - name: bugprone-suspicious-semicolon + reliability: high + - name: bugprone-suspicious-string-compare + reliability: high + - name: bugprone-swapped-arguments + reliability: high + - name: bugprone-too-small-loop-variable + reliability: high + - name: bugprone-unused-raii + reliability: high + - name: bugprone-use-after-move + reliability: high + - name: clang-analyzer-core.CallAndMessage + reliability: medium + - name: clang-analyzer-core.DivideZero + reliability: high + - name: clang-analyzer-core.NonNullParamChecker + reliability: high + - name: clang-analyzer-core.NullDereference + reliability: medium + - name: clang-analyzer-core.UndefinedBinaryOperatorResult + reliability: medium + - name: clang-analyzer-core.uninitialized.Assign + reliability: medium + - name: clang-analyzer-core.uninitialized.Branch + reliability: medium + - name: clang-analyzer-cplusplus.Move + reliability: high + - name: clang-analyzer-cplusplus.NewDelete + reliability: medium + - name: clang-analyzer-cplusplus.NewDeleteLeaks + reliability: medium + - name: clang-analyzer-deadcode.DeadStores + reliability: high + - name: clang-analyzer-optin.performance.Padding + reliability: high + config: + - key: AllowedPad + value: 2 + - name: clang-analyzer-security.FloatLoopCounter + reliability: high + - name: clang-analyzer-security.insecureAPI.bcmp + reliability: high + - name: clang-analyzer-security.insecureAPI.bcopy + reliability: high + - name: clang-analyzer-security.insecureAPI.bzero + reliability: high + - name: clang-analyzer-security.insecureAPI.getpw + reliability: high + # We don't add clang-analyzer-security.insecureAPI.gets here; it's deprecated. + - name: clang-analyzer-security.insecureAPI.mkstemp + reliability: high + - name: clang-analyzer-security.insecureAPI.mktemp + reliability: high + - name: clang-analyzer-security.insecureAPI.rand + reliability: low + # C checker, that is outdated and doesn't check for the new std::rand calls. + publish: !!bool no + - name: clang-analyzer-security.insecureAPI.strcpy + reliability: low + # The functions that should be used differ on POSIX and Windows, and there + # isn't a consensus on how we should approach this. + publish: !!bool no + - name: clang-analyzer-security.insecureAPI.UncheckedReturn + reliability: low + - name: clang-analyzer-security.insecureAPI.vfork + reliability: medium + - name: clang-analyzer-unix.Malloc + reliability: high + - name: clang-analyzer-unix.cstring.BadSizeArg + reliability: high + - name: clang-analyzer-unix.cstring.NullArg + reliability: high + - name: cppcoreguidelines-narrowing-conversions + reliability: high + - name: cppcoreguidelines-pro-type-member-init + reliability: medium + - name: misc-non-copyable-objects + reliability: high + - name: misc-redundant-expression + reliability: medium + - name: misc-unused-alias-decls + reliability: high + - name: misc-unused-using-decls + reliability: high + - name: modernize-avoid-bind + restricted-platforms: + - win32 + - win64 + reliability: medium + - name: modernize-concat-nested-namespaces + reliability: high + - name: modernize-deprecated-ios-base-aliases + reliability: high + - name: modernize-loop-convert + reliability: high + - name: modernize-raw-string-literal + reliability: high + - name: modernize-redundant-void-arg + reliability: high + # We still have some old C code that is built with a C compiler, so this + # might break the build. + publish: !!bool no + - name: modernize-shrink-to-fit + reliability: high + - name: modernize-use-auto + reliability: high + # Controversial, see bug 1371052. + publish: !!bool no + - name: modernize-use-bool-literals + reliability: high + - name: modernize-use-equals-default + reliability: high + - name: modernize-use-equals-delete + reliability: high + - name: modernize-use-nullptr + reliability: high + - name: modernize-use-override + reliability: low + # Too noisy because of the way how we implement NS_IMETHOD. See Bug 1420366. + publish: !!bool no + - name: modernize-use-using + reliability: high + - name: mozilla-* + reliability: high + - name: performance-faster-string-find + reliability: high + - name: performance-for-range-copy + reliability: high + - name: performance-implicit-conversion-in-loop + reliability: high + - name: performance-inefficient-algorithm + restricted-platforms: + - linux64 + - macosx64 + reliability: high + # Disable as the test does not support C++17 yet + publish: !!bool no + - name: performance-inefficient-string-concatenation + reliability: high + - name: performance-inefficient-vector-operation + reliability: high + - name: performance-move-const-arg + reliability: high + config: + - key: CheckTriviallyCopyableMove + # As per Bug 1558359 - disable detection of trivially copyable types + # that do not have a move constructor. + value: 0 + - name: performance-move-constructor-init + reliability: high + - name: performance-noexcept-move-constructor + reliability: high + - name: performance-type-promotion-in-math-fn + reliability: high + - name: performance-unnecessary-copy-initialization + reliability: high + - name: performance-unnecessary-value-param + reliability: high + - name: readability-braces-around-statements + reliability: high + config: + - key: ShortStatementLines + # Allow `if (foo) return;` without braces + # Still warns on `if (foo)\n return;` + value: 1 + - name: readability-const-return-type + reliability: high + # Note: this can be loosened up by using the ShortStatementLines option + - name: readability-container-size-empty + reliability: high + - name: readability-delete-null-pointer + reliability: high + - name: readability-else-after-return + reliability: high + config: + - key: WarnOnConditionVariables + # Disable as we don't mind this kind of behavior + value: 0 + - name: readability-implicit-bool-conversion + reliability: low + # On automation the config flags act strange. Please see Bug 1500241. + publish: !!bool no + config: + - key: AllowIntegerConditions + # The check will allow conditional integer conversions. + value: 1 + - key: AllowPointerConditions + # The check will allow conditional pointer conversions. + value: 1 + - name: readability-inconsistent-declaration-parameter-name + reliability: high + - name: readability-isolate-declaration + # As per bug 1558987 - we don't want to have this enabled + publish: !!bool no + reliability: high + - name: readability-magic-numbers + # Bug 1553495 - we must see first its impact on our code. + publish: !!bool no + reliability: high + - name: readability-misleading-indentation + reliability: high + - name: readability-non-const-parameter + reliability: high + - name: readability-qualified-auto + reliability: high + - name: readability-redundant-control-flow + reliability: high + - name: readability-redundant-preprocessor + reliability: high + - name: readability-redundant-smartptr-get + reliability: high + - name: readability-redundant-string-cstr + reliability: high + - name: readability-redundant-string-init + reliability: high + - name: readability-static-accessed-through-instance + reliability: high + - name: readability-simplify-boolean-expr + reliability: high + config: + - key: SimplifyDeMorgan + # Don't want to enable DeMorgan expressions because of MOZ_ASSERT() + # See Bug 1804160 + value: 0 + - name: readability-uniqueptr-delete-release + reliability: high + # We don't publish the google checkers since we are interested in only having + # a general idea how our code complies with the rules added by these checkers. + - name: google-build-explicit-make-pair + reliability: low + publish: !!bool no + - name: google-build-namespaces + reliability: low + publish: !!bool no + - name: google-build-using-namespace + reliability: low + publish: !!bool no + - name: google-default-arguments + reliability: low + publish: !!bool no + - name: google-explicit-constructor + reliability: low + publish: !!bool no + - name: google-global-names-in-headers + reliability: low + publish: !!bool no + - name: google-readability-casting + reliability: low + publish: !!bool no + - name: google-readability-function-size + reliability: low + publish: !!bool no + - name: google-readability-namespace-comments + reliability: low + publish: !!bool no + - name: google-readability-todo + reliability: low + publish: !!bool no + - name: google-runtime-int + reliability: low + publish: !!bool no + - name: google-runtime-operator + reliability: low + publish: !!bool no + - name: google-runtime-references + reliability: low + publish: !!bool no diff --git a/tools/clang-tidy/test/bugprone-argument-comment.cpp b/tools/clang-tidy/test/bugprone-argument-comment.cpp new file mode 100644 index 0000000000..3099575a35 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-argument-comment.cpp @@ -0,0 +1,6 @@ +// bugprone-argument-comment + +void f(int x, int y); +void g() { + f(/*y=*/0, /*z=*/0); +} diff --git a/tools/clang-tidy/test/bugprone-argument-comment.json b/tools/clang-tidy/test/bugprone-argument-comment.json new file mode 100644 index 0000000000..034f6dbf87 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-argument-comment.json @@ -0,0 +1,13 @@ +[ + [ + "warning", + "argument name 'y' in comment does not match parameter name 'x'", + "bugprone-argument-comment" + ], + [ + "warning", + "argument name 'z' in comment does not match parameter name 'y'", + "bugprone-argument-comment" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-assert-side-effect.cpp b/tools/clang-tidy/test/bugprone-assert-side-effect.cpp new file mode 100644 index 0000000000..7cc0a79cf1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-assert-side-effect.cpp @@ -0,0 +1,8 @@ +#include "structures.h" + +// bugprone-assert-side-effect +void misc_assert_side_effect() { + int X = 0; + assert(X == 1); + assert(X = 1); +} diff --git a/tools/clang-tidy/test/bugprone-assert-side-effect.json b/tools/clang-tidy/test/bugprone-assert-side-effect.json new file mode 100644 index 0000000000..b17a456064 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-assert-side-effect.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "side effect in assert() condition discarded in release builds", + "bugprone-assert-side-effect" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.cpp b/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.cpp new file mode 100644 index 0000000000..602fa9a578 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.cpp @@ -0,0 +1,20 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-bool-pointer-implicit-conversion.html + +bool test(bool* pointer_to_bool, int* pointer_to_int) +{ + if (pointer_to_bool) { // warning for pointer to bool + } + + if (pointer_to_int) { // no warning for pointer to int + } + + if (!pointer_to_bool) { // no warning, but why not?? + } + + if (pointer_to_bool != nullptr) { // no warning for nullptr comparison + } + + // no warning on return, but why not?? + // clang-tidy bug: https://bugs.llvm.org/show_bug.cgi?id=38060 + return pointer_to_bool; +} diff --git a/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.json b/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.json new file mode 100644 index 0000000000..e4d64ee683 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "dubious check of 'bool *' against 'nullptr', did you mean to dereference it?", + "bugprone-bool-pointer-implicit-conversion" + ], + { "reliability": "low" } +] diff --git a/tools/clang-tidy/test/bugprone-forward-declaration-namespace.cpp b/tools/clang-tidy/test/bugprone-forward-declaration-namespace.cpp new file mode 100644 index 0000000000..f93d54b0a1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-forward-declaration-namespace.cpp @@ -0,0 +1,3 @@ +namespace na { struct A; } +namespace nb { struct A {}; } +nb::A a; diff --git a/tools/clang-tidy/test/bugprone-forward-declaration-namespace.json b/tools/clang-tidy/test/bugprone-forward-declaration-namespace.json new file mode 100644 index 0000000000..aee1ec88e5 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-forward-declaration-namespace.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "no definition found for 'A', but a definition with the same name 'A' found in another namespace 'nb'", + "bugprone-forward-declaration-namespace" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-incorrect-roundings.cpp b/tools/clang-tidy/test/bugprone-incorrect-roundings.cpp new file mode 100644 index 0000000000..ee37b56ae0 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-incorrect-roundings.cpp @@ -0,0 +1,7 @@ +void f1() +{ + double d; + int x; + + x = (d + 0.5); +} diff --git a/tools/clang-tidy/test/bugprone-incorrect-roundings.json b/tools/clang-tidy/test/bugprone-incorrect-roundings.json new file mode 100644 index 0000000000..f8da228b16 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-incorrect-roundings.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "casting (double + 0.5) to integer leads to incorrect rounding; consider using lround (#include ) instead", + "bugprone-incorrect-roundings" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-integer-division.cpp b/tools/clang-tidy/test/bugprone-integer-division.cpp new file mode 100644 index 0000000000..058edffe39 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-integer-division.cpp @@ -0,0 +1,5 @@ +float f() { + int a = 2; + int b = 10; + return a/b; +} diff --git a/tools/clang-tidy/test/bugprone-integer-division.json b/tools/clang-tidy/test/bugprone-integer-division.json new file mode 100644 index 0000000000..95c43fc8e0 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-integer-division.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "result of integer division used in a floating point context; possible loss of precision", + "bugprone-integer-division" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-macro-parentheses.cpp b/tools/clang-tidy/test/bugprone-macro-parentheses.cpp new file mode 100644 index 0000000000..53c22090a1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-macro-parentheses.cpp @@ -0,0 +1,5 @@ +#define BAD1 -1 +#define BAD2 1+2 +#define BAD3(A) (A+1) +#define BAD4(x) ((unsigned char)(x & 0xff)) +#define BAD5(X) A*B=(C*)X+2 diff --git a/tools/clang-tidy/test/bugprone-macro-parentheses.json b/tools/clang-tidy/test/bugprone-macro-parentheses.json new file mode 100644 index 0000000000..c50bf76cbd --- /dev/null +++ b/tools/clang-tidy/test/bugprone-macro-parentheses.json @@ -0,0 +1,28 @@ +[ + [ + "warning", + "macro replacement list should be enclosed in parentheses", + "bugprone-macro-parentheses" + ], + [ + "warning", + "macro replacement list should be enclosed in parentheses", + "bugprone-macro-parentheses" + ], + [ + "warning", + "macro argument should be enclosed in parentheses", + "bugprone-macro-parentheses" + ], + [ + "warning", + "macro argument should be enclosed in parentheses", + "bugprone-macro-parentheses" + ], + [ + "warning", + "macro argument should be enclosed in parentheses", + "bugprone-macro-parentheses" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.cpp b/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.cpp new file mode 100644 index 0000000000..2dedb3aca9 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.cpp @@ -0,0 +1,28 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-macro-repeated-side-effects.html + +#define MACRO_WITHOUT_REPEATED_ARG(x) (x) +#define MACRO_WITH_REPEATED_ARG(x) ((x) + (x)) + +static int g; + +int function_with_side_effects(int i) +{ + g += i; + return g; +} + +void test() +{ + int i; + i = MACRO_WITHOUT_REPEATED_ARG(1); // OK + i = MACRO_WITH_REPEATED_ARG(1); // OK + + i = MACRO_WITHOUT_REPEATED_ARG(i); // OK + i = MACRO_WITH_REPEATED_ARG(i); // OK + + i = MACRO_WITHOUT_REPEATED_ARG(function_with_side_effects(i)); // OK + i = MACRO_WITH_REPEATED_ARG(function_with_side_effects(i)); // NO WARNING + + i = MACRO_WITHOUT_REPEATED_ARG(i++); // OK + i = MACRO_WITH_REPEATED_ARG(i++); // WARNING +} diff --git a/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.json b/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.json new file mode 100644 index 0000000000..236120ae05 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "side effects in the 1st macro argument 'x' are repeated in macro expansion", + "bugprone-macro-repeated-side-effects" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-misplaced-widening-cast.cpp b/tools/clang-tidy/test/bugprone-misplaced-widening-cast.cpp new file mode 100644 index 0000000000..e75541bf6e --- /dev/null +++ b/tools/clang-tidy/test/bugprone-misplaced-widening-cast.cpp @@ -0,0 +1,3 @@ +long f(int x) { + return (long)(x * 1000); +} diff --git a/tools/clang-tidy/test/bugprone-misplaced-widening-cast.json b/tools/clang-tidy/test/bugprone-misplaced-widening-cast.json new file mode 100644 index 0000000000..bd0d9f2c00 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-misplaced-widening-cast.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "either cast from 'int' to 'long' is ineffective, or there is loss of precision before the conversion", + "bugprone-misplaced-widening-cast" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-move-forwarding-reference.cpp b/tools/clang-tidy/test/bugprone-move-forwarding-reference.cpp new file mode 100644 index 0000000000..45be15ee65 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-move-forwarding-reference.cpp @@ -0,0 +1,25 @@ + +namespace std { +template struct remove_reference; + +template struct remove_reference { typedef _Tp type; }; + +template struct remove_reference<_Tp &> { typedef _Tp type; }; + +template struct remove_reference<_Tp &&> { typedef _Tp type; }; + +template +constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t); + +} // namespace std + +// Standard case. +template void f1(U &&SomeU) { + T SomeT(std::move(SomeU)); + // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to + // CHECK-FIXES: T SomeT(std::forward(SomeU)); +} + +void foo() { + f1(2); +} diff --git a/tools/clang-tidy/test/bugprone-move-forwarding-reference.json b/tools/clang-tidy/test/bugprone-move-forwarding-reference.json new file mode 100644 index 0000000000..43166e4af1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-move-forwarding-reference.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead", + "bugprone-move-forwarding-reference" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-multiple-statement-macro.cpp b/tools/clang-tidy/test/bugprone-multiple-statement-macro.cpp new file mode 100644 index 0000000000..7ad2a2df64 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-multiple-statement-macro.cpp @@ -0,0 +1,10 @@ +void F(); + +#define BAD_MACRO(x) \ + F(); \ + F() + +void positives() { + if (1) + BAD_MACRO(1); +} diff --git a/tools/clang-tidy/test/bugprone-multiple-statement-macro.json b/tools/clang-tidy/test/bugprone-multiple-statement-macro.json new file mode 100644 index 0000000000..81c3dc89e5 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-multiple-statement-macro.json @@ -0,0 +1,7 @@ +[ + [ + "warning", + "multiple statement macro used without braces; some statements will be unconditionally executed", + "bugprone-multiple-statement-macro" + ] +] diff --git a/tools/clang-tidy/test/bugprone-sizeof-expression.cpp b/tools/clang-tidy/test/bugprone-sizeof-expression.cpp new file mode 100644 index 0000000000..f5f1f469ce --- /dev/null +++ b/tools/clang-tidy/test/bugprone-sizeof-expression.cpp @@ -0,0 +1,3 @@ +class C { + int size() { return sizeof(this); } +}; diff --git a/tools/clang-tidy/test/bugprone-sizeof-expression.json b/tools/clang-tidy/test/bugprone-sizeof-expression.json new file mode 100644 index 0000000000..438194296b --- /dev/null +++ b/tools/clang-tidy/test/bugprone-sizeof-expression.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "suspicious usage of 'sizeof(this)'; did you mean 'sizeof(*this)'", + "bugprone-sizeof-expression" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-string-constructor.cpp b/tools/clang-tidy/test/bugprone-string-constructor.cpp new file mode 100644 index 0000000000..8b6a4980a3 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-string-constructor.cpp @@ -0,0 +1,17 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-string-constructor.html + +#include "structures.h" + +void test() +{ + // A common mistake is to swap parameters to the ‘fill’ string-constructor. + std::string str('x', 50); // should be str(50, 'x') + + // Calling the string-literal constructor with a length bigger than the + // literal is suspicious and adds extra random characters to the string. + std::string("test", 200); // Will include random characters after "test". + + // Creating an empty string from constructors with parameters is considered + // suspicious. The programmer should use the empty constructor instead. + std::string("test", 0); // Creation of an empty string. +} diff --git a/tools/clang-tidy/test/bugprone-string-constructor.json b/tools/clang-tidy/test/bugprone-string-constructor.json new file mode 100644 index 0000000000..7e2ba1764f --- /dev/null +++ b/tools/clang-tidy/test/bugprone-string-constructor.json @@ -0,0 +1,18 @@ +[ + [ + "warning", + "string constructor parameters are probably swapped; expecting string(count, character)", + "bugprone-string-constructor" + ], + [ + "warning", + "length is bigger than string literal size", + "bugprone-string-constructor" + ], + [ + "warning", + "constructor creating an empty string", + "bugprone-string-constructor" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-string-integer-assignment.cpp b/tools/clang-tidy/test/bugprone-string-integer-assignment.cpp new file mode 100644 index 0000000000..30ef46b922 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-string-integer-assignment.cpp @@ -0,0 +1,28 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-string-integer-assignment.html + +#include "structures.h" + +void test_int() +{ + // Numeric types can be implicitly casted to character types. + std::string s; + int x = 5965; + s = 6; // warning + s = x; // warning +} + +void test_conversion() +{ + // Use the appropriate conversion functions or character literals. + std::string s; + int x = 5965; + s = '6'; // OK + s = std::to_string(x); // OK +} + +void test_cast() +{ + // In order to suppress false positives, use an explicit cast. + std::string s; + s = static_cast(6); // OK +} diff --git a/tools/clang-tidy/test/bugprone-string-integer-assignment.json b/tools/clang-tidy/test/bugprone-string-integer-assignment.json new file mode 100644 index 0000000000..37912fd950 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-string-integer-assignment.json @@ -0,0 +1,13 @@ +[ + [ + "warning", + "an integer is interpreted as a character code when assigning it to a string; if this is intended, cast the integer to the appropriate character type; if you want a string representation, use the appropriate conversion facility", + "bugprone-string-integer-assignment" + ], + [ + "warning", + "an integer is interpreted as a character code when assigning it to a string; if this is intended, cast the integer to the appropriate character type; if you want a string representation, use the appropriate conversion facility", + "bugprone-string-integer-assignment" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-suspicious-memset-usage.cpp b/tools/clang-tidy/test/bugprone-suspicious-memset-usage.cpp new file mode 100644 index 0000000000..71fe7239a1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-memset-usage.cpp @@ -0,0 +1,22 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-suspicious-memset-usage.html + +#include "structures.h" + +void test(int* ip, char* cp) +{ + // Case 1: Fill value is a character '0' instead of NUL '\0'. + memset(ip, '0', 1); // WARNING: suspicious for non-char pointers + memset(cp, '0', 1); // OK for char pointers + + // Case 2: Fill value is truncated. + memset(ip, 0xabcd, 1); // WARNING: fill value gets truncated + memset(ip, 0x00cd, 1); // OK because value 0xcd is not truncated. + memset(ip, 0x00, 1); // OK because value is not truncated. + + // Case 3: Byte count is zero. + memset(ip, sizeof(int), 0); // WARNING: zero length, potentially swapped + memset(ip, sizeof(int), 1); // OK with non-zero length + + // See clang bug https://bugs.llvm.org/show_bug.cgi?id=38098 + memset(ip, 8, 0); // OK with zero length without sizeof +} diff --git a/tools/clang-tidy/test/bugprone-suspicious-memset-usage.json b/tools/clang-tidy/test/bugprone-suspicious-memset-usage.json new file mode 100644 index 0000000000..73f26cf7c1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-memset-usage.json @@ -0,0 +1,18 @@ +[ + [ + "warning", + "memset fill value is char '0', potentially mistaken for int 0", + "bugprone-suspicious-memset-usage" + ], + [ + "warning", + "memset fill value is out of unsigned character range, gets truncated", + "bugprone-suspicious-memset-usage" + ], + [ + "warning", + "memset of size zero, potentially swapped arguments", + "bugprone-suspicious-memset-usage" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-suspicious-missing-comma.cpp b/tools/clang-tidy/test/bugprone-suspicious-missing-comma.cpp new file mode 100644 index 0000000000..de1634e11f --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-missing-comma.cpp @@ -0,0 +1,9 @@ +const char* Cartoons[] = { + "Bugs Bunny", + "Homer Simpson", + "Mickey Mouse", + "Bart Simpson", + "Charlie Brown" // There is a missing comma here. + "Fred Flintstone", + "Popeye", +}; diff --git a/tools/clang-tidy/test/bugprone-suspicious-missing-comma.json b/tools/clang-tidy/test/bugprone-suspicious-missing-comma.json new file mode 100644 index 0000000000..f4adb6b33a --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-missing-comma.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "suspicious string literal, probably missing a comma", + "bugprone-suspicious-missing-comma" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-suspicious-semicolon.cpp b/tools/clang-tidy/test/bugprone-suspicious-semicolon.cpp new file mode 100644 index 0000000000..7a90a87cd3 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-semicolon.cpp @@ -0,0 +1,8 @@ + +// bugprone-suspicious-semicolon +void nop(); +void fail1() +{ + int x = 0; + if(x > 5); nop(); +} diff --git a/tools/clang-tidy/test/bugprone-suspicious-semicolon.json b/tools/clang-tidy/test/bugprone-suspicious-semicolon.json new file mode 100644 index 0000000000..c94a1d5abb --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-semicolon.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "potentially unintended semicolon", + "bugprone-suspicious-semicolon" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-suspicious-string-compare.cpp b/tools/clang-tidy/test/bugprone-suspicious-string-compare.cpp new file mode 100644 index 0000000000..505a9d282c --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-string-compare.cpp @@ -0,0 +1,8 @@ +static const char A[] = "abc"; + +int strcmp(const char *, const char *); + +int test_warning_patterns() { + if (strcmp(A, "a")) + return 0; +} diff --git a/tools/clang-tidy/test/bugprone-suspicious-string-compare.json b/tools/clang-tidy/test/bugprone-suspicious-string-compare.json new file mode 100644 index 0000000000..eda430ef01 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-string-compare.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "function 'strcmp' is called without explicitly comparing result", + "bugprone-suspicious-string-compare" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-swapped-arguments.cpp b/tools/clang-tidy/test/bugprone-swapped-arguments.cpp new file mode 100644 index 0000000000..074df52050 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-swapped-arguments.cpp @@ -0,0 +1,26 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-swapped-arguments.html + +void test_d_i(double d, int i); +void test_d_i_i(double d, int i, int ii); +void test_i_d(int i, double d); +void test_i_i_d(int i, int ii, double d); + +void test() +{ + double d = 1; + int i = 1; + + test_d_i(d, i); // OK + test_d_i(i, d); // WARNING + + test_i_d(i, d); // OK + test_i_d(d, i); // WARNING + + test_i_i_d(i, i, d); // OK + test_i_i_d(i, d, i); // WARNING + test_i_i_d(d, i, i); // NO WARNING after second parameter + + test_d_i_i(d, i, i); // OK + test_d_i_i(i, d, i); // WARNING + test_d_i_i(i, i, d); // NO WARNING after second parameter +} diff --git a/tools/clang-tidy/test/bugprone-swapped-arguments.json b/tools/clang-tidy/test/bugprone-swapped-arguments.json new file mode 100644 index 0000000000..44c8093e52 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-swapped-arguments.json @@ -0,0 +1,23 @@ +[ + [ + "warning", + "argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.", + "bugprone-swapped-arguments" + ], + [ + "warning", + "argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.", + "bugprone-swapped-arguments" + ], + [ + "warning", + "argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.", + "bugprone-swapped-arguments" + ], + [ + "warning", + "argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.", + "bugprone-swapped-arguments" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-too-small-loop-variable.cpp b/tools/clang-tidy/test/bugprone-too-small-loop-variable.cpp new file mode 100644 index 0000000000..4dc8ed7a22 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-too-small-loop-variable.cpp @@ -0,0 +1,4 @@ +int main() { + long size = 294967296l; + for (short i = 0; i < size; ++i) {} +} diff --git a/tools/clang-tidy/test/bugprone-too-small-loop-variable.json b/tools/clang-tidy/test/bugprone-too-small-loop-variable.json new file mode 100644 index 0000000000..23f781936c --- /dev/null +++ b/tools/clang-tidy/test/bugprone-too-small-loop-variable.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "loop variable has narrower type 'short' than iteration's upper bound 'long'", + "bugprone-too-small-loop-variable" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-unused-raii.cpp b/tools/clang-tidy/test/bugprone-unused-raii.cpp new file mode 100644 index 0000000000..6a4a0a15ab --- /dev/null +++ b/tools/clang-tidy/test/bugprone-unused-raii.cpp @@ -0,0 +1,25 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-raii.html + +struct scoped_lock +{ + scoped_lock() {} + ~scoped_lock() {} +}; + +#define SCOPED_LOCK_MACRO(m) scoped_lock() + +struct trivial_scoped_lock +{ + trivial_scoped_lock() {} +}; + +scoped_lock test() +{ + scoped_lock(); // misc-unused-raii warning! + + SCOPED_LOCK_MACRO(); // no warning for macros + + trivial_scoped_lock(); // no warning for trivial objects without destructors + + return scoped_lock(); // no warning for return values +} diff --git a/tools/clang-tidy/test/bugprone-unused-raii.json b/tools/clang-tidy/test/bugprone-unused-raii.json new file mode 100644 index 0000000000..99a9936485 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-unused-raii.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "object destroyed immediately after creation; did you mean to name the object?", + "bugprone-unused-raii" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/bugprone-use-after-move.cpp b/tools/clang-tidy/test/bugprone-use-after-move.cpp new file mode 100644 index 0000000000..f90a8700d6 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-use-after-move.cpp @@ -0,0 +1,62 @@ +namespace std { +typedef unsigned size_t; + +template +struct unique_ptr { + unique_ptr(); + T *get() const; + explicit operator bool() const; + void reset(T *ptr); + T &operator*() const; + T *operator->() const; + T& operator[](size_t i) const; +}; + +template +struct remove_reference; + +template +struct remove_reference { + typedef _Tp type; +}; + +template +struct remove_reference<_Tp &> { + typedef _Tp type; +}; + +template +struct remove_reference<_Tp &&> { + typedef _Tp type; +}; + +template +constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept { + return static_cast::type &&>(__t); +} +} + +class A { +public: + A(); + A(const A &); + A(A &&); + + A &operator=(const A &); + A &operator=(A &&); + + void foo() const; + int getInt() const; + + operator bool() const; + + int i; +}; + +void func() { + std::unique_ptr ptr; + std::move(ptr); + ptr.get(); + static_cast(ptr); + *ptr; +} diff --git a/tools/clang-tidy/test/bugprone-use-after-move.json b/tools/clang-tidy/test/bugprone-use-after-move.json new file mode 100644 index 0000000000..50d7210781 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-use-after-move.json @@ -0,0 +1,4 @@ +[ + ["warning", "'ptr' used after it was moved", "bugprone-use-after-move"], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.cpp b/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.cpp new file mode 100644 index 0000000000..286189e25b --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.cpp @@ -0,0 +1,10 @@ +struct S { + int x; +}; + +void f(struct S s); + +void test() { + struct S s; + f(s); +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.json b/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.json new file mode 100644 index 0000000000..ecf097e287 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Passed-by-value struct argument contains uninitialized data (e.g., field: 'x')", + "clang-analyzer-core.CallAndMessage" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-core.DivideZero.cpp b/tools/clang-tidy/test/clang-analyzer-core.DivideZero.cpp new file mode 100644 index 0000000000..aac9f7c9f6 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.DivideZero.cpp @@ -0,0 +1,4 @@ +void test(int z) { + if (z == 0) + int x = 1 / z; +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.DivideZero.json b/tools/clang-tidy/test/clang-analyzer-core.DivideZero.json new file mode 100644 index 0000000000..78a64ad35b --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.DivideZero.json @@ -0,0 +1,4 @@ +[ + ["warning", "Division by zero", "clang-analyzer-core.DivideZero"], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.cpp b/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.cpp new file mode 100644 index 0000000000..bc071f5453 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.cpp @@ -0,0 +1,6 @@ +int f(int *p) __attribute__((nonnull)); + +void test(int *p) { + if (!p) + f(p); // warn +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.json b/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.json new file mode 100644 index 0000000000..deaae128ff --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Null pointer passed to 1st parameter expecting 'nonnull'", + "clang-analyzer-core.NonNullParamChecker" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-core.NullDereference.cpp b/tools/clang-tidy/test/clang-analyzer-core.NullDereference.cpp new file mode 100644 index 0000000000..6c9c555532 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.NullDereference.cpp @@ -0,0 +1,9 @@ +class C { +public: + int x; +}; + +void test() { + C *pc = 0; + int k = pc->x; +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.NullDereference.json b/tools/clang-tidy/test/clang-analyzer-core.NullDereference.json new file mode 100644 index 0000000000..4c9258b2b7 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.NullDereference.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Access to field 'x' results in a dereference of a null pointer (loaded from variable 'pc')", + "clang-analyzer-core.NullDereference" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.cpp b/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.cpp new file mode 100644 index 0000000000..1351c35f44 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.cpp @@ -0,0 +1,4 @@ +void test() { + int x; + int y = x + 1; +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.json b/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.json new file mode 100644 index 0000000000..9ec6c8a809 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "The left operand of '+' is a garbage value", + "clang-analyzer-core.UndefinedBinaryOperatorResult" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.cpp b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.cpp new file mode 100644 index 0000000000..e9685d48a4 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.cpp @@ -0,0 +1,4 @@ +void test() { + int x; + x |= 1; +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.json b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.json new file mode 100644 index 0000000000..3691af741c --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage", + "clang-analyzer-core.uninitialized.Assign" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.cpp b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.cpp new file mode 100644 index 0000000000..7a985eb080 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.cpp @@ -0,0 +1,6 @@ +void test() { + int x; + if (x) { + return; + } +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.json b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.json new file mode 100644 index 0000000000..00c6b3ad1e --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Branch condition evaluates to a garbage value", + "clang-analyzer-core.uninitialized.Branch" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.cpp b/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.cpp new file mode 100644 index 0000000000..65f2e36561 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.cpp @@ -0,0 +1,10 @@ +class P {}; + +void bar(P) {} + +void foo(int n) { + P x; + for (int i = n; i >= 0; --i) { + bar(static_cast(x)); + } +} diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.json b/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.json new file mode 100644 index 0000000000..e60f052e86 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Moved-from object 'x' is moved", + "clang-analyzer-cplusplus.Move" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.cpp b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.cpp new file mode 100644 index 0000000000..d886d74989 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.cpp @@ -0,0 +1,50 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +void use(int *p); + +void test_use_parameter_after_delete(int *p) +{ + delete p; + use(p); // warning: use after free +} + +class SomeClass { +public: + void f(); +}; + +void test_use_local_after_delete() +{ + SomeClass *c = new SomeClass; + delete c; + c->f(); // warning: use after free +} + +// XXX clang documentation says this should cause a warning but it doesn't! +void test_delete_alloca() +{ + int *p = (int *)__builtin_alloca(sizeof(int)); + delete p; // NO warning: deleting memory allocated by alloca +} + +void test_double_free() +{ + int *p = new int; + delete p; + delete p; // warning: attempt to free released +} + +void test_delete_local() +{ + int i; + delete &i; // warning: delete address of local +} + +// XXX clang documentation says this should cause a warning but it doesn't! +void test_delete_offset() +{ + int *p = new int[1]; + delete[] (++p); + // NO warning: argument to 'delete[]' is offset by 4 bytes + // from the start of memory allocated by 'new[]' +} diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.json b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.json new file mode 100644 index 0000000000..99a9cd0dd2 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.json @@ -0,0 +1,23 @@ +[ + [ + "warning", + "Use of memory after it is freed", + "clang-analyzer-cplusplus.NewDelete" + ], + [ + "warning", + "Use of memory after it is freed", + "clang-analyzer-cplusplus.NewDelete" + ], + [ + "warning", + "Attempt to free released memory", + "clang-analyzer-cplusplus.NewDelete" + ], + [ + "warning", + "Argument to 'delete' is the address of the local variable 'i', which is not memory allocated by 'new'", + "clang-analyzer-cplusplus.NewDelete" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.cpp b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.cpp new file mode 100644 index 0000000000..60772a30db --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.cpp @@ -0,0 +1,6 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +void test() +{ + int *p = new int; +} // warning diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.json b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.json new file mode 100644 index 0000000000..37490a67f8 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Potential leak of memory pointed to by 'p'", + "clang-analyzer-cplusplus.NewDeleteLeaks" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.cpp b/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.cpp new file mode 100644 index 0000000000..4e1c2c851d --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.cpp @@ -0,0 +1,6 @@ + +// clang-analyzer-deadcode.DeadStores +void test() { + int x; + x = 1; // warn +} diff --git a/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.json b/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.json new file mode 100644 index 0000000000..c46d5f2c2a --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Value stored to 'x' is never read", + "clang-analyzer-deadcode.DeadStores" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-optin.performance.Padding.cpp b/tools/clang-tidy/test/clang-analyzer-optin.performance.Padding.cpp new file mode 100644 index 0000000000..0b851a68d3 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-optin.performance.Padding.cpp @@ -0,0 +1,6 @@ +struct OverlyAlignedChar { + char c1; + int x; + char c2; + char c __attribute__((aligned(4096))); +}; diff --git a/tools/clang-tidy/test/clang-analyzer-optin.performance.Padding.json b/tools/clang-tidy/test/clang-analyzer-optin.performance.Padding.json new file mode 100644 index 0000000000..a7ce9df9a5 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-optin.performance.Padding.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Excessive padding in 'struct OverlyAlignedChar' (8185 padding bytes, where 4089 is optimal). Optimal fields order: c, c1, c2, x, consider reordering the fields or adding explicit padding members", + "clang-analyzer-optin.performance.Padding" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.cpp b/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.cpp new file mode 100644 index 0000000000..60dcdad746 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.cpp @@ -0,0 +1,3 @@ +void test() { + for (float x = 0.1f; x <= 1.0f; x += 0.1f) {} +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.json b/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.json new file mode 100644 index 0000000000..792f5b13dc --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Variable 'x' with floating point type 'float' should not be used as a loop counter", + "clang-analyzer-security.FloatLoopCounter" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.cpp new file mode 100644 index 0000000000..f1dede2d51 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test() { + setuid(1); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.json new file mode 100644 index 0000000000..a4f89bc0d9 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "The return value from the call to 'setuid' is not checked. If an error occurs in 'setuid', the following code may execute with unexpected privileges", + "clang-analyzer-security.insecureAPI.UncheckedReturn" + ], + { "reliability": "low" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.cpp new file mode 100644 index 0000000000..8821807518 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +int test_bcmp(void *a, void *b, size_t n) { + return bcmp(a, b, n); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.json new file mode 100644 index 0000000000..ea7d6267ee --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "The bcmp() function is obsoleted by memcmp()", + "clang-analyzer-security.insecureAPI.bcmp" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.cpp new file mode 100644 index 0000000000..67df7d1638 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test_bcopy(void *a, void *b, size_t n) { + bcopy(a, b, n); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.json new file mode 100644 index 0000000000..d752f6c7a8 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "The bcopy() function is obsoleted by memcpy() or memmove()", + "clang-analyzer-security.insecureAPI.bcopy" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.cpp new file mode 100644 index 0000000000..d3b5aa685f --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test_bzero(void *a, size_t n) { + bzero(a, n); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.json new file mode 100644 index 0000000000..cdc654a176 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "The bzero() function is obsoleted by memset()", + "clang-analyzer-security.insecureAPI.bzero" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.cpp new file mode 100644 index 0000000000..c3da0b1970 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.cpp @@ -0,0 +1,6 @@ +#include "structures.h" + +void test() { + char buff[1024]; + getpw(2, buff); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.json new file mode 100644 index 0000000000..2f80393d54 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "The getpw() function is dangerous as it may overflow the provided buffer. It is obsoleted by getpwuid()", + "clang-analyzer-security.insecureAPI.getpw" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.cpp new file mode 100644 index 0000000000..f096c29de3 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.cpp @@ -0,0 +1,6 @@ +#include + +void test() { + char buff[1024]; + gets(buff); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.json new file mode 100644 index 0000000000..1d2212ee27 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.json @@ -0,0 +1 @@ +"[[\"error\", \"use of undeclared identifier 'gets'\", \"clang-diagnostic-error\"]]" diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.cpp new file mode 100644 index 0000000000..904fc92ce6 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test() { + mkstemp("XX"); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.json new file mode 100644 index 0000000000..cca843ce93 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Call to 'mkstemp' should have at least 6 'X's in the format string to be secure (2 'X's seen)", + "clang-analyzer-security.insecureAPI.mkstemp" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.cpp new file mode 100644 index 0000000000..8bb511a7d7 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test() { + char *x = mktemp("/tmp/zxcv"); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.json new file mode 100644 index 0000000000..ce58bfdddf --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Call to function 'mktemp' is insecure as it always creates or uses insecure temporary file. Use 'mkstemp' instead", + "clang-analyzer-security.insecureAPI.mktemp" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.cpp new file mode 100644 index 0000000000..2274127c50 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.cpp @@ -0,0 +1,4 @@ +#include +void test() { + random(); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.json new file mode 100644 index 0000000000..7669f38d3e --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.json @@ -0,0 +1 @@ +"[[\"warning\", \"The 'random' function produces a sequence of values that an adversary may be able to predict. Use 'arc4random' instead\", \"clang-analyzer-security.insecureAPI.rand\"]]" diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.cpp new file mode 100644 index 0000000000..41713adb4e --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.cpp @@ -0,0 +1,7 @@ +#include +void test() { + char x[4]; + char *y = "abcd"; + + strcpy(x, y); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.json new file mode 100644 index 0000000000..874de88ded --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.json @@ -0,0 +1 @@ +"[[\"warning\", \"Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119\", \"clang-analyzer-security.insecureAPI.strcpy\"], [\"note\", \"Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119\", null]]" diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.cpp new file mode 100644 index 0000000000..619d986cf7 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test() { + vfork(); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.json new file mode 100644 index 0000000000..dd681fd537 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Call to function 'vfork' is insecure as it can lead to denial of service situations in the parent process. Replace calls to vfork with calls to the safer 'posix_spawn' function", + "clang-analyzer-security.insecureAPI.vfork" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-unix.Malloc.cpp b/tools/clang-tidy/test/clang-analyzer-unix.Malloc.cpp new file mode 100644 index 0000000000..a08422b336 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.Malloc.cpp @@ -0,0 +1,37 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +#include "structures.h" + +void test_malloc() +{ + int *p = (int*) malloc(1); + free(p); + free(p); // warning: attempt to free released memory +} + +void test_use_after_free() +{ + int *p = (int*) malloc(sizeof(int)); + free(p); + *p = 1; // warning: use after free +} + +void test_leak() +{ + int *p = (int*) malloc(1); + if (p) + return; // warning: memory is never released +} + +void test_free_local() +{ + int a[] = { 1 }; + free(a); // warning: argument is not allocated by malloc +} + +void test_free_offset() +{ + int *p = (int*) malloc(sizeof(char)); + p = p - 1; + free(p); // warning: argument to free() is offset by -4 bytes +} diff --git a/tools/clang-tidy/test/clang-analyzer-unix.Malloc.json b/tools/clang-tidy/test/clang-analyzer-unix.Malloc.json new file mode 100644 index 0000000000..701cbba680 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.Malloc.json @@ -0,0 +1,20 @@ +[ + ["warning", "Attempt to free released memory", "clang-analyzer-unix.Malloc"], + ["warning", "Use of memory after it is freed", "clang-analyzer-unix.Malloc"], + [ + "warning", + "Potential leak of memory pointed to by 'p'", + "clang-analyzer-unix.Malloc" + ], + [ + "warning", + "Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()", + "clang-analyzer-unix.Malloc" + ], + [ + "warning", + "Argument to free() is offset by -4 bytes from the start of memory allocated by malloc()", + "clang-analyzer-unix.Malloc" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.cpp b/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.cpp new file mode 100644 index 0000000000..124737c3f4 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.cpp @@ -0,0 +1,9 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +#include "structures.h" + +void test() +{ + char dest[3]; + strncat(dest, "***", sizeof(dest)); // warning : potential buffer overflow +} diff --git a/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.json b/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.json new file mode 100644 index 0000000000..dc6b9facf1 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Potential buffer overflow. Replace with 'sizeof(dest) - strlen(dest) - 1' or use a safer 'strlcat' API", + "clang-analyzer-unix.cstring.BadSizeArg" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.cpp b/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.cpp new file mode 100644 index 0000000000..30cdaf6ce9 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.cpp @@ -0,0 +1,14 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +#include "structures.h" + +int my_strlen(const char* s) +{ + return strlen(s); // warning +} + +int bad_caller() +{ + const char* s = nullptr; + return my_strlen(s); +} diff --git a/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.json b/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.json new file mode 100644 index 0000000000..a1270cafd8 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "Null pointer passed as 1st argument to string length function", + "clang-analyzer-unix.cstring.NullArg" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.cpp b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.cpp new file mode 100644 index 0000000000..b10b0fa1c3 --- /dev/null +++ b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.cpp @@ -0,0 +1,4 @@ +class Foo { + int f; + void a_f(double val) { f = val;} +}; diff --git a/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.json b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.json new file mode 100644 index 0000000000..9dca259044 --- /dev/null +++ b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "narrowing conversion from 'double' to 'int'", + "cppcoreguidelines-narrowing-conversions" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.cpp b/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.cpp new file mode 100644 index 0000000000..be331829f3 --- /dev/null +++ b/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.cpp @@ -0,0 +1,7 @@ +struct Foo final { + int x; +}; + +void foo() { + Foo y; +} diff --git a/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.json b/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.json new file mode 100644 index 0000000000..11e79f1579 --- /dev/null +++ b/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "uninitialized record type: 'y'", + "cppcoreguidelines-pro-type-member-init" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/misc-non-copyable-objects.cpp b/tools/clang-tidy/test/misc-non-copyable-objects.cpp new file mode 100644 index 0000000000..2f9060a818 --- /dev/null +++ b/tools/clang-tidy/test/misc-non-copyable-objects.cpp @@ -0,0 +1,5 @@ +namespace std { +typedef struct FILE {} FILE; +} + +void g(std::FILE f); diff --git a/tools/clang-tidy/test/misc-non-copyable-objects.json b/tools/clang-tidy/test/misc-non-copyable-objects.json new file mode 100644 index 0000000000..30826f3700 --- /dev/null +++ b/tools/clang-tidy/test/misc-non-copyable-objects.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "'f' declared as type 'FILE', which is unsafe to copy; did you mean 'FILE *'?", + "misc-non-copyable-objects" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/misc-redundant-expression.cpp b/tools/clang-tidy/test/misc-redundant-expression.cpp new file mode 100644 index 0000000000..0ccc9c55f7 --- /dev/null +++ b/tools/clang-tidy/test/misc-redundant-expression.cpp @@ -0,0 +1,3 @@ +int TestSimpleEquivalent(int X, int Y) { + if (X - X) return 1; +} diff --git a/tools/clang-tidy/test/misc-redundant-expression.json b/tools/clang-tidy/test/misc-redundant-expression.json new file mode 100644 index 0000000000..e4bffef44c --- /dev/null +++ b/tools/clang-tidy/test/misc-redundant-expression.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "both sides of operator are equivalent", + "misc-redundant-expression" + ], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/misc-unused-alias-decls.cpp b/tools/clang-tidy/test/misc-unused-alias-decls.cpp new file mode 100644 index 0000000000..1bbaa2db0a --- /dev/null +++ b/tools/clang-tidy/test/misc-unused-alias-decls.cpp @@ -0,0 +1,18 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/misc-unused-alias-decls.html + +namespace n1 { + namespace n2 { + namespace n3 { + int qux = 42; + } + } +} + +namespace n1_unused = ::n1; // WARNING +namespace n12_unused = n1::n2; // WARNING +namespace n123 = n1::n2::n3; // OK + +int test() +{ + return n123::qux; +} diff --git a/tools/clang-tidy/test/misc-unused-alias-decls.json b/tools/clang-tidy/test/misc-unused-alias-decls.json new file mode 100644 index 0000000000..1144566e4e --- /dev/null +++ b/tools/clang-tidy/test/misc-unused-alias-decls.json @@ -0,0 +1,13 @@ +[ + [ + "warning", + "namespace alias decl 'n1_unused' is unused", + "misc-unused-alias-decls" + ], + [ + "warning", + "namespace alias decl 'n12_unused' is unused", + "misc-unused-alias-decls" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/misc-unused-using-decls.cpp b/tools/clang-tidy/test/misc-unused-using-decls.cpp new file mode 100644 index 0000000000..6564711aba --- /dev/null +++ b/tools/clang-tidy/test/misc-unused-using-decls.cpp @@ -0,0 +1,4 @@ + +// misc-unused-using-decls +namespace n { class C; } +using n::C; diff --git a/tools/clang-tidy/test/misc-unused-using-decls.json b/tools/clang-tidy/test/misc-unused-using-decls.json new file mode 100644 index 0000000000..fc4156adca --- /dev/null +++ b/tools/clang-tidy/test/misc-unused-using-decls.json @@ -0,0 +1,4 @@ +[ + ["warning", "using decl 'C' is unused", "misc-unused-using-decls"], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/modernize-avoid-bind.cpp b/tools/clang-tidy/test/modernize-avoid-bind.cpp new file mode 100644 index 0000000000..c46fb31cd5 --- /dev/null +++ b/tools/clang-tidy/test/modernize-avoid-bind.cpp @@ -0,0 +1,6 @@ +#include "structures.h" + +int add(int x, int y) { return x + y; } +void f_bind() { + auto clj = std::bind(add, 2, 2); +} diff --git a/tools/clang-tidy/test/modernize-avoid-bind.json b/tools/clang-tidy/test/modernize-avoid-bind.json new file mode 100644 index 0000000000..915f62f042 --- /dev/null +++ b/tools/clang-tidy/test/modernize-avoid-bind.json @@ -0,0 +1,4 @@ +[ + ["warning", "prefer a lambda to std::bind", "modernize-avoid-bind"], + { "reliability": "medium" } +] diff --git a/tools/clang-tidy/test/modernize-concat-nested-namespaces.cpp b/tools/clang-tidy/test/modernize-concat-nested-namespaces.cpp new file mode 100644 index 0000000000..0ff35d0e07 --- /dev/null +++ b/tools/clang-tidy/test/modernize-concat-nested-namespaces.cpp @@ -0,0 +1,5 @@ +namespace mozilla { +namespace dom { +void foo(); +} +} diff --git a/tools/clang-tidy/test/modernize-concat-nested-namespaces.json b/tools/clang-tidy/test/modernize-concat-nested-namespaces.json new file mode 100644 index 0000000000..2c7bc6f52b --- /dev/null +++ b/tools/clang-tidy/test/modernize-concat-nested-namespaces.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "nested namespaces can be concatenated", + "modernize-concat-nested-namespaces" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.cpp b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.cpp new file mode 100644 index 0000000000..288fac8483 --- /dev/null +++ b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.cpp @@ -0,0 +1,18 @@ +namespace std { +class ios_base { +public: + typedef int io_state; + typedef int open_mode; + typedef int seek_dir; + + typedef int streampos; + typedef int streamoff; +}; + +template +class basic_ios : public ios_base { +}; +} // namespace std + +// Test function return values (declaration) +std::ios_base::io_state f_5(); diff --git a/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.json b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.json new file mode 100644 index 0000000000..7d6d0d055f --- /dev/null +++ b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "'std::ios_base::io_state' is deprecated; use 'std::ios_base::iostate' instead", + "modernize-deprecated-ios-base-aliases" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/modernize-loop-convert.cpp b/tools/clang-tidy/test/modernize-loop-convert.cpp new file mode 100644 index 0000000000..2205846c7e --- /dev/null +++ b/tools/clang-tidy/test/modernize-loop-convert.cpp @@ -0,0 +1,7 @@ +int arr[6] = {1, 2, 3, 4, 5, 6}; + +void bar(void) { + for (int i = 0; i < 6; ++i) { + (void)arr[i]; + } +} diff --git a/tools/clang-tidy/test/modernize-loop-convert.json b/tools/clang-tidy/test/modernize-loop-convert.json new file mode 100644 index 0000000000..105e44bc2b --- /dev/null +++ b/tools/clang-tidy/test/modernize-loop-convert.json @@ -0,0 +1,4 @@ +[ + ["warning", "use range-based for loop instead", "modernize-loop-convert"], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/modernize-raw-string-literal.cpp b/tools/clang-tidy/test/modernize-raw-string-literal.cpp new file mode 100644 index 0000000000..d120aad9bf --- /dev/null +++ b/tools/clang-tidy/test/modernize-raw-string-literal.cpp @@ -0,0 +1 @@ +char const *const ManyQuotes("quotes:\'\'\'\'"); diff --git a/tools/clang-tidy/test/modernize-raw-string-literal.json b/tools/clang-tidy/test/modernize-raw-string-literal.json new file mode 100644 index 0000000000..595deaa7db --- /dev/null +++ b/tools/clang-tidy/test/modernize-raw-string-literal.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "escaped string literal can be written as a raw string literal", + "modernize-raw-string-literal" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/modernize-redundant-void-arg.cpp b/tools/clang-tidy/test/modernize-redundant-void-arg.cpp new file mode 100644 index 0000000000..078e0e13ca --- /dev/null +++ b/tools/clang-tidy/test/modernize-redundant-void-arg.cpp @@ -0,0 +1,5 @@ +// modernize-redundant-void-arg + +int foo(void) { + return 0; +} diff --git a/tools/clang-tidy/test/modernize-redundant-void-arg.json b/tools/clang-tidy/test/modernize-redundant-void-arg.json new file mode 100644 index 0000000000..a34b4069b6 --- /dev/null +++ b/tools/clang-tidy/test/modernize-redundant-void-arg.json @@ -0,0 +1 @@ +"[[\"warning\", \"redundant void argument list in function definition\", \"modernize-redundant-void-arg\"]]" diff --git a/tools/clang-tidy/test/modernize-shrink-to-fit.cpp b/tools/clang-tidy/test/modernize-shrink-to-fit.cpp new file mode 100644 index 0000000000..c545a517a3 --- /dev/null +++ b/tools/clang-tidy/test/modernize-shrink-to-fit.cpp @@ -0,0 +1,10 @@ +#include "structures.h" + +void f() { + std::vector v; + + std::vector(v).swap(v); + + std::vector &vref = v; + std::vector(vref).swap(vref); +} diff --git a/tools/clang-tidy/test/modernize-shrink-to-fit.json b/tools/clang-tidy/test/modernize-shrink-to-fit.json new file mode 100644 index 0000000000..f8e4eda19f --- /dev/null +++ b/tools/clang-tidy/test/modernize-shrink-to-fit.json @@ -0,0 +1,13 @@ +[ + [ + "warning", + "the shrink_to_fit method should be used to reduce the capacity of a shrinkable container", + "modernize-shrink-to-fit" + ], + [ + "warning", + "the shrink_to_fit method should be used to reduce the capacity of a shrinkable container", + "modernize-shrink-to-fit" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/modernize-use-auto.cpp b/tools/clang-tidy/test/modernize-use-auto.cpp new file mode 100644 index 0000000000..ba54d0cb8a --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-auto.cpp @@ -0,0 +1,11 @@ +#include + +void func() { + int val = 42; + std::vector my_container; + for (std::vector::iterator I = my_container.begin(), + E = my_container.end(); + I != E; + ++I) { + } +} diff --git a/tools/clang-tidy/test/modernize-use-auto.json b/tools/clang-tidy/test/modernize-use-auto.json new file mode 100644 index 0000000000..5885e8b6d5 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-auto.json @@ -0,0 +1 @@ +"[[\"warning\", \"use auto when declaring iterators\", \"modernize-use-auto\"]]" diff --git a/tools/clang-tidy/test/modernize-use-bool-literals.cpp b/tools/clang-tidy/test/modernize-use-bool-literals.cpp new file mode 100644 index 0000000000..58b7ec8f29 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-bool-literals.cpp @@ -0,0 +1,5 @@ +void foo() { + bool p = 1; + bool f = static_cast(1); + bool x = p ? 1 : 0; +} diff --git a/tools/clang-tidy/test/modernize-use-bool-literals.json b/tools/clang-tidy/test/modernize-use-bool-literals.json new file mode 100644 index 0000000000..4d5effc1b9 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-bool-literals.json @@ -0,0 +1,23 @@ +[ + [ + "warning", + "converting integer literal to bool, use bool literal instead", + "modernize-use-bool-literals" + ], + [ + "warning", + "converting integer literal to bool, use bool literal instead", + "modernize-use-bool-literals" + ], + [ + "warning", + "converting integer literal to bool, use bool literal instead", + "modernize-use-bool-literals" + ], + [ + "warning", + "converting integer literal to bool, use bool literal instead", + "modernize-use-bool-literals" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/modernize-use-equals-default.cpp b/tools/clang-tidy/test/modernize-use-equals-default.cpp new file mode 100644 index 0000000000..ea5f71d93a --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-equals-default.cpp @@ -0,0 +1,6 @@ + +class IL { +public: + IL() {} + ~IL() {} +}; diff --git a/tools/clang-tidy/test/modernize-use-equals-default.json b/tools/clang-tidy/test/modernize-use-equals-default.json new file mode 100644 index 0000000000..5119e361b3 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-equals-default.json @@ -0,0 +1,13 @@ +[ + [ + "warning", + "use '= default' to define a trivial default constructor", + "modernize-use-equals-default" + ], + [ + "warning", + "use '= default' to define a trivial destructor", + "modernize-use-equals-default" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/modernize-use-equals-delete.cpp b/tools/clang-tidy/test/modernize-use-equals-delete.cpp new file mode 100644 index 0000000000..f08848c0a6 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-equals-delete.cpp @@ -0,0 +1,7 @@ +struct PositivePrivate { +private: + PositivePrivate(); + PositivePrivate(const PositivePrivate &); + PositivePrivate &operator=(PositivePrivate &&); + ~PositivePrivate(); +}; diff --git a/tools/clang-tidy/test/modernize-use-equals-delete.json b/tools/clang-tidy/test/modernize-use-equals-delete.json new file mode 100644 index 0000000000..bcb9354149 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-equals-delete.json @@ -0,0 +1,23 @@ +[ + [ + "warning", + "use '= delete' to prohibit calling of a special member function", + "modernize-use-equals-delete" + ], + [ + "warning", + "use '= delete' to prohibit calling of a special member function", + "modernize-use-equals-delete" + ], + [ + "warning", + "use '= delete' to prohibit calling of a special member function", + "modernize-use-equals-delete" + ], + [ + "warning", + "use '= delete' to prohibit calling of a special member function", + "modernize-use-equals-delete" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/modernize-use-nullptr.cpp b/tools/clang-tidy/test/modernize-use-nullptr.cpp new file mode 100644 index 0000000000..4b8b3ee3c0 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-nullptr.cpp @@ -0,0 +1,5 @@ +#define NULL 0 +void f(void) { + char *str = NULL; // ok + (void)str; +} diff --git a/tools/clang-tidy/test/modernize-use-nullptr.json b/tools/clang-tidy/test/modernize-use-nullptr.json new file mode 100644 index 0000000000..44bd18a10c --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-nullptr.json @@ -0,0 +1 @@ +[["warning", "use nullptr", "modernize-use-nullptr"], { "reliability": "high" }] diff --git a/tools/clang-tidy/test/modernize-use-override.cpp b/tools/clang-tidy/test/modernize-use-override.cpp new file mode 100644 index 0000000000..1cbec3868c --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-override.cpp @@ -0,0 +1,8 @@ +class Base { +public: + virtual void foo() = 0; +}; + +class Deriv : public Base { + void foo(); +}; diff --git a/tools/clang-tidy/test/modernize-use-override.json b/tools/clang-tidy/test/modernize-use-override.json new file mode 100644 index 0000000000..64f8b6e870 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-override.json @@ -0,0 +1 @@ +"[[\"warning\", \"annotate this function with 'override' or (rarely) 'final'\", \"modernize-use-override\"]]" diff --git a/tools/clang-tidy/test/modernize-use-using.cpp b/tools/clang-tidy/test/modernize-use-using.cpp new file mode 100644 index 0000000000..0e7b73222c --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-using.cpp @@ -0,0 +1,5 @@ +template +class Test { + typedef typename T::iterator Iter; +}; +typedef int Type; diff --git a/tools/clang-tidy/test/modernize-use-using.json b/tools/clang-tidy/test/modernize-use-using.json new file mode 100644 index 0000000000..50ee7060a9 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-using.json @@ -0,0 +1,5 @@ +[ + ["warning", "use 'using' instead of 'typedef'", "modernize-use-using"], + ["warning", "use 'using' instead of 'typedef'", "modernize-use-using"], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-faster-string-find.cpp b/tools/clang-tidy/test/performance-faster-string-find.cpp new file mode 100644 index 0000000000..d7ac3d0c3c --- /dev/null +++ b/tools/clang-tidy/test/performance-faster-string-find.cpp @@ -0,0 +1,6 @@ +#include "structures.h" + +void foo() { + std::string str; + str.find("A"); +} diff --git a/tools/clang-tidy/test/performance-faster-string-find.json b/tools/clang-tidy/test/performance-faster-string-find.json new file mode 100644 index 0000000000..1ab2d7ba08 --- /dev/null +++ b/tools/clang-tidy/test/performance-faster-string-find.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "'find' called with a string literal consisting of a single character; consider using the more effective overload accepting a character", + "performance-faster-string-find" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-for-range-copy.cpp b/tools/clang-tidy/test/performance-for-range-copy.cpp new file mode 100644 index 0000000000..264dd42896 --- /dev/null +++ b/tools/clang-tidy/test/performance-for-range-copy.cpp @@ -0,0 +1,30 @@ +template +struct Iterator { + void operator++() {} + const T& operator*() { + static T* TT = new T(); + return *TT; + } + bool operator!=(const Iterator &) { return false; } + typedef const T& const_reference; +}; +template +struct View { + T begin() { return T(); } + T begin() const { return T(); } + T end() { return T(); } + T end() const { return T(); } + typedef typename T::const_reference const_reference; +}; + +struct S { + S(); + S(const S &); + ~S(); + S &operator=(const S &); +}; + +void negativeConstReference() { + for (const S S1 : View>()) { + } +} diff --git a/tools/clang-tidy/test/performance-for-range-copy.json b/tools/clang-tidy/test/performance-for-range-copy.json new file mode 100644 index 0000000000..2082041aad --- /dev/null +++ b/tools/clang-tidy/test/performance-for-range-copy.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "the loop variable's type is not a reference type; this creates a copy in each iteration; consider making this a reference", + "performance-for-range-copy" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp new file mode 100644 index 0000000000..75ed510f3f --- /dev/null +++ b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp @@ -0,0 +1,43 @@ +// Iterator returning by value. +template +struct Iterator { + void operator++(); + T operator*(); + bool operator!=(const Iterator& other); +}; + +// The template argument is an iterator type, and a view is an object you can +// run a for loop on. +template +struct View { + T begin(); + T end(); +}; + +// With this class, the implicit conversion is a call to the (implicit) +// constructor of the class. +template +class ImplicitWrapper { + public: + // Implicit! + ImplicitWrapper(const T& t); +}; + +template +class OperatorWrapper { + public: + OperatorWrapper() = delete; +}; + +struct SimpleClass { + int foo; + operator OperatorWrapper(); +}; + +typedef View> SimpleView; + +void ImplicitSimpleClassIterator() { + for (const ImplicitWrapper& foo : SimpleView()) {} + for (const ImplicitWrapper foo : SimpleView()) {} + for (ImplicitWrapper foo : SimpleView()) {} +} diff --git a/tools/clang-tidy/test/performance-implicit-conversion-in-loop.json b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.json new file mode 100644 index 0000000000..d9bcb1e00a --- /dev/null +++ b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "the type of the loop variable 'foo' is different from the one returned by the iterator and generates an implicit conversion; you can either change the type to the matching one ('const SimpleClass &' but 'const auto&' is always a valid option) or remove the reference to make it explicit that you are creating a new value", + "performance-implicit-conversion-in-loop" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-inefficient-algorithm.cpp b/tools/clang-tidy/test/performance-inefficient-algorithm.cpp new file mode 100644 index 0000000000..b508260dbd --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-algorithm.cpp @@ -0,0 +1,30 @@ +namespace std { +template struct less { + bool operator()(const T &lhs, const T &rhs) { return lhs < rhs; } +}; + +template struct greater { + bool operator()(const T &lhs, const T &rhs) { return lhs > rhs; } +}; + +struct iterator_type {}; + +template > struct set { + typedef iterator_type iterator; + iterator find(const K &k); + unsigned count(const K &k); + + iterator begin(); + iterator end(); + iterator begin() const; + iterator end() const; +}; + +template +FwIt find(FwIt, FwIt end, const K &) { return end; } +} + +template void f(const T &t) { + std::set s; + find(s.begin(), s.end(), 46); +} diff --git a/tools/clang-tidy/test/performance-inefficient-algorithm.json b/tools/clang-tidy/test/performance-inefficient-algorithm.json new file mode 100644 index 0000000000..e3c575bd85 --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-algorithm.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "this STL algorithm call should be replaced with a container method", + "performance-inefficient-algorithm" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-inefficient-string-concatenation.cpp b/tools/clang-tidy/test/performance-inefficient-string-concatenation.cpp new file mode 100644 index 0000000000..5a5860f215 --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-string-concatenation.cpp @@ -0,0 +1,13 @@ +#include "structures.h" + +extern void fstring(std::string); + +void foo() { + std::string mystr1, mystr2; + auto myautostr1 = mystr1; + auto myautostr2 = mystr2; + + for (int i = 0; i < 10; ++i) { + fstring(mystr1 + mystr2 + mystr1); + } +} diff --git a/tools/clang-tidy/test/performance-inefficient-string-concatenation.json b/tools/clang-tidy/test/performance-inefficient-string-concatenation.json new file mode 100644 index 0000000000..8c7223db6d --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-string-concatenation.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead", + "performance-inefficient-string-concatenation" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-inefficient-vector-operation.cpp b/tools/clang-tidy/test/performance-inefficient-vector-operation.cpp new file mode 100644 index 0000000000..4f0e143aa2 --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-vector-operation.cpp @@ -0,0 +1,10 @@ +#include "structures.h" + +void foo() +{ + std::vector v; + int n = 100; + for (int i = 0; i < n; ++i) { + v.push_back(n); + } +} diff --git a/tools/clang-tidy/test/performance-inefficient-vector-operation.json b/tools/clang-tidy/test/performance-inefficient-vector-operation.json new file mode 100644 index 0000000000..d3e9e769d2 --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-vector-operation.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop", + "performance-inefficient-vector-operation" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-move-const-arg.cpp b/tools/clang-tidy/test/performance-move-const-arg.cpp new file mode 100644 index 0000000000..39f1ce06ec --- /dev/null +++ b/tools/clang-tidy/test/performance-move-const-arg.cpp @@ -0,0 +1,33 @@ +namespace std { +template +struct remove_reference { + typedef _Tp type; +}; + +template +constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { + return static_cast::type &&>(__t); +} +} // namespace std + +struct TriviallyCopyable { + int i; +}; + +class A { +public: + A() {} + A(const A &rhs) {} + A(A &&rhs) {} +}; + +void f(TriviallyCopyable) {} + +void g() { + TriviallyCopyable obj; + f(std::move(obj)); +} + +A f5(const A x5) { + return std::move(x5); +} diff --git a/tools/clang-tidy/test/performance-move-const-arg.json b/tools/clang-tidy/test/performance-move-const-arg.json new file mode 100644 index 0000000000..d56fe6bf37 --- /dev/null +++ b/tools/clang-tidy/test/performance-move-const-arg.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const", + "performance-move-const-arg" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-move-constructor-init.cpp b/tools/clang-tidy/test/performance-move-constructor-init.cpp new file mode 100644 index 0000000000..243b399e95 --- /dev/null +++ b/tools/clang-tidy/test/performance-move-constructor-init.cpp @@ -0,0 +1,11 @@ +struct B { + B() {} + B(const B&) {} + B(B &&) {} +}; + +struct D : B { + D() : B() {} + D(const D &RHS) : B(RHS) {} + D(D &&RHS) : B(RHS) {} +}; diff --git a/tools/clang-tidy/test/performance-move-constructor-init.json b/tools/clang-tidy/test/performance-move-constructor-init.json new file mode 100644 index 0000000000..17582a86e7 --- /dev/null +++ b/tools/clang-tidy/test/performance-move-constructor-init.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "move constructor initializes base class by calling a copy constructor", + "performance-move-constructor-init" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-noexcept-move-constructor.cpp b/tools/clang-tidy/test/performance-noexcept-move-constructor.cpp new file mode 100644 index 0000000000..8b4900b00d --- /dev/null +++ b/tools/clang-tidy/test/performance-noexcept-move-constructor.cpp @@ -0,0 +1,4 @@ +class A { + A(A &&); + A &operator=(A &&); +}; diff --git a/tools/clang-tidy/test/performance-noexcept-move-constructor.json b/tools/clang-tidy/test/performance-noexcept-move-constructor.json new file mode 100644 index 0000000000..94823b9ed5 --- /dev/null +++ b/tools/clang-tidy/test/performance-noexcept-move-constructor.json @@ -0,0 +1,13 @@ +[ + [ + "warning", + "move constructors should be marked noexcept", + "performance-noexcept-move-constructor" + ], + [ + "warning", + "move assignment operators should be marked noexcept", + "performance-noexcept-move-constructor" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-type-promotion-in-math-fn.cpp b/tools/clang-tidy/test/performance-type-promotion-in-math-fn.cpp new file mode 100644 index 0000000000..9a6fcf9848 --- /dev/null +++ b/tools/clang-tidy/test/performance-type-promotion-in-math-fn.cpp @@ -0,0 +1,7 @@ +double acos(double); + +void check_all_fns() +{ + float a; + acos(a); +} diff --git a/tools/clang-tidy/test/performance-type-promotion-in-math-fn.json b/tools/clang-tidy/test/performance-type-promotion-in-math-fn.json new file mode 100644 index 0000000000..577d2ddc91 --- /dev/null +++ b/tools/clang-tidy/test/performance-type-promotion-in-math-fn.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "call to 'acos' promotes float to double", + "performance-type-promotion-in-math-fn" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-unnecessary-copy-initialization.cpp b/tools/clang-tidy/test/performance-unnecessary-copy-initialization.cpp new file mode 100644 index 0000000000..ca0f591a3e --- /dev/null +++ b/tools/clang-tidy/test/performance-unnecessary-copy-initialization.cpp @@ -0,0 +1,7 @@ +#include "structures.h" + +extern const std::string& constReference(); + +void foo() { + const std::string UnnecessaryCopy = constReference(); +} diff --git a/tools/clang-tidy/test/performance-unnecessary-copy-initialization.json b/tools/clang-tidy/test/performance-unnecessary-copy-initialization.json new file mode 100644 index 0000000000..fcb16746ed --- /dev/null +++ b/tools/clang-tidy/test/performance-unnecessary-copy-initialization.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "the const qualified variable 'UnnecessaryCopy' is copy-constructed from a const reference but is never used; consider removing the statement", + "performance-unnecessary-copy-initialization" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/performance-unnecessary-value-param.cpp b/tools/clang-tidy/test/performance-unnecessary-value-param.cpp new file mode 100644 index 0000000000..ed5f36f7fa --- /dev/null +++ b/tools/clang-tidy/test/performance-unnecessary-value-param.cpp @@ -0,0 +1,4 @@ +#include "structures.h" + +void f(const std::string Value) { +} diff --git a/tools/clang-tidy/test/performance-unnecessary-value-param.json b/tools/clang-tidy/test/performance-unnecessary-value-param.json new file mode 100644 index 0000000000..35ed09e4be --- /dev/null +++ b/tools/clang-tidy/test/performance-unnecessary-value-param.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "the const qualified parameter 'Value' is copied for each invocation; consider making it a reference", + "performance-unnecessary-value-param" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-braces-around-statements.cpp b/tools/clang-tidy/test/readability-braces-around-statements.cpp new file mode 100644 index 0000000000..ce456ec2e3 --- /dev/null +++ b/tools/clang-tidy/test/readability-braces-around-statements.cpp @@ -0,0 +1,38 @@ + +void do_something(const char *) {} + +bool cond(const char *) { + return false; +} + +void test() { +if (cond("if0") /*comment*/) do_something("same-line"); + +if (cond("if1") /*comment*/) + do_something("next-line"); + + if (!1) return; + if (!2) { return; } + + if (!3) + return; + + if (!4) { + return; + } +} + +void foo() { +if (1) while (2) if (3) for (;;) do ; while(false) /**/;/**/ +} + +void f() {} + +void foo2() { + constexpr bool a = true; + if constexpr (a) { + f(); + } else { + f(); + } +} diff --git a/tools/clang-tidy/test/readability-braces-around-statements.json b/tools/clang-tidy/test/readability-braces-around-statements.json new file mode 100644 index 0000000000..7cc8ae280a --- /dev/null +++ b/tools/clang-tidy/test/readability-braces-around-statements.json @@ -0,0 +1,13 @@ +[ + [ + "warning", + "statement should be inside braces", + "readability-braces-around-statements" + ], + [ + "warning", + "statement should be inside braces", + "readability-braces-around-statements" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-const-return-type.cpp b/tools/clang-tidy/test/readability-const-return-type.cpp new file mode 100644 index 0000000000..695ed1d83f --- /dev/null +++ b/tools/clang-tidy/test/readability-const-return-type.cpp @@ -0,0 +1,5 @@ +const int p1() { +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness +// CHECK-FIXES: int p1() { + return 1; +} diff --git a/tools/clang-tidy/test/readability-const-return-type.json b/tools/clang-tidy/test/readability-const-return-type.json new file mode 100644 index 0000000000..f6c634c0b1 --- /dev/null +++ b/tools/clang-tidy/test/readability-const-return-type.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness", + "readability-const-return-type" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-container-size-empty.cpp b/tools/clang-tidy/test/readability-container-size-empty.cpp new file mode 100644 index 0000000000..1dcfe68bd7 --- /dev/null +++ b/tools/clang-tidy/test/readability-container-size-empty.cpp @@ -0,0 +1,7 @@ +#include "structures.h" + +void foo() { + std::string a; + if (a.size()) + return; +} diff --git a/tools/clang-tidy/test/readability-container-size-empty.json b/tools/clang-tidy/test/readability-container-size-empty.json new file mode 100644 index 0000000000..8c51b1c039 --- /dev/null +++ b/tools/clang-tidy/test/readability-container-size-empty.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "the 'empty' method should be used to check for emptiness instead of 'size'", + "readability-container-size-empty" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-delete-null-pointer.cpp b/tools/clang-tidy/test/readability-delete-null-pointer.cpp new file mode 100644 index 0000000000..e083404043 --- /dev/null +++ b/tools/clang-tidy/test/readability-delete-null-pointer.cpp @@ -0,0 +1,6 @@ +void func() { + int* f = 0; + if (f) { + delete f; + } +} diff --git a/tools/clang-tidy/test/readability-delete-null-pointer.json b/tools/clang-tidy/test/readability-delete-null-pointer.json new file mode 100644 index 0000000000..2a7184cdb1 --- /dev/null +++ b/tools/clang-tidy/test/readability-delete-null-pointer.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "'if' statement is unnecessary; deleting null pointer has no effect", + "readability-delete-null-pointer" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-else-after-return.cpp b/tools/clang-tidy/test/readability-else-after-return.cpp new file mode 100644 index 0000000000..2c72b68a92 --- /dev/null +++ b/tools/clang-tidy/test/readability-else-after-return.cpp @@ -0,0 +1,10 @@ +void f() { + +} + +void foo() { + if (true) + return; + else + f(); +} diff --git a/tools/clang-tidy/test/readability-else-after-return.json b/tools/clang-tidy/test/readability-else-after-return.json new file mode 100644 index 0000000000..7d2f8b0adf --- /dev/null +++ b/tools/clang-tidy/test/readability-else-after-return.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "do not use 'else' after 'return'", + "readability-else-after-return" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp b/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp new file mode 100644 index 0000000000..c30089a126 --- /dev/null +++ b/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp @@ -0,0 +1,55 @@ + +#define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) + +void takesChar(char); +void takesShort(short); +void takesInt(int); +void takesLong(long); + +void takesUChar(unsigned char); +void takesUShort(unsigned short); +void takesUInt(unsigned int); +void takesULong(unsigned long); + +struct InitializedWithInt { + MOZ_IMPLICIT InitializedWithInt(int); +}; + +void f() { + bool b = true; + char s0 = b; + short s1 = b; + int s2 = b; + long s3 = b; + + unsigned char u0 = b; + unsigned short u1 = b; + unsigned u2 = b; + unsigned long u3 = b; + + takesChar(b); + takesShort(b); + takesInt(b); + takesLong(b); + takesUChar(b); + takesUShort(b); + takesUInt(b); + takesULong(b); + + InitializedWithInt i = b; + (InitializedWithInt(b)); + + bool x = b; + + int exp = (int)true; + + if (x == b) {} + if (x != b) {} + + if (b == exp) {} + if (exp == b) {} + + char* ptr; + // Shouldn't trigger a checker warning since we are using AllowPointerConditions + if (ptr) {} +} diff --git a/tools/clang-tidy/test/readability-implicit-bool-conversion.json b/tools/clang-tidy/test/readability-implicit-bool-conversion.json new file mode 100644 index 0000000000..b10044f03f --- /dev/null +++ b/tools/clang-tidy/test/readability-implicit-bool-conversion.json @@ -0,0 +1,102 @@ +[ + [ + "warning", + "implicit conversion bool -> 'char'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'short'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'int'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'long'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'unsigned char'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'unsigned short'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'unsigned int'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'unsigned long'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'char'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'short'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'int'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'long'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'unsigned char'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'unsigned short'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'unsigned int'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'unsigned long'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'int'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'int'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'int'", + "readability-implicit-bool-conversion" + ], + [ + "warning", + "implicit conversion bool -> 'int'", + "readability-implicit-bool-conversion" + ] +] diff --git a/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.cpp b/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.cpp new file mode 100644 index 0000000000..acf13b240b --- /dev/null +++ b/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.cpp @@ -0,0 +1,6 @@ +struct S { + void f(int x); +}; + +void S::f(int y) { +} diff --git a/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.json b/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.json new file mode 100644 index 0000000000..f5e04a1041 --- /dev/null +++ b/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "function 'S::f' has a definition with different parameter names", + "readability-inconsistent-declaration-parameter-name" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-isolate-declaration.cpp b/tools/clang-tidy/test/readability-isolate-declaration.cpp new file mode 100644 index 0000000000..5d64e0171f --- /dev/null +++ b/tools/clang-tidy/test/readability-isolate-declaration.cpp @@ -0,0 +1,7 @@ +void f() { + int * pointer = nullptr, value = 42, * const const_ptr = &value; + // This declaration will be diagnosed and transformed into: + // int * pointer = nullptr; + // int value = 42; + // int * const const_ptr = &value; +} diff --git a/tools/clang-tidy/test/readability-isolate-declaration.json b/tools/clang-tidy/test/readability-isolate-declaration.json new file mode 100644 index 0000000000..3f8ccf52fa --- /dev/null +++ b/tools/clang-tidy/test/readability-isolate-declaration.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "multiple declarations in a single statement reduces readability", + "readability-isolate-declaration" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-magic-numbers.cpp b/tools/clang-tidy/test/readability-magic-numbers.cpp new file mode 100644 index 0000000000..430fa17056 --- /dev/null +++ b/tools/clang-tidy/test/readability-magic-numbers.cpp @@ -0,0 +1,4 @@ +void func() { + int radius = 2; + double circleArea = 3.1415926535 * radius * radius; +} diff --git a/tools/clang-tidy/test/readability-magic-numbers.json b/tools/clang-tidy/test/readability-magic-numbers.json new file mode 100644 index 0000000000..ee5d0f204c --- /dev/null +++ b/tools/clang-tidy/test/readability-magic-numbers.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "3.1415926535 is a magic number; consider replacing it with a named constant", + "readability-magic-numbers" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-misleading-indentation.cpp b/tools/clang-tidy/test/readability-misleading-indentation.cpp new file mode 100644 index 0000000000..8b23010170 --- /dev/null +++ b/tools/clang-tidy/test/readability-misleading-indentation.cpp @@ -0,0 +1,20 @@ +void f() +{ +} + +void foo() { + if (1) + if (0) + f(); + else + f(); +} + +void foo2() { + constexpr bool a = true; + if constexpr (a) { + f(); + } else { + f(); + } +} diff --git a/tools/clang-tidy/test/readability-misleading-indentation.json b/tools/clang-tidy/test/readability-misleading-indentation.json new file mode 100644 index 0000000000..9ef6d30c45 --- /dev/null +++ b/tools/clang-tidy/test/readability-misleading-indentation.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "different indentation for 'if' and corresponding 'else'", + "readability-misleading-indentation" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-non-const-parameter.cpp b/tools/clang-tidy/test/readability-non-const-parameter.cpp new file mode 100644 index 0000000000..5a0ffd0e30 --- /dev/null +++ b/tools/clang-tidy/test/readability-non-const-parameter.cpp @@ -0,0 +1,5 @@ +void warn1(int *first, int *last) { + *first = 0; + if (first < last) { + } +} diff --git a/tools/clang-tidy/test/readability-non-const-parameter.json b/tools/clang-tidy/test/readability-non-const-parameter.json new file mode 100644 index 0000000000..fb83ec8572 --- /dev/null +++ b/tools/clang-tidy/test/readability-non-const-parameter.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "pointer parameter 'last' can be pointer to const", + "readability-non-const-parameter" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-qualified-auto.cpp b/tools/clang-tidy/test/readability-qualified-auto.cpp new file mode 100644 index 0000000000..03c5164e2c --- /dev/null +++ b/tools/clang-tidy/test/readability-qualified-auto.cpp @@ -0,0 +1,6 @@ +typedef int *MyPtr; +MyPtr getPtr(); + +void foo() { + auto TdNakedPtr = getPtr(); +} diff --git a/tools/clang-tidy/test/readability-qualified-auto.json b/tools/clang-tidy/test/readability-qualified-auto.json new file mode 100644 index 0000000000..eaf0a176cf --- /dev/null +++ b/tools/clang-tidy/test/readability-qualified-auto.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "'auto TdNakedPtr' can be declared as 'auto *TdNakedPtr'", + "readability-qualified-auto" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-redundant-control-flow.cpp b/tools/clang-tidy/test/readability-redundant-control-flow.cpp new file mode 100644 index 0000000000..d221715542 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-control-flow.cpp @@ -0,0 +1,5 @@ +extern void g(); +void f() { + g(); + return; +} diff --git a/tools/clang-tidy/test/readability-redundant-control-flow.json b/tools/clang-tidy/test/readability-redundant-control-flow.json new file mode 100644 index 0000000000..efedaf1009 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-control-flow.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "redundant return statement at the end of a function with a void return type", + "readability-redundant-control-flow" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-redundant-preprocessor.cpp b/tools/clang-tidy/test/readability-redundant-preprocessor.cpp new file mode 100644 index 0000000000..317905dab8 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-preprocessor.cpp @@ -0,0 +1,5 @@ +#ifndef FOO +#ifdef FOO // inner ifdef is considered redundant +void f(); +#endif +#endif diff --git a/tools/clang-tidy/test/readability-redundant-preprocessor.json b/tools/clang-tidy/test/readability-redundant-preprocessor.json new file mode 100644 index 0000000000..e3b7fb4ce1 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-preprocessor.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "nested redundant #ifdef; consider removing it", + "readability-redundant-preprocessor" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-redundant-smartptr-get.cpp b/tools/clang-tidy/test/readability-redundant-smartptr-get.cpp new file mode 100644 index 0000000000..66eb8d6c37 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-smartptr-get.cpp @@ -0,0 +1,19 @@ +#define NULL __null + +namespace std { + +template +struct unique_ptr { + T& operator*() const; + T* operator->() const; + T* get() const; + explicit operator bool() const noexcept; +}; +} + +struct A { +}; + +void foo() { + A& b2 = *std::unique_ptr().get(); +} diff --git a/tools/clang-tidy/test/readability-redundant-smartptr-get.json b/tools/clang-tidy/test/readability-redundant-smartptr-get.json new file mode 100644 index 0000000000..c5f06cbc21 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-smartptr-get.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "redundant get() call on smart pointer", + "readability-redundant-smartptr-get" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-redundant-string-cstr.cpp b/tools/clang-tidy/test/readability-redundant-string-cstr.cpp new file mode 100644 index 0000000000..d35a2998e5 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-string-cstr.cpp @@ -0,0 +1,7 @@ +#include "structures.h" + +void foo() { + std::string a = "Mozilla"; + std::string tmp; + tmp.assign(a.c_str()); +} diff --git a/tools/clang-tidy/test/readability-redundant-string-cstr.json b/tools/clang-tidy/test/readability-redundant-string-cstr.json new file mode 100644 index 0000000000..cce79a38a2 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-string-cstr.json @@ -0,0 +1,4 @@ +[ + ["warning", "redundant call to 'c_str'", "readability-redundant-string-cstr"], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-redundant-string-init.cpp b/tools/clang-tidy/test/readability-redundant-string-init.cpp new file mode 100644 index 0000000000..39bae4bd56 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-string-init.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +int foo() { + std::string a = ""; +} diff --git a/tools/clang-tidy/test/readability-redundant-string-init.json b/tools/clang-tidy/test/readability-redundant-string-init.json new file mode 100644 index 0000000000..3092808205 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-string-init.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "redundant string initialization", + "readability-redundant-string-init" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-simplify-boolean-expr.cpp b/tools/clang-tidy/test/readability-simplify-boolean-expr.cpp new file mode 100644 index 0000000000..277a469880 --- /dev/null +++ b/tools/clang-tidy/test/readability-simplify-boolean-expr.cpp @@ -0,0 +1,2 @@ +bool a1 = false; +bool aa = false == a1; diff --git a/tools/clang-tidy/test/readability-simplify-boolean-expr.json b/tools/clang-tidy/test/readability-simplify-boolean-expr.json new file mode 100644 index 0000000000..45eb9e1a66 --- /dev/null +++ b/tools/clang-tidy/test/readability-simplify-boolean-expr.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "redundant boolean literal supplied to boolean operator", + "readability-simplify-boolean-expr" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-static-accessed-through-instance.cpp b/tools/clang-tidy/test/readability-static-accessed-through-instance.cpp new file mode 100644 index 0000000000..95f13b994c --- /dev/null +++ b/tools/clang-tidy/test/readability-static-accessed-through-instance.cpp @@ -0,0 +1,11 @@ +struct C { + static int x; +}; + +int C::x = 0; + +// Expressions with side effects +C &f(int, int, int, int); +void g() { + f(1, 2, 3, 4).x; +} diff --git a/tools/clang-tidy/test/readability-static-accessed-through-instance.json b/tools/clang-tidy/test/readability-static-accessed-through-instance.json new file mode 100644 index 0000000000..67c84c188b --- /dev/null +++ b/tools/clang-tidy/test/readability-static-accessed-through-instance.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "static member accessed through instance", + "readability-static-accessed-through-instance" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/readability-uniqueptr-delete-release.cpp b/tools/clang-tidy/test/readability-uniqueptr-delete-release.cpp new file mode 100644 index 0000000000..4fce9cde4e --- /dev/null +++ b/tools/clang-tidy/test/readability-uniqueptr-delete-release.cpp @@ -0,0 +1,6 @@ +#include "structures.h" + +int foo() { + std::unique_ptr P; + delete P.release(); +} diff --git a/tools/clang-tidy/test/readability-uniqueptr-delete-release.json b/tools/clang-tidy/test/readability-uniqueptr-delete-release.json new file mode 100644 index 0000000000..79330346e1 --- /dev/null +++ b/tools/clang-tidy/test/readability-uniqueptr-delete-release.json @@ -0,0 +1,8 @@ +[ + [ + "warning", + "prefer '= nullptr' to reset 'unique_ptr<>' objects", + "readability-uniqueptr-delete-release" + ], + { "reliability": "high" } +] diff --git a/tools/clang-tidy/test/structures.h b/tools/clang-tidy/test/structures.h new file mode 100644 index 0000000000..0966109635 --- /dev/null +++ b/tools/clang-tidy/test/structures.h @@ -0,0 +1,108 @@ +// Proxy file in order to define generic data types, to avoid binding with system headers + +typedef __SIZE_TYPE__ size_t; + +namespace std { + +typedef size_t size_t; + +template +class vector { + public: + typedef T* iterator; + typedef const T* const_iterator; + typedef T& reference; + typedef const T& const_reference; + typedef size_t size_type; + + explicit vector(); + explicit vector(size_type n); + + void swap(vector &other); + void push_back(const T& val); + + template void emplace_back(Args &&... args); + + void reserve(size_t n); + void resize(size_t n); + + size_t size(); + const_reference operator[] (size_type) const; + reference operator[] (size_type); + + const_iterator begin() const; + const_iterator end() const; +}; + +template +class basic_string { +public: + typedef basic_string _Type; + basic_string() {} + basic_string(const T *p); + basic_string(const T *p, size_t count); + basic_string(size_t count, char ch); + ~basic_string() {} + size_t size() const; + bool empty() const; + size_t find (const char* s, size_t pos = 0) const; + const T *c_str() const; + _Type& assign(const T *s); + basic_string &operator=(T ch); + basic_string *operator+=(const basic_string &) {} + friend basic_string operator+(const basic_string &, const basic_string &) {} +}; +typedef basic_string string; +typedef basic_string wstring; + +string to_string(int value); + +template +struct default_delete {}; + +template > +class unique_ptr { + public: + unique_ptr(); + ~unique_ptr(); + explicit unique_ptr(T*); + template + unique_ptr(unique_ptr&&); + T* release(); +}; + +template +class bind_rt {}; + +template +bind_rt bind(Fp &&, Arguments &&...); +} + +typedef unsigned int uid_t; +typedef unsigned int pid_t; + +int bcmp(void *, void *, size_t); +void bcopy(void *, void *, size_t); +void bzero(void *, size_t); + +int getpw(uid_t uid, char *buf); +int setuid(uid_t uid); + +int mkstemp(char *tmpl); +char *mktemp(char *tmpl); + +pid_t vfork(void); + +int abort() { return 0; } + +#define assert(x) \ + if (!(x)) \ + (void)abort() + +size_t strlen(const char *s); +char *strncat(char *s1, const char *s2, size_t); + +void free(void *ptr); +void *malloc(size_t size); + +void *memset(void *b, int c, size_t len); -- cgit v1.2.3