diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2019-10-09 10:00:05 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2019-10-09 10:00:05 +0000 |
commit | aeae71cd96c3477ce09ed543bcb385583172a9be (patch) | |
tree | 15d32ef53aa415f685935991abae0f7aa50d1c94 /clang/lib/Sema/Sema.cpp | |
parent | df7ea71c3adf23f056eb0e0b926cef002812fb59 (diff) | |
download | bcm5719-llvm-aeae71cd96c3477ce09ed543bcb385583172a9be.tar.gz bcm5719-llvm-aeae71cd96c3477ce09ed543bcb385583172a9be.zip |
[Sema] Emit diagnostics for uncorrected delayed typos at the end of TU
Summary:
Instead of asserting all typos are corrected in the sema destructor.
The sema destructor is not run in the common case of running the compiler
with the -disable-free cc1 flag (which is the default in the driver).
Having this assertion led to crashes in libclang and clangd, which are not
reproducible when running the compiler.
Asserting at the end of the TU could be an option, but finding all
missing typo correction cases is hard and having worse diagnostics instead
of a failing assertion is a better trade-off.
For more discussion on this, see:
https://lists.llvm.org/pipermail/cfe-dev/2019-July/062872.html
Reviewers: sammccall, rsmith
Reviewed By: rsmith
Subscribers: usaxena95, dgoldman, jkorous, vsapsai, rnk, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64799
llvm-svn: 374152
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index d1b8e958e65..bedea216795 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -38,6 +38,7 @@ #include "clang/Sema/SemaInternal.h" #include "clang/Sema/TemplateDeduction.h" #include "clang/Sema/TemplateInstCallback.h" +#include "clang/Sema/TypoCorrection.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallSet.h" #include "llvm/Support/TimeProfiler.h" @@ -383,8 +384,6 @@ Sema::~Sema() { // Detach from the PP callback handler which outlives Sema since it's owned // by the preprocessor. SemaPPCallbackHandler->reset(); - - assert(DelayedTypos.empty() && "Uncorrected typos!"); } void Sema::warnStackExhausted(SourceLocation Loc) { @@ -934,6 +933,15 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) { assert(LateParsedInstantiations.empty() && "end of TU template instantiation should not create more " "late-parsed templates"); + + // Report diagnostics for uncorrected delayed typos. Ideally all of them + // should have been corrected by that time, but it is very hard to cover all + // cases in practice. + for (const auto &Typo : DelayedTypos) { + // We pass an empty TypoCorrection to indicate no correction was performed. + Typo.second.DiagHandler(TypoCorrection()); + } + DelayedTypos.clear(); } /// ActOnEndOfTranslationUnit - This is called at the very end of the |