Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

run-clang-tools: Add pass through checks and and header-filter arguments

Add a -checks argument to allow the checks passed to the clang-tool to
be set on the command line.

Add a pass through -header-filter option.

Don't run analysis on non-C or CPP files.

Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: llvm@lists.linux.dev
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Tom Rix <trix@redhat.com>
Cc: bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
Link: https://lore.kernel.org/r/20231009183920.200859-4-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
b24520ff 9e56d3be

+25 -7
+25 -7
scripts/clang-tools/run-clang-tools.py
··· 33 33 path_help = "Path to the compilation database to parse" 34 34 parser.add_argument("path", type=str, help=path_help) 35 35 36 + checks_help = "Checks to pass to the analysis" 37 + parser.add_argument("-checks", type=str, default=None, help=checks_help) 38 + header_filter_help = "Pass the -header-filter value to the tool" 39 + parser.add_argument("-header-filter", type=str, default=None, help=header_filter_help) 40 + 36 41 return parser.parse_args() 37 42 38 43 ··· 50 45 51 46 def run_analysis(entry): 52 47 # Disable all checks, then re-enable the ones we want 53 - checks = [] 54 - checks.append("-checks=-*") 55 - if args.type == "clang-tidy": 56 - checks.append("linuxkernel-*") 48 + global args 49 + checks = None 50 + if args.checks: 51 + checks = args.checks.split(',') 57 52 else: 58 - checks.append("clang-analyzer-*") 59 - checks.append("-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling") 60 - p = subprocess.run(["clang-tidy", "-p", args.path, ",".join(checks), entry["file"]], 53 + checks = ["-*"] 54 + if args.type == "clang-tidy": 55 + checks.append("linuxkernel-*") 56 + else: 57 + checks.append("clang-analyzer-*") 58 + checks.append("-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling") 59 + file = entry["file"] 60 + if not file.endswith(".c") and not file.endswith(".cpp"): 61 + with lock: 62 + print(f"Skipping non-C file: '{file}'", file=sys.stderr) 63 + return 64 + pargs = ["clang-tidy", "-p", args.path, "-checks=" + ",".join(checks)] 65 + if args.header_filter: 66 + pargs.append("-header-filter=" + args.header_filter) 67 + pargs.append(file) 68 + p = subprocess.run(pargs, 61 69 stdout=subprocess.PIPE, 62 70 stderr=subprocess.STDOUT, 63 71 cwd=entry["directory"])