Bigcheese created this revision. Bigcheese added a reviewer: jansvoboda11. Bigcheese added a project: clang. Herald added a subscriber: ributzka. Herald added a project: All. Bigcheese requested review of this revision. Herald added a subscriber: cfe-commits.
Since system modules don't emit most warnings, remove the warning flags to increase module reuse. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D150689 Files: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp clang/test/ClangScanDeps/optimize-system-warnings.m
Index: clang/test/ClangScanDeps/optimize-system-warnings.m =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/optimize-system-warnings.m @@ -0,0 +1,84 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t +// RUN: sed -e "s|DIR|%/t|g" %t/build/compile-commands.json.in > %t/build/compile-commands.json +// RUN: clang-scan-deps -compilation-database %t/build/compile-commands.json \ +// RUN: -j 1 -format experimental-full -optimize-args > %t/deps.db +// RUN: cat %t/deps.db | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t + +// CHECK: { +// CHECK-NEXT: "modules": [ +// CHECK-NEXT: { +// CHECK-NEXT: "clang-module-deps": [], +// CHECK-NEXT: "clang-modulemap-file": +// CHECK-NEXT: "command-line": [ +// CHECK-NOT: "-W +// CHECK: ], +// CHECK-NEXT: "context-hash": "{{.*}}", +// CHECK-NEXT: "file-deps": [ +// CHECK: ], +// CHECK-NEXT: "name": "A" +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "clang-module-deps": [], +// CHECK-NEXT: "clang-modulemap-file": +// CHECK-NEXT: "command-line": [ +// CHECK-NOT: "-W +// CHECK: ], +// CHECK-NEXT: "context-hash": "{{.*}}", +// CHECK-NEXT: "file-deps": [ +// CHECK: ], +// CHECK-NEXT: "name": "B" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK-NEXT: "translation-units": [ +// CHECK: ] +// CHECK: } + +//--- build/compile-commands.json.in + +[ +{ + "directory": "DIR", + "command": "clang -c DIR/A.m -isystem modules/A -I modules/B -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps", + "file": "DIR/A.m" +}, +{ + "directory": "DIR", + "command": "clang -c DIR/B.m -isystem modules/A -I modules/B -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps -Wmaybe-unused", + "file": "DIR/B.m" +} +] + +//--- modules/A/module.modulemap + +module A { + umbrella header "A.h" +} + +//--- modules/A/A.h + +typedef int A_t; + +//--- modules/B/module.modulemap + +module B [system] { + umbrella header "B.h" +} + +//--- modules/B/B.h + +typedef int B_t; + +//--- A.m + +#include <A.h> +#include <B.h> + +A_t a = 0; + +//--- B.m + +#include <A.h> +#include <B.h> + +A_t b = 0; Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -43,6 +43,28 @@ Opts.UserEntries.push_back(Entries[Idx]); } +static void optimizeDiagnosticOpts(DiagnosticOptions &Opts, + bool IsSystemModule) { + // If this is not a system module or -Wsystem-headers was passed, don't + // optimize. + if (!IsSystemModule) + return; + bool Wsystem_headers = false; + for (StringRef Opt : Opts.Warnings) { + bool isPositive = !Opt.consume_front("no-"); + if (Opt == "system-headers") + Wsystem_headers = isPositive; + } + if (Wsystem_headers) + return; + + // Remove all warning flags. System modules suppress most, but not all, + // warnings. + Opts.Warnings.clear(); + Opts.UndefPrefixes.clear(); + Opts.Remarks.clear(); +} + static std::vector<std::string> splitString(std::string S, char Separator) { SmallVector<StringRef> Segments; StringRef(S).split(Segments, Separator, /*MaxSplit=*/-1, /*KeepEmpty=*/false); @@ -480,9 +502,13 @@ CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs( MD, [&](CompilerInvocation &BuildInvocation) { - if (MDC.OptimizeArgs) + if (MDC.OptimizeArgs) { optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(), *MDC.ScanInstance.getASTReader(), *MF); + optimizeDiagnosticOpts( + BuildInvocation.getDiagnosticOpts(), + BuildInvocation.getFrontendOpts().IsSystemModule); + } }); MDC.associateWithContextHash(CI, MD);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits