[clang] 143b510 - [Clang] Fix asan error after ad1a65fca

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 27 05:35:28 PST 2024


Author: Corentin Jabot
Date: 2024-01-27T14:35:18+01:00
New Revision: 143b510a8fefb0d203c9ac7e036aa9967dd8a2ef

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

LOG: [Clang] Fix asan error after ad1a65fca

Annotating tokens can invalid the stack of Peaked tokens.

Added: 
    

Modified: 
    clang/lib/Parse/ParseExpr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 6e83b7aa3441b5c..68dc1bc4a40a074 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1065,7 +1065,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
     if (getLangOpts().CPlusPlus) {
       // Avoid the unnecessary parse-time lookup in the common case
       // where the syntax forbids a type.
-      const Token &Next = NextToken();
+      Token Next = NextToken();
 
       if (Next.is(tok::ellipsis) && Tok.is(tok::identifier) &&
           GetLookAheadToken(2).is(tok::l_square)) {
@@ -1081,9 +1081,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
       // If this identifier was reverted from a token ID, and the next token
       // is a parenthesis, this is likely to be a use of a type trait. Check
       // those tokens.
-      if (Next.is(tok::l_paren) &&
-          Tok.is(tok::identifier) &&
-          Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) {
+      else if (Next.is(tok::l_paren) && Tok.is(tok::identifier) &&
+               Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) {
         IdentifierInfo *II = Tok.getIdentifierInfo();
         // Build up the mapping of revertible type traits, for future use.
         if (RevertibleTypeTraits.empty()) {
@@ -1170,9 +1169,9 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
         }
       }
 
-      if ((!ColonIsSacred && Next.is(tok::colon)) ||
-          Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
-                       tok::l_brace)) {
+      else if ((!ColonIsSacred && Next.is(tok::colon)) ||
+               Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
+                            tok::l_brace)) {
         // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
         if (TryAnnotateTypeOrScopeToken())
           return ExprError();


        


More information about the cfe-commits mailing list