r374152 - [Sema] Emit diagnostics for uncorrected delayed typos at the end of TU

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 9 03:00:06 PDT 2019


Author: ibiryukov
Date: Wed Oct  9 03:00:05 2019
New Revision: 374152

URL: http://llvm.org/viewvc/llvm-project?rev=374152&view=rev
Log:
[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

Modified:
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/test/SemaObjC/typo-correction-subscript.m

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=374152&r1=374151&r2=374152&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Wed Oct  9 03:00:05 2019
@@ -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::ActOnEndOfTranslationUnitFrag
   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

Modified: cfe/trunk/test/SemaObjC/typo-correction-subscript.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/typo-correction-subscript.m?rev=374152&r1=374151&r2=374152&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/typo-correction-subscript.m (original)
+++ cfe/trunk/test/SemaObjC/typo-correction-subscript.m Wed Oct  9 03:00:05 2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i386-apple-macosx10.10 -fobjc-arc -fsyntax-only -Wno-objc-root-class %s -verify -disable-free
+// RUN: %clang_cc1 -triple i386-apple-macosx10.10 -fobjc-arc -fsyntax-only -Wno-objc-root-class %s -verify
 
 @class Dictionary;
 
@@ -9,6 +9,7 @@
 - (void)rdar47403222:(Dictionary *)opts {
   [self undeclaredMethod:undeclaredArg];
   // expected-error at -1{{no visible @interface for 'Test' declares the selector 'undeclaredMethod:'}}
+  // expected-error at -2{{use of undeclared identifier 'undeclaredArg}}
   opts[(__bridge id)undeclaredKey] = 0;
   // expected-error at -1{{use of undeclared identifier 'undeclaredKey'}}
 }




More information about the cfe-commits mailing list