[PATCH] D30963: Fix crash when an 'import a module' TypoCorrection has its CorrectionDecls replaced by visible decls.

Jorge Gorbe via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 2 18:03:56 PDT 2017


jgorbe updated this revision to Diff 101302.
jgorbe added a comment.

Also clear the 'requires import' flag when the TypoCorrection has no decls at all.


https://reviews.llvm.org/D30963

Files:
  lib/Sema/SemaLookup.cpp
  test/Modules/Inputs/crash-typo-correction-visibility/module.h
  test/Modules/Inputs/crash-typo-correction-visibility/module.modulemap
  test/Modules/crash-typo-correction-visibility.cpp


Index: test/Modules/crash-typo-correction-visibility.cpp
===================================================================
--- /dev/null
+++ test/Modules/crash-typo-correction-visibility.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-name=module -o %T/module.pcm -emit-module %S/Inputs/crash-typo-correction-visibility/module.modulemap
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-file=%T/module.pcm %s -verify
+
+struct S {
+  int member; // expected-note {{declared here}}
+};
+
+int f(...);
+
+int b = sizeof(f(member)); // expected-error {{undeclared identifier 'member'}}
Index: test/Modules/Inputs/crash-typo-correction-visibility/module.modulemap
===================================================================
--- /dev/null
+++ test/Modules/Inputs/crash-typo-correction-visibility/module.modulemap
@@ -0,0 +1,3 @@
+module "module" {
+  header "module.h"
+}
Index: test/Modules/Inputs/crash-typo-correction-visibility/module.h
===================================================================
--- /dev/null
+++ test/Modules/Inputs/crash-typo-correction-visibility/module.h
@@ -0,0 +1 @@
+struct member;
Index: lib/Sema/SemaLookup.cpp
===================================================================
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -3746,20 +3746,24 @@
                                       bool FindHidden);
 
 /// \brief Check whether the declarations found for a typo correction are
-/// visible, and if none of them are, convert the correction to an 'import
-/// a module' correction.
+/// visible. Set the correction's RequiresImport flag to true if none of the
+/// declarations are visible, false otherwise.
 static void checkCorrectionVisibility(Sema &SemaRef, TypoCorrection &TC) {
-  if (TC.begin() == TC.end())
+  if (TC.begin() == TC.end()) {
+    TC.setRequiresImport(false);
     return;
+  }
 
   TypoCorrection::decl_iterator DI = TC.begin(), DE = TC.end();
 
   for (/**/; DI != DE; ++DI)
     if (!LookupResult::isVisible(SemaRef, *DI))
       break;
-  // Nothing to do if all decls are visible.
-  if (DI == DE)
+  // No filtering needed if all decls are visible.
+  if (DI == DE) {
+    TC.setRequiresImport(false);
     return;
+  }
 
   llvm::SmallVector<NamedDecl*, 4> NewDecls(TC.begin(), DI);
   bool AnyVisibleDecls = !NewDecls.empty();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30963.101302.patch
Type: text/x-patch
Size: 2352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170603/1645b49a/attachment.bin>


More information about the cfe-commits mailing list