jansvoboda11 created this revision. jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman. jansvoboda11 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Inject custom diagnostic options into `ToolInvocation` with stripped diagnostic serialization file to make test pass again. Also add test that confirms the driver -> cc1 command-line transformation/parsing respects `-Wno-error=...`. Depends on D108981 <https://reviews.llvm.org/D108981>. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D108982 Files: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp clang/test/ClangScanDeps/Inputs/diagnostics/cdb.json.template clang/test/ClangScanDeps/Inputs/diagnostics/tu.c clang/test/ClangScanDeps/diagnostics.c clang/test/ClangScanDeps/strip_diag_serialize.cpp
Index: clang/test/ClangScanDeps/strip_diag_serialize.cpp =================================================================== --- clang/test/ClangScanDeps/strip_diag_serialize.cpp +++ clang/test/ClangScanDeps/strip_diag_serialize.cpp @@ -1,6 +1,3 @@ -// FIXME: Make this pass again. -// XFAIL: * - // RUN: rm -rf %t.dir // RUN: rm -rf %t.cdb // RUN: mkdir -p %t.dir Index: clang/test/ClangScanDeps/diagnostics.c =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/diagnostics.c @@ -0,0 +1,8 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: cp %S/Inputs/diagnostics/* %t + +// RUN: sed "s|DIR|%/t|g" %S/Inputs/diagnostics/cdb.json.template > %t/cdb.json +// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \ +// RUN: -generate-modules-path-args -module-files-dir %t/build 2>&1 | FileCheck %s + +// CHECK-NOT: error: invalid iOS deployment version Index: clang/test/ClangScanDeps/Inputs/diagnostics/cdb.json.template =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/Inputs/diagnostics/cdb.json.template @@ -0,0 +1,7 @@ +[ + { + "directory": "DIR", + "command": "clang -c DIR/tu.c -target i386-apple-ios14.0-simulator -Wno-error=invalid-ios-deployment-target -o DIR/tu.o", + "file": "DIR/tu.c" + } +] Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -269,8 +269,6 @@ DependencyScanningWorker::DependencyScanningWorker( DependencyScanningService &Service) : Format(Service.getFormat()) { - DiagOpts = new DiagnosticOptions(); - PCHContainerOps = std::make_shared<PCHContainerOperations>(); PCHContainerOps->registerReader( std::make_unique<ObjectFilePCHContainerReader>()); @@ -290,16 +288,20 @@ Files = new FileManager(FileSystemOptions(), RealFS); } -static llvm::Error runWithDiags( - DiagnosticOptions *DiagOpts, - llvm::function_ref<bool(DiagnosticConsumer &DC)> BodyShouldSucceed) { +static llvm::Error +runWithDiags(DiagnosticOptions *DiagOpts, + llvm::function_ref<bool(DiagnosticConsumer &, DiagnosticOptions &)> + BodyShouldSucceed) { + // Avoid serializing diagnostics. + DiagOpts->DiagnosticSerializationFile.clear(); + // Capture the emitted diagnostics and report them to the client // in the case of a failure. std::string DiagnosticOutput; llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput); TextDiagnosticPrinter DiagPrinter(DiagnosticsOS, DiagOpts); - if (BodyShouldSucceed(DiagPrinter)) + if (BodyShouldSucceed(DiagPrinter, *DiagOpts)) return llvm::Error::success(); return llvm::make_error<llvm::StringError>(DiagnosticsOS.str(), llvm::inconvertibleErrorCode()); @@ -313,15 +315,22 @@ llvm::IntrusiveRefCntPtr<FileManager> CurrentFiles = Files ? Files : new FileManager(FileSystemOptions(), RealFS); - return runWithDiags(DiagOpts.get(), [&](DiagnosticConsumer &DC) { - DependencyScanningAction Action(WorkingDirectory, Consumer, DepFS, - PPSkipMappings.get(), Format); - // Create an invocation that uses the underlying file system to ensure that - // any file system requests that are made by the driver do not go through - // the dependency scanning filesystem. - ToolInvocation Invocation(CommandLine, &Action, CurrentFiles.get(), - PCHContainerOps); - Invocation.setDiagnosticConsumer(&DC); - return Invocation.run(); - }); + std::vector<const char *> CCommandLine(CommandLine.size(), nullptr); + llvm::transform(CommandLine, CCommandLine.begin(), + [](const std::string &Str) { return Str.c_str(); }); + + return runWithDiags( + CreateAndPopulateDiagOpts(CCommandLine), + [&](DiagnosticConsumer &DC, DiagnosticOptions &DiagOpts) { + DependencyScanningAction Action(WorkingDirectory, Consumer, DepFS, + PPSkipMappings.get(), Format); + // Create an invocation that uses the underlying file system to ensure that + // any file system requests that are made by the driver do not go through + // the dependency scanning filesystem. + ToolInvocation Invocation(CommandLine, &Action, CurrentFiles.get(), + PCHContainerOps); + Invocation.setDiagnosticConsumer(&DC); + Invocation.setDiagnosticOptions(&DiagOpts); + return Invocation.run(); + }); } Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h =================================================================== --- clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h +++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h @@ -66,7 +66,6 @@ DependencyConsumer &Consumer); private: - IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; std::shared_ptr<PCHContainerOperations> PCHContainerOps; std::unique_ptr<ExcludedPreprocessorDirectiveSkipMapping> PPSkipMappings;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits