if (DiagID >= diag::DIAG_UPPER_LIMIT)
return false;
- return GetDefaultDiagMapping(DiagID).getSeverity() == diag::Severity::Error;
+ return GetDefaultDiagMapping(DiagID).getSeverity() >= diag::Severity::Error;
}
/// getDescription - Given a diagnostic ID, return a description of the
}
bool ASTUnit::serialize(raw_ostream &OS) {
- bool hasErrors = getDiagnostics().hasErrorOccurred();
+ // For serialization we are lenient if the errors were only warn-as-error kind.
+ bool hasErrors = getDiagnostics().hasUncompilableErrorOccurred();
if (WriterData)
return serializeUnit(WriterData->Writer, WriterData->Buffer,
ArrayRef<llvm::IntrusiveRefCntPtr<ModuleFileExtension>> Extensions;
auto consumer = llvm::make_unique<PCHGenerator>(
Clang->getPreprocessor(), "-", nullptr, /*isysroot=*/"", Buffer,
- Extensions);
+ Extensions, /*AllowASTWithErrors=*/true);
Clang->getASTContext().setASTMutationListener(
consumer->GetASTMutationListener());
Clang->setASTConsumer(std::move(consumer));
if (cast<DeclContext>(D)->isDependentContext())
return;
- if (Diags.hasUncompilableErrorOccurred() || Diags.hasFatalErrorOccurred()) {
+ if (Diags.hasUncompilableErrorOccurred()) {
// Flush out any possibly unreachable diagnostics.
flushDiagnostics(S, fscope);
return;
Diag(diag::err_pch_with_compiler_errors);
return HadErrors;
}
+ if (hasErrors) {
+ Diags.ErrorOccurred = true;
+ Diags.UncompilableErrorOccurred = true;
+ Diags.UnrecoverableErrorOccurred = true;
+ }
F.RelocatablePCH = Record[4];
// Relative paths in a relocatable PCH are relative to our sysroot.
// Emit the PCH file to the Buffer.
assert(SemaPtr && "No Sema?");
Buffer->Signature =
- Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, hasErrors);
+ Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot,
+ // For serialization we are lenient if the errors were
+ // only warn-as-error kind.
+ PP.getDiagnostics().hasUncompilableErrorOccurred());
Buffer->IsComplete = true;
}
--- /dev/null
+// RUN: CINDEXTEST_EDITING=1 c-index-test -test-load-source local %s -Wuninitialized -Werror=unused 2>&1 | FileCheck -check-prefix=DIAGS %s
+
+// Make sure -Wuninitialized works even though the header had a warn-as-error occurrence.
+
+// DIAGS: error: unused variable 'x'
+// DIAGS: warning: variable 'x1' is uninitialized
+// DIAGS-NOT: error: use of undeclared identifier
+// DIAGS: warning: variable 'x1' is uninitialized
+
+#include "pch-warn-as-error-code-split.h"
+
+void test() {
+ int x1; // expected-note {{initialize}}
+ int x2 = x1; // expected-warning {{uninitialized}}
+ (void)x2;
+ foo_head();
+}
--- /dev/null
+
+static void foo_head() {
+ int x;
+}
--- /dev/null
+// RUN: rm -f %t.head.h.pch
+// RUN: c-index-test -write-pch %t.head.h.pch %s -Wuninitialized -Werror=unused 2>&1 | FileCheck -check-prefix=HEAD_DIAGS %s
+// RUN: c-index-test -test-load-source local %s -include %t.head.h -Wuninitialized -Werror=unused 2>&1 | FileCheck -check-prefix=MAIN_DIAGS %s
+
+// Make sure -Wuninitialized works even though the header had a warn-as-error occurrence.
+
+// HEAD_DIAGS: error: unused variable 'x'
+// MAIN_DIAGS: warning: variable 'x1' is uninitialized
+// MAIN_DIAGS-NOT: error: use of undeclared identifier
+
+#ifndef HEADER
+#define HEADER
+
+static void foo_head() {
+ int x;
+}
+
+#else
+
+void test() {
+ int x1; // expected-note {{initialize}}
+ int x2 = x1; // expected-warning {{uninitialized}}
+ (void)x2;
+ foo_head();
+}
+
+#endif
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only %s -chain-include %s -Wuninitialized -Wunused -verify
+
+// Make sure there is no crash.
+
+#ifndef HEADER
+#define HEADER
+
+#include "non-existent-header.h"
+
+class A {
+public:
+ ~A();
+};
+
+class ForwardCls;
+struct B {
+ ForwardCls f;
+ A a;
+};
+
+#else
+
+static void test() {
+ int x; // expected-warning {{unused}}
+ B b;
+}
+
+#endif