aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorkadir çetinkaya <kadircet@google.com>2024-11-12 10:53:43 +0100
committerGitHub <noreply@github.com>2024-11-12 10:53:43 +0100
commit41e3919ded78d8870f7c95e9181c7f7e29aa3cc4 (patch)
tree19330af040636ba3c624ee5be77dc21243f93dd7 /clang/lib/Frontend/CompilerInvocation.cpp
parente385e0d3e71e17da0b2023f480259c95923707bd (diff)
downloadllvm-41e3919ded78d8870f7c95e9181c7f7e29aa3cc4.zip
llvm-41e3919ded78d8870f7c95e9181c7f7e29aa3cc4.tar.gz
llvm-41e3919ded78d8870f7c95e9181c7f7e29aa3cc4.tar.bz2
[clang] Introduce diagnostics suppression mappings (#112517)
This implements https://discourse.llvm.org/t/rfc-add-support-for-controlling-diagnostics-severities-at-file-level-granularity-through-command-line/81292. Users now can suppress warnings for certain headers by providing a mapping with globs, a sample file looks like: ``` [unused] src:* src:*clang/*=emit ``` This will suppress warnings from `-Wunused` group in all files that aren't under `clang/` directory. This mapping file can be passed to clang via `--warning-suppression-mappings=foo.txt`. At a high level, mapping file is stored in DiagnosticOptions and then processed with rest of the warning flags when creating a DiagnosticsEngine. This is a functor that uses SpecialCaseLists underneath to match against globs coming from the mappings file. This implies processing warning options now performs IO, relevant interfaces are updated to take in a VFS, falling back to RealFileSystem when one is not available.
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index b5fd35a..e3145dc 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2521,6 +2521,11 @@ void CompilerInvocationBase::GenerateDiagnosticArgs(
Consumer(StringRef("-R") + Remark);
}
+
+ if (!Opts.DiagnosticSuppressionMappingsFile.empty()) {
+ GenerateArg(Consumer, OPT_warning_suppression_mappings_EQ,
+ Opts.DiagnosticSuppressionMappingsFile);
+ }
}
std::unique_ptr<DiagnosticOptions>
@@ -2597,6 +2602,9 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
Opts.TabStop = DiagnosticOptions::DefaultTabStop;
}
+ if (const Arg *A = Args.getLastArg(OPT_warning_suppression_mappings_EQ))
+ Opts.DiagnosticSuppressionMappingsFile = A->getValue();
+
addDiagnosticArgs(Args, OPT_W_Group, OPT_W_value_Group, Opts.Warnings);
addDiagnosticArgs(Args, OPT_R_Group, OPT_R_value_Group, Opts.Remarks);