Commit graph

38 commits

Author SHA1 Message Date
Chih-Hung Hsieh
9f876e9eab Set NoWarningsAsErrorsInTidyFlags
* Reject -warnings-as-errors in the tidy_flags.
* Fix one grammar error in comment.

Bug: 229801437
Test: WITH_TIDY=1 make; make tidy-soong_subset
Change-Id: I4fae229add65131b64cd5a1d06507d27198010ed
2022-06-13 23:58:12 +00:00
Chih-Hung Hsieh
794b81d9d1 Prepare to obsolete -warnings-as-errors in tidy_flags
* A follow up CL will set const NoWarningsAsErrorsInTidyFlags
  and make it an error to use -warnings-as-errors in tidy_flags.
* Append TidyGlobalNoChecks after local tidy_checks to disable some checks.
* Append TidyGlobalNoErrorChecks after local tidy_checks_as_errors
  (-warnings-as-errors) to allow some warnings globally.
* Move bugprone-signed-char-misuse and bugprone-branch-clone to
  globalNoErrorCheckList so we can find and fix some of those warnings.

Bug: 229801437
Test: WITH_TIDY=1 make; make tidy-soong_subset
Change-Id: I0128b859b7be6eb9bbda1916b89a6a471b052150
2022-06-12 20:25:43 -07:00
Chih-hung Hsieh
6f9312127c Merge "Disable tidy checks in TidyGlobalNoChecks" 2022-06-10 18:01:08 +00:00
Yasin Kilicdere
5a8ce13c2a Revert "Disallow -warnings-as-errors in tidy_flags"
This reverts commit 2d481842b1.

Reason for revert: b/235569235#comment4

Change-Id: I5c87b1d5a1bdf0bad7f436c397688fe3fc20d04e
2022-06-10 12:18:07 +00:00
Chih-Hung Hsieh
43b920e707 Disable tidy checks in TidyGlobalNoChecks
* Save repeated strings in TidyFlags of build.ninja rules.
* Some of these checks were disabled to upgrade clang-tidy.
  They could later be moved to TidyDefaultGlobalChecks and
  TidyExternalVendorChecks if not breaking the build.
  Some projects can then enable those checks locally.

Test: WITH_TIDY=1 make; make tidy-soong_subset
Change-Id: I70e4218c929e3c88f766f2c68c56c51356110e72
2022-06-09 17:58:41 -07:00
Chih-Hung Hsieh
2d481842b1 Disallow -warnings-as-errors in tidy_flags
* Also remove the undocumented complicated
  experiment to overwrite local warnings-as-errors.

Bug: 229801437
Test: WITH_TIDY=1 make; make tidy-soong_subset
Change-Id: I2fb32146b4685ab9f5198724c15c303f799b7a14
2022-06-09 11:12:10 -07:00
Chih-Hung Hsieh
80e3e03aa9 Shorten the -checks flag in clang-tidy rules
* If a module defines tidy_checks with "-*",
  pass only "-*" and checks after it to clang-tidy.

