Skip to content

Commit 993f60a

Browse files
committed
[clang][deps] Sanitize both instances of DiagnosticOptions
During dependency scanning, we generally want to suppress -Werror. Apply the same logic to the DiagnosticOptions instance used for command-line parsing. This fixes a test failure on the PS4 bot, where the system header directory could not be found, which was reported due to -Werror being on the command line and not being sanitized.
1 parent ec7d8d5 commit 993f60a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ deduceDepTarget(const std::string &OutputFile,
133133
return makeObjFileName(InputFiles.front().getFile());
134134
}
135135

136+
/// Sanitize diagnostic options for dependency scan.
137+
static void sanitizeDiagOpts(DiagnosticOptions &DiagOpts) {
138+
// Don't print 'X warnings and Y errors generated'.
139+
DiagOpts.ShowCarets = false;
140+
// Don't write out diagnostic file.
141+
DiagOpts.DiagnosticSerializationFile.clear();
142+
// Don't treat warnings as errors.
143+
DiagOpts.Warnings.push_back("no-error");
144+
}
145+
136146
/// A clang tool that runs the preprocessor in a mode that's optimized for
137147
/// dependency scanning for the given compiler invocation.
138148
class DependencyScanningAction : public tooling::ToolAction {
@@ -157,13 +167,8 @@ class DependencyScanningAction : public tooling::ToolAction {
157167
CompilerInstance Compiler(std::move(PCHContainerOps));
158168
Compiler.setInvocation(std::move(Invocation));
159169

160-
// Don't print 'X warnings and Y errors generated'.
161-
Compiler.getDiagnosticOpts().ShowCarets = false;
162-
// Don't write out diagnostic file.
163-
Compiler.getDiagnosticOpts().DiagnosticSerializationFile.clear();
164-
// Don't treat warnings as errors.
165-
Compiler.getDiagnosticOpts().Warnings.push_back("no-error");
166170
// Create the compiler's actual diagnostics engine.
171+
sanitizeDiagOpts(Compiler.getDiagnosticOpts());
167172
Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false);
168173
if (!Compiler.hasDiagnostics())
169174
return false;
@@ -304,8 +309,7 @@ static llvm::Error
304309
runWithDiags(DiagnosticOptions *DiagOpts,
305310
llvm::function_ref<bool(DiagnosticConsumer &, DiagnosticOptions &)>
306311
BodyShouldSucceed) {
307-
// Avoid serializing diagnostics.
308-
DiagOpts->DiagnosticSerializationFile.clear();
312+
sanitizeDiagOpts(*DiagOpts);
309313

310314
// Capture the emitted diagnostics and report them to the client
311315
// in the case of a failure.

clang/test/ClangScanDeps/error.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
// CHECK-NEXT: error:
2222
// CHECK-NEXT: Error while scanning dependencies
2323
// CHECK-NEXT: fatal error: 'missing.h' file not found
24-
// CHECK-NEXT: "missing.h"
25-
// CHECK-NEXT: ^
2624
// CHECK-NEXT: Error while scanning dependencies
2725
// CHECK-NEXT: fatal error: 'missing.h' file not found
28-
// CHECK-NEXT: "missing.h"
29-
// CHECK-NEXT: ^
3026
// CHECK-NEXT: EOF

0 commit comments

Comments
 (0)