HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In the presence of pp branches we parse the token stream multiple times. Thus 
the token already has the type set. It's best just not to assert on any type in 
the parser.

Fixes https://github.com/llvm/llvm-project/issues/54019


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120512

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23808,6 +23808,15 @@
 
   verifyFormat("template <typename T>\n"
                "concept C = [] && requires(T t) { typename T::size_type; };");
+
+  verifyFormat("template <typename T>\n"
+               "concept C =\n"
+               "#if X\n"
+               "    A &&\n"
+               "#else\n"
+               "    B &&\n"
+               "#endif\n"
+               "    requires C2<T>;");
 }
 
 TEST_F(FormatTest, RequiresClausesPositions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2995,7 +2995,6 @@
 void UnwrappedLineParser::parseRequiresClause(FormatToken *RequiresToken) {
   assert(FormatTok->getPreviousNonComment() == RequiresToken);
   assert(RequiresToken->is(tok::kw_requires) && "'requires' expected");
-  assert(RequiresToken->getType() == TT_Unknown);
 
   // If there is no previous token, we are within a requires expression,
   // otherwise we will always have the template or function declaration in 
front
@@ -3024,7 +3023,6 @@
 void UnwrappedLineParser::parseRequiresExpression(FormatToken *RequiresToken) {
   assert(FormatTok->getPreviousNonComment() == RequiresToken);
   assert(RequiresToken->is(tok::kw_requires) && "'requires' expected");
-  assert(RequiresToken->getType() == TT_Unknown);
 
   RequiresToken->setFinalizedType(TT_RequiresExpression);
 


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23808,6 +23808,15 @@
 
   verifyFormat("template <typename T>\n"
                "concept C = [] && requires(T t) { typename T::size_type; };");
+
+  verifyFormat("template <typename T>\n"
+               "concept C =\n"
+               "#if X\n"
+               "    A &&\n"
+               "#else\n"
+               "    B &&\n"
+               "#endif\n"
+               "    requires C2<T>;");
 }
 
 TEST_F(FormatTest, RequiresClausesPositions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2995,7 +2995,6 @@
 void UnwrappedLineParser::parseRequiresClause(FormatToken *RequiresToken) {
   assert(FormatTok->getPreviousNonComment() == RequiresToken);
   assert(RequiresToken->is(tok::kw_requires) && "'requires' expected");
-  assert(RequiresToken->getType() == TT_Unknown);
 
   // If there is no previous token, we are within a requires expression,
   // otherwise we will always have the template or function declaration in front
@@ -3024,7 +3023,6 @@
 void UnwrappedLineParser::parseRequiresExpression(FormatToken *RequiresToken) {
   assert(FormatTok->getPreviousNonComment() == RequiresToken);
   assert(RequiresToken->is(tok::kw_requires) && "'requires' expected");
-  assert(RequiresToken->getType() == TT_Unknown);
 
   RequiresToken->setFinalizedType(TT_RequiresExpression);
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to