[PATCH] D82738: [clang] Fix a null-NSS-access crash in DependentNameType.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 28 23:57:32 PDT 2020


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.

The DependentNameType must have a non-null NSS. This property could be
violated during typo correction.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82738

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/Parser/cxx-template-decl.cpp


Index: clang/test/Parser/cxx-template-decl.cpp
===================================================================
--- clang/test/Parser/cxx-template-decl.cpp
+++ clang/test/Parser/cxx-template-decl.cpp
@@ -286,3 +286,16 @@
   template<int> int b;
   template<int> auto f() -> b<0>; // expected-error +{{}}
 }
+
+namespace NoCrashOnNullNNSTypoCorrection {
+
+int AddObservation(); // expected-note {{declared here}}
+
+template <typename T, typename... Args>
+class UsingImpl {};
+class AddObservation {
+  using Using =
+    UsingImpl<AddObservationFn, const int>; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}}
+};
+
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -4866,6 +4866,11 @@
       if (Result.getAsSingle<TypeDecl>() ||
           Result.getResultKind() ==
               LookupResult::NotFoundInCurrentInstantiation) {
+        if (SS.isEmpty())
+          // bail out if we don't have a NNS, this could be happened during
+          // typo correction in error recovery.
+          // A dependent name type should have a non-null NNS.
+          return true;
         // Suggest that the user add 'typename' before the NNS.
         SourceLocation Loc = AL.getSourceRange().getBegin();
         Diag(Loc, getLangOpts().MSVCCompat


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82738.273998.patch
Type: text/x-patch
Size: 1418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200629/16c68312/attachment-0001.bin>


More information about the cfe-commits mailing list