Test: make tidy-soong_subset
Change-Id: I2a4a6111f67b934bc29e4e4fe8596a8dce4e7031
2022-06-03 17:17:17 -07:00
Chih-Hung Hsieh
5fe637aadb no out/soong/... in default header-filter
* There are too many warnings from out/.../*.pb.h
  and other generated header files.

Bug: 180862582
Bug: 231245501
Test: WITH_TIDY=1 make
Change-Id: Ibabc1040666b50c6dec4fd66ae999a3441324fbd
2022-05-10 01:27:42 -07:00
Chih-Hung Hsieh
104f51f70b add ALLOW_LOCAL_TIDY_TRUE and some tests
* A new ALLOW_LOCAL_TIDY_TRUE variable, default is false.
* If it is 0/false, local "tidy:true" is ignored.
* If it is 1/true, local "tidy:true" is honored as it is now.

Bug: 229779921
Test: make with and without ALLOW_LOCAL_TIDY_TRUE=1
Change-Id: I0323289a4d3bb2514982252a5a1339e94f2bbaab
2022-04-26 13:30:32 -07:00
Chih-Hung Hsieh
63d59eb77c Use only single dash for tidy flags
* Work around RBE preprocessor bug, which rejects double dash flags.

Bug: 217778010
Test: make tidy-soong_subset
Change-Id: Ic7c0a95ae7afefb49cc9d124fd3c9f38fe2e0f56
2022-02-04 20:34:27 -08:00
Pirama Arumuga Nainar
5fc137b63b [cc/tidy] Disable cert-err33-c
Bug: http://b/216364337

This check warns when return values of standard-library functions
(including fprintf, snprintf) are not checked. Some of these warnings
turn to error when tidy_checks_as_errors in Android.bp.

Disable this for now and follow-up after compiler update to disable or
fix individual instances.

Test: Build with new compiler
Change-Id: I5af89b3f9cea4961c69708c51d22c510d478405b
2022-01-25 15:45:06 -08:00
Chih-Hung Hsieh
7540a78a35 Generate tidy-* rules unless tidy is disabled
* make tidy-soong_subset, or make tidy-<any_directory>,
  should trigger the same clang-tidy compilations
  with or without global WITH_TIDY=1.
* Normal make should not trigger clang-tidy compilations
  unless global WITH_TIDY=1 or a module has set tidy:true.

Bug: 213918926
Test: NINJA_ARGS="-n" make tidy-soong_subset
Test: NINJA_ARGS="-n" make <some-library>
Change-Id: Iafffd3894abe137c9584c2c01830898422f9a677
2022-01-12 16:48:40 -08:00
Chih-Hung Hsieh
80783774b9 Add (obj|tidy)-*_os, and (obj|tidy)-*_subset targets
* The obj-* targets only call clang or clang++ to compile
  C/C++ files, like the tidy-* targets only call clang-tidy.
* Add (obj|tidy)-dir_os and module_os-(obj|tidy) phony targets
  to include only targets of the specified OS.
* Add (obj|tidy)-dir_os_subset and module_os_subset-(obj|tidy) phony targets
  to include only a subset of that OS target group.
  * Most clang-tidy runs produce the same warnings for all variants
    of an OS. The *_subset targets reduce runs over multiple variants.
  * The obj-*subset targets are useful for a quick test to compile
    at least one variant of every C/C++ file for each OS.
* The (obj|tidy)-soong phony target is changed to include only
  (obj|tidy)-top_level_directory targets instead of ALL
  module-(obj|tidy) targets in all subdirectories.
* For aosp_arm64-eng make tidy-* targets; count NINJA commands:
    tidy-soong                     381K
    tidy-soong_subset              106K
    tidy-soong_android             294K
    tidy-soong_android_subset       73K
    tidy-soong_linux_glibc          84K
    tidy-soong_windows              12K
    tidy-bionic                     12K
    tidy-bionic_subset               2.4K
    tidy-bionic_android             11.5K
    tidy-bionic_android_subset       2.1K
    tidy-bionic_linux_glibc          1K
    tidy-device_android              7K
    tidy-device_android_subset       5K
    tidy-hardware_android            3K
    tidy-hardware_android_subset     9K
    libfec_rs-tidy                   33
    libfec_rs_subset-tidy             9
    libfec_rs_android-tidy           18
    libfec_rs_android_subset-tidy     3
* For aosp_arm64-eng make obj-* targets; count NINJA commands:
    obj-soong                      399K
    obj-soong_subset               112K
    obj-soong_android              305K
    obj-soong_android_subset        75K
    obj-soong_linux_glibc           90K
    obj-soong_linux_glibc_subset    38K
    obj-soong_windows               12K
    obj-bionic                      15K
    obj-bionic_subset                3K
    obj-bionic_android              14K
    obj-bionic_android_subset        2.3K
    obj-bionic_linux_glibc           1.3K
    obj-system-core                  6K
    obj-system-core_subset           3K
    obj-frameworks-base             16K
    obj-frameworks-base_subset       6K
    libfec_rs-obj                    33
    libfec_rs_subset-obj              9
    libfec_rs_android-obj            18
    libfec_rs_android_subset-obj      3

Test: NINJA_ARGS="-n" WITH_TIDY=1 make some_obj_tidy_target;
      compare output commands from various phony targets
Bug: 199169329
Bug: 202769240
Change-Id: I186c45dc07c5884888c1063dfc09cf212ffb0ebf
2021-12-07 12:58:11 -08:00
Yi Kong
e82732916a Switch to clang r433403
Bug: 197230471
Test: presubmit
Change-Id: I374a66deb785bae99953ea23c67f873f33c2081b
2021-09-10 04:20:49 +00:00
Yabin Cui
10bf3b8c00 Revert^2 "Switch to clang r428724 13.0.1."
786c1d41ef

Change-Id: Ic143d1b3375c8258e0e4274339524380de391676
2021-08-10 15:42:10 +00:00
Yabin Cui
786c1d41ef Revert "Switch to clang r428724 13.0.1."
Revert submission 1743633-switch-to-clang-r428724

Reason for revert: fix build
Reverted Changes:
I824f3bc1c:Update bazel's clang version to clang-r428724
I6c4c26267:Adjust test for compiler update.
I94ab1f2dc:Switch to clang r428724 13.0.1.

Change-Id: I846e904b6e868d4e2be1bd8260ed59fc5464ef68
2021-08-08 20:59:59 +00:00
Yabin Cui
e87329c4c5 Switch to clang r428724 13.0.1.
Bug: http://b/190099451
Test: build and boot devices

Change-Id: I94ab1f2dc194ffcec5681708b558af26ced30aae
2021-08-06 18:28:08 +00:00
Liz Kammer
3b606c8218 Delete unused functions
As they're unused, also removing them from the interface.

Test: go test soong tests
Change-Id: I76e7cbca12876395d8d7eaae4481c5e0d1350d76
2021-06-28 12:29:30 -04:00
Chih-Hung Hsieh
217e09a784 Forbit extra quotes in tidy flag lists
* Start with clang-tidy flags;
  maybe other flags should be checked too.

Bug: 180862582
Test: make
Change-Id: I82f86a911733693a14fe56a35e28590b065e3ae7
2021-02-25 20:46:15 -08:00
Chih-Hung Hsieh
9f94c362ea Change default DEFAULT_TIDY_HEADER_DIRS to empty
* Default -header-filter will now contain only module directory.
  * In a clean build of aosp_x86_64-eng, this change can reduce
    the number of (duplicated) clang-tidy warnings by 77% or more.
* When compiled with WITH_TIDY=1, if DEFAULT_TIDY_HEADER_DIRS is
  not set, warnings from a header file will be shown only if
  the file is in a module's (sub)directory.
* Set DEFAULT_TIDY_HEADER_DIRS="bionic/|bootable/|build/|cts/|\
  dalvik/|developers/|development/|frameworks/|\
  libcore/|libnativehelper/|system/"
  will get before this change's -header-filter.
* Fix a bug: Default header-filter was not added when
  tidy_flags was defined in a module.
  With this fix, some incorrectly hidden header file tidy warnings
  will now show up.

Bug: 179530304
Test: make with WITH_TIDY=1 and various setting of DEFAULT_TIDY_HEADER_DIRS
Change-Id: Ia0c05349908a730862dae36be9a2dbe4f44fb6da
2021-02-12 13:50:38 -08:00
Chih-Hung Hsieh
1b4934a215 WITH_TIDY=1 implies -warnings-as-errors=-*
* This allows local projects to enable clang-tidy
  and catch errors in a default build, but allows
  all warnings in a global build with WITH_TIDY=1.

Test: make with WITH_TIDY=1
Change-Id: I92a10af24b23ee9f04eebb0513e8f611dd7dcf59
2021-01-15 14:17:39 -08:00
Dan Albert
d12afec49c Allow globally disabling some clang-tidy checks.
Test: used for the upcoming compiler update
Bug: None
Change-Id: Id17db2c48fa3e165da81a1d084827bde142406dd
2020-08-18 13:28:03 -07:00
Yabin Cui
8ec05ff5f6 Switch to clang-r383902 (11.0.1).
Also suppress some warnings/flags globally to pass compilation.

Bug: 149839606
Test: build aosp_arm64-userdebug.
Change-Id: I0ed740e51b6b39c58842a58eabcf3cdf404e73fa
2020-04-27 01:17:12 -07:00
Yabin Cui
70ba0e23a4 Disable cert-dcl51-cpp and -cert-dcl37-c.
Disable them for the next clang compiler update.

Bug: 153464409
Test: WITH_TIDY=1 make

Change-Id: I27c315637e02c7c6c708a24a04220f10136b681a
2020-04-09 16:28:51 -07:00
Chih-Hung Hsieh
3d3df826c1 Disable bugprone-reserved-identifier
* Disable it for the next clang compiler update
  until all source files with this warning are fixed.

Bug: 153464409
Test: WITH_TIDY=1 make
Change-Id: I126d2f5170f3883192348577e523ef99f5c5a70e
2020-04-08 10:42:16 -07:00
Nikita Ioffe
32c4986268 Add support for clang-tidy -warnings-as-errors in Android.bp files
Test: manually change Android.bp and checked clang-tidy invocation cmd
Change-Id: I51a64b3f7da82428b896f46f739c93d76a050aaf
2019-03-26 20:47:08 +00:00
Colin Cross
0b9f31fb08 Replace *Escape with *EscapeList
Follow the change to blueprint to make *Escape take and return a string
and add *EscapeList that take and return slices of strings.  Fix up
a few places that were unnecessarily converting a string to a slice
and back to a string.

Test: m nothing
Change-Id: I3fa87de175522205f36544ef76aa2f04aef1b936
2019-03-04 18:11:53 +00:00
Chih-Hung Hsieh
327b6f0c69 Disable cert-dcl16-c clang-tidy check for mingw32.
Bug: 120614316
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,cert-*
Change-Id: Ibe46409543eaa4a7f3b710d9742b3252dc9ac7e8
2018-12-10 16:28:56 -08:00
Dan Willemsen
8536d6b3b7 Remove GCC checks
Clang is always used now, so we can remove all the GCC checks. Removing
GCC-specific configuration will happen in the next CL.

Test: m
Change-Id: I4835ecf6062159315d0dfb07b098e60bff033a8a
2018-10-09 02:16:58 +00:00
Chih-Hung Hsieh
9e5d8a60e2 Use WITH_TIDY_FLAGS env variable.
This variable is a space separated string of clang-tidy flags to be passed
to clang-tidy before any other system required extra flags.
Note that when this flag or local tidy_flags is defined,
the default -header-filter flag is suppressed.

Test: make with WITH_TIDY=1 WITH_TIDY_FLAGS="-extra-arg=-DABCD1=1 -extra-arg=-DABCD2=2"
Bug: 32668284
Change-Id: If7bd31c65404ef7fe6c3499d51f0f209a704efd9
2018-09-21 15:19:24 -07:00
George Burgess IV
030ccee01c Disable dtor inlining for clang-tidy
LLVM r328258 turned on a feature called temporary dtor inlining by
default for all of C++ in clang-tidy. This feature appears to be
somewhat over-aggressive when objects are being passed by value. For
example, given:

void foo(std::unique_ptr<int> i);

void bar() {
  auto x = std::make_unique<int>();
  int *i = x.get();
  foo(std::move(x));
  *i = 99;
}

...clang-tidy will complain about `*i = 99;` being a definite
use-after-free. This is incorrect, however: `foo` could stash the
`unique_ptr` it's given in a global, or a class member, or ...

Until upstream fixes this bug, it's probably best to keep this disabled.

Bug: None
Test: Ran the analyzer across Android locally. Nothing broke; number of
complaints dropped significantly.

Change-Id: I806c7ead34b61f4a88a7e6ec1c94751836a21e70
2018-05-14 16:30:46 -07:00
Chih-Hung Hsieh
669cb9150e Call clang-tidy with -fno-caret-diagnostics by default.
* clang -fno-caret-diagnostics
  suppresses warning source lines, carets, and
  the stats line of "n warnings generated"
* clang-tidy -extra-arg-before=-fno-caret-diagnotics
  only suppresses the "n warnings generated" line.
* Pass this flag and -quiet to clang-tidy when
  WITH_TIDY is not 1 or true.

Bug: 69051430
Test: normal build and build with WITH_TIDY=1

Change-Id: I34e34cddc0e7329e73b5f04da4b1458dabfcd4c8
2018-01-04 01:41:16 -08:00
Chih-Hung Hsieh
dc0c0302e9 Call clang-tidy with -quiet unless WITH_TIDY is set.
* Default builds calls clang-tidy only if enabled locally.
  In this case, clang-tidy should be quiet.
* If WITH_TIDY is 1 or true, let clang-tidy emit default messages.
* Even with -quiet and all warnings are suppressed,
  clang-tidy emits one line message of the number of suppressed messages.
  This one-liner could be suppressed in future changes.

Bug: 69051430
Test: default build and build with WITH_TIDY=1
Change-Id: I45303149930b33544e271e6d5eeddf18c9e48d7a
2017-12-15 20:57:48 -08:00
Colin Cross
6510f91a1c Replace ModuleContext.AConfig() with Config()
AConfig() now duplicates Config().  Replace the uses of AConfig()
with Config().  Leave AConfig() for now until code in other
projects is cleaned up.

Test: m checkbuild
Change-Id: Ic88be643049d21dba45dbd1a65588ed94bf43bdc
2017-11-30 00:44:18 +00:00
George Burgess IV
561a3fe4af soong: add __clang_analyzer__ to clang-tidy
We have code that acts slightly differently when the static analyzer is
running, so that it can produce more accurate diagnostics (e.g. less
false positives). It uses __clang_analyzer__ to detect the static
analyzer.

When the static analyzer is run via clang-tidy, __clang_analyzer__
doesn't get defined.

Bug: None
Test: WITH_TIDY=1 m. clang-tidy now acts as expected in code made for
the static analyzer

Change-Id: I460ff410640524633c0a60b71d34927d17e1ed98
2017-05-04 01:19:02 +00:00
Colin Cross
37047f1c7e Pass DepsContext to dependency methods
Pass a DepsContext that embeds android.BottomUpMutatorContext
instead of android.BaseContext so that dependency methods can
directly add dependencies.

Test: m -j
Change-Id: Id4c157975d3d6f03efd99785d217bef486a76139
2016-12-13 17:32:29 -08:00
Colin Cross
379d2cb511 Always check tidy properties
To avoid build breakages when WITH_TIDY=1 is set, check for bad tidy
properties before checking if tidy is enabled.

Test: mmma -j external/llvm with a tidy error
Test: m -j
Change-Id: Ia338c417091ff6b03909bbac8b26febed5b6d6ea
2016-12-05 17:12:10 -08:00
Dan Willemsen
a03cf6d322 Add clang-tidy support
For every file which we can run clang-tidy (C/C++ clang-built), we add a
new build node that depends on the object file (since clang-tidy does
not export a depfile), and is depended on by the link step. This is
better than how we're doing it in make, since calling tidy can be turned
on or off without needing to rebuild the object files.

This does not attempt to port WITH_TIDY_ONLY from Make, since the way
that it works is broken (due to the lack of a depfile).

Bug: 32244182
Test: WITH_TIDY=true mmma -j bionic/libc
Test: ./soong (Setting ClangTidy: true)
Change-Id: I40bbb5bb00d292d72bf1c293b93080b5f9f6d8ea
2016-10-31 16:21:01 -07:00