r304745 - Fix crash when an 'import a module' TypoCorrection has its CorrectionDecls

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 5 15:29:36 PDT 2017


Author: rsmith
Date: Mon Jun  5 17:29:36 2017
New Revision: 304745

URL: http://llvm.org/viewvc/llvm-project?rev=304745&view=rev
Log:
Fix crash when an 'import a module' TypoCorrection has its CorrectionDecls
replaced by visible decls.

Make sure that all paths through checkCorrectionVisibility set the
RequiresImport flag appropriately, so we don't end up using a stale value.
Patch by Jorge Gorbe!

Differential Revision: https://reviews.llvm.org/D30963

Added:
    cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/
    cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.h
    cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.modulemap
    cfe/trunk/test/Modules/crash-typo-correction-visibility.cpp
Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=304745&r1=304744&r2=304745&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Jun  5 17:29:36 2017
@@ -3747,20 +3747,19 @@ static void LookupPotentialTypoResult(Se
                                       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())
-    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();

Added: cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.h?rev=304745&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.h (added)
+++ cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.h Mon Jun  5 17:29:36 2017
@@ -0,0 +1 @@
+struct member;

Added: cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.modulemap?rev=304745&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/crash-typo-correction-visibility/module.modulemap Mon Jun  5 17:29:36 2017
@@ -0,0 +1,3 @@
+module "module" {
+  header "module.h"
+}

Added: cfe/trunk/test/Modules/crash-typo-correction-visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-typo-correction-visibility.cpp?rev=304745&view=auto
==============================================================================
--- cfe/trunk/test/Modules/crash-typo-correction-visibility.cpp (added)
+++ cfe/trunk/test/Modules/crash-typo-correction-visibility.cpp Mon Jun  5 17:29:36 2017
@@ -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'}}




More information about the cfe-commits mailing list