[clang] d1fcce9 - [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 29 15:43:35 PDT 2023


Author: Shafik Yaghmour
Date: 2023-06-29T15:42:18-07:00
New Revision: d1fcce97a6af872e64b365d80d5b85eb94487dc8

URL: https://github.com/llvm/llvm-project/commit/d1fcce97a6af872e64b365d80d5b85eb94487dc8
DIFF: https://github.com/llvm/llvm-project/commit/d1fcce97a6af872e64b365d80d5b85eb94487dc8.diff

LOG: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

When attempting to decide if in C++17 a type template for class template
argument deduction and the code is ill-formed the condition to break is
checking the current token is an identifier when it should be checking
if the next token is not ::.

This fixes: https://github.com/llvm/llvm-project/issues/57495
https://github.com/llvm/llvm-project/issues/63052

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

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Parse/ParseTentative.cpp
    clang/test/Parser/cxx1z-class-template-argument-deduction.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3afb4b1edb2dbd..da4ddff93c1f95 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -553,6 +553,10 @@ Bug Fixes in This Version
   (`#48512 <https://github.com/llvm/llvm-project/issues/48512>`_).
 - Fixed a failing assertion when parsing incomplete destructor.
   (`#63503 <https://github.com/llvm/llvm-project/issues/63503>`_)
+- Fix C++17 mode assert when parsing malformed code and the compiler is
+  attempting to see if it could be type template for class template argument
+  deduction. This fixes
+  (`Issue 57495 <https://github.com/llvm/llvm-project/issues/57495>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index 89e543f4b0900f..b7c83bbeb82ee7 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1656,7 +1656,10 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
             if (getLangOpts().CPlusPlus17) {
               if (TryAnnotateTypeOrScopeToken())
                 return TPResult::Error;
-              if (Tok.isNot(tok::identifier))
+              // If we annotated then the current token should not still be ::
+              // FIXME we may want to also check for tok::annot_typename but
+              // currently don't have a test case.
+              if (Tok.isNot(tok::annot_cxxscope))
                 break;
             }
 

diff  --git a/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp b/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
index fd651ad1b1b48f..2dd61baac31b3c 100644
--- a/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ b/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -247,3 +247,11 @@ struct A2 {
 };
 
 }
+
+namespace GH57495 {
+template <typename T> struct vector{};
+
+void f() {
+  GH57495::vector.d; // expected-error {{cannot use dot operator on a type}}
+}
+}


        


More information about the cfe-commits mailing list