llvm-capstone/clang/test/Tooling/clang-check-analyze-save-temps.cpp
Sam McCall bba729af3e [clang-check] Adjust argument adjusters for clang-check to strip options blocking the static analyzer
Output generation options (like `-save-temps`) will make the analyzer not executed even `--analyze` option is provided in the driver arguments.
Besides, the original approach of adding `--analyze` option will not work when (more than one) `-fsyntax-only` options are provided in the driver arguments.

This patch fixes these two problems by using the syntax-only adjuster to remove output generation options and manually filter out redundant `-fsyntax-only` options.

In the new implementation, the adjusters added by `ClangTool` will not be removed but used as dependencies for clang-check adjusters for analyzer options.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D116329
2022-01-14 10:05:47 +01:00

20 lines
577 B
C++

// Check whether output generation options (like -save-temps) will not affect
// the execution of the analyzer.
// RUN: clang-check -analyze %s -- -save-temps -c -Xclang -verify
// Check whether redundant -fsyntax-only options will affect the execution of
// the analyzer.
// RUN: clang-check -analyze %s -- \
// RUN: -fsyntax-only -c -fsyntax-only -Xclang -verify 2>&1 | \
// RUN: FileCheck %s --allow-empty
// CHECK-NOT: argument unused during compilation: '--analyze'
void a(int *x) {
if (x) {
}
*x = 47; // expected-warning {{Dereference of null pointer}}
}