nik created this revision. Herald added a subscriber: cfe-commits. Depending on the included files and the used warning flags, e.g. - Weverything, a huge number of warnings can be reported for included files. As processing that many diagnostics comes with a performance impact and not all clients are interested in those diagnostics, add a flag to skip them.
Repository: rC Clang https://reviews.llvm.org/D48116 Files: include/clang-c/Index.h include/clang/Basic/Diagnostic.h lib/Basic/DiagnosticIDs.cpp test/Index/ignore-warnings-from-headers.cpp test/Index/ignore-warnings-from-headers.h tools/c-index-test/c-index-test.c tools/libclang/CIndex.cpp
Index: tools/libclang/CIndex.cpp =================================================================== --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3397,6 +3397,9 @@ if (options & CXTranslationUnit_KeepGoing) Diags->setSuppressAfterFatalError(false); + if (options & CXTranslationUnit_IgnoreWarningsFromIncludedFiles) + Diags->setSuppressWarningsFromIncludedFiles(true); + // Recover resources if we crash before exiting this function. llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine, llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> > Index: tools/c-index-test/c-index-test.c =================================================================== --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -84,6 +84,8 @@ options |= CXTranslationUnit_KeepGoing; if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE")) options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble; + if (getenv("CINDEXTEST_IGNORE_WARNINGS_FROM_INCLUDED_FILES")) + options |= CXTranslationUnit_IgnoreWarningsFromIncludedFiles; return options; } Index: test/Index/ignore-warnings-from-headers.h =================================================================== --- /dev/null +++ test/Index/ignore-warnings-from-headers.h @@ -0,0 +1 @@ +void f(int unusedInHeader) {} Index: test/Index/ignore-warnings-from-headers.cpp =================================================================== --- /dev/null +++ test/Index/ignore-warnings-from-headers.cpp @@ -0,0 +1,7 @@ +#include "ignore-warnings-from-headers.h" + +void g(int unusedInMainFile) {} + +// RUN: env CINDEXTEST_IGNORE_WARNINGS_FROM_INCLUDED_FILES=1 c-index-test -test-load-source function %s -Wunused-parameter 2>&1 | FileCheck %s +// CHECK-NOT: warning: unused parameter 'unusedInHeader' +// CHECK: warning: unused parameter 'unusedInMainFile' Index: lib/Basic/DiagnosticIDs.cpp =================================================================== --- lib/Basic/DiagnosticIDs.cpp +++ lib/Basic/DiagnosticIDs.cpp @@ -477,6 +477,13 @@ Result = diag::Severity::Fatal; } + // If requested, ignore warnings from all headers. + if (Diag.SuppressWarningsFromIncludedFiles && Result <= diag::Severity::Warning && + Loc.isValid() && + !Diag.getSourceManager().isInMainFile( + Diag.getSourceManager().getExpansionLoc(Loc))) + return diag::Severity::Ignored; + // Custom diagnostics always are emitted in system headers. bool ShowInSystemHeader = !GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader; Index: include/clang/Basic/Diagnostic.h =================================================================== --- include/clang/Basic/Diagnostic.h +++ include/clang/Basic/Diagnostic.h @@ -213,6 +213,9 @@ // Suppress all diagnostics. bool SuppressAllDiagnostics = false; + // Suppress warnings from all included files. + bool SuppressWarningsFromIncludedFiles = false; + // Elide common types of templates. bool ElideType = true; @@ -634,6 +637,10 @@ } bool getSuppressAllDiagnostics() const { return SuppressAllDiagnostics; } + void setSuppressWarningsFromIncludedFiles(bool Val = true) { + SuppressWarningsFromIncludedFiles = Val; + } + /// Set type eliding, to skip outputting same types occurring in /// template types. void setElideType(bool Val = true) { ElideType = Val; } Index: include/clang-c/Index.h =================================================================== --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -1332,7 +1332,17 @@ * * The function bodies of the main file are not skipped. */ - CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800 + CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800, + + /** + * Used to indicate that warnings from included files should be ignored. + * + * If set, clang_getDiagnosticSetFromTU() will not report warnings from + * included files anymore. This speeds up clang_getDiagnosticSetFromTU() for + * the case where these warnings are not of interest, as for an IDE for + * example, which typically shows only the diagnostics in the main file. + */ + CXTranslationUnit_IgnoreWarningsFromIncludedFiles = 0x1000 }; /**
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits