aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/ASTUnit.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/ASTUnit.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/ASTUnit.cpp')
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index f58e27a..8df5465 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1367,7 +1367,7 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
// after parsing the preamble.
getDiagnostics().Reset();
ProcessWarningOptions(getDiagnostics(),
- PreambleInvocationIn.getDiagnosticOpts());
+ PreambleInvocationIn.getDiagnosticOpts(), *VFS);
getDiagnostics().setNumWarnings(NumWarningsInPreamble);
PreambleRebuildCountdown = 1;
@@ -1593,7 +1593,8 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
// We'll manage file buffers ourselves.
CI->getPreprocessorOpts().RetainRemappedFileBuffers = true;
CI->getFrontendOpts().DisableFree = false;
- ProcessWarningOptions(AST->getDiagnostics(), CI->getDiagnosticOpts());
+ ProcessWarningOptions(AST->getDiagnostics(), CI->getDiagnosticOpts(),
+ AST->getFileManager().getVirtualFileSystem());
// Create the compiler instance to use for building the AST.
std::unique_ptr<CompilerInstance> Clang(
@@ -1701,7 +1702,8 @@ bool ASTUnit::LoadFromCompilerInvocation(
Invocation->getPreprocessorOpts().RetainRemappedFileBuffers = true;
Invocation->getFrontendOpts().DisableFree = false;
getDiagnostics().Reset();
- ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
+ ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts(),
+ *VFS);
std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
if (PrecompilePreambleAfterNParses > 0) {
@@ -1709,7 +1711,8 @@ bool ASTUnit::LoadFromCompilerInvocation(
OverrideMainBuffer =
getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, VFS);
getDiagnostics().Reset();
- ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
+ ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts(),
+ *VFS);
}
SimpleTimer ParsingTimer(WantTiming);
@@ -1902,7 +1905,8 @@ bool ASTUnit::Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
// Clear out the diagnostics state.
FileMgr.reset();
getDiagnostics().Reset();
- ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
+ ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts(),
+ *VFS);
if (OverrideMainBuffer)
getDiagnostics().setNumWarnings(NumWarningsInPreamble);
@@ -2241,7 +2245,8 @@ void ASTUnit::CodeComplete(
CaptureDroppedDiagnostics Capture(CaptureDiagsKind::All,
Clang->getDiagnostics(),
&StoredDiagnostics, nullptr);
- ProcessWarningOptions(Diag, Inv.getDiagnosticOpts());
+ ProcessWarningOptions(Diag, Inv.getDiagnosticOpts(),
+ FileMgr.getVirtualFileSystem());
// Create the target instance.
if (!Clang->createTarget()) {