https://github.com/ChenMiaoi created https://github.com/llvm/llvm-project/pull/239107
Share the parsing logic for __builtin_astype and __builtin_convertvector, then dispatch to their respective Sema actions. Preserve diagnostics and error recovery. >From 191bb7c4f71d94255528d90b2a4230f64e0a6b6b Mon Sep 17 00:00:00 2001 From: Chen Miao <[email protected]> Date: Thu, 5 Nov 2026 14:10:12 +0800 Subject: [PATCH] [clang][Parse][NFC] Share parsing for astype and convertvector builtins Share the parsing logic for __builtin_astype and __builtin_convertvector, then dispatch to their respective Sema actions. Preserve diagnostics and error recovery. --- clang/lib/Parse/ParseExpr.cpp | 38 +++++++---------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index d42ffc2ccf0a65..14a55cfecfb8e0 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -2524,35 +2524,7 @@ ExprResult Parser::ParseBuiltinPrimaryExpression() { Expr2.get(), ConsumeParen()); break; } - case tok::kw___builtin_astype: { - // The first argument is an expression to be converted, followed by a comma. - ExprResult Expr(ParseAssignmentExpression()); - if (Expr.isInvalid()) { - SkipUntil(tok::r_paren, StopAtSemi); - return ExprError(); - } - - if (ExpectAndConsume(tok::comma)) { - SkipUntil(tok::r_paren, StopAtSemi); - return ExprError(); - } - - // Second argument is the type to bitcast to. - TypeResult DestTy = ParseTypeName(); - if (DestTy.isInvalid()) - return ExprError(); - - // Attempt to consume the r-paren. - if (Tok.isNot(tok::r_paren)) { - Diag(Tok, diag::err_expected) << tok::r_paren; - SkipUntil(tok::r_paren, StopAtSemi); - return ExprError(); - } - - Res = Actions.ActOnAsTypeExpr(Expr.get(), DestTy.get(), StartLoc, - ConsumeParen()); - break; - } + case tok::kw___builtin_astype: case tok::kw___builtin_convertvector: { // The first argument is an expression to be converted, followed by a comma. ExprResult Expr(ParseAssignmentExpression()); @@ -2578,8 +2550,12 @@ ExprResult Parser::ParseBuiltinPrimaryExpression() { return ExprError(); } - Res = Actions.ActOnConvertVectorExpr(Expr.get(), DestTy.get(), StartLoc, - ConsumeParen()); + if (T == tok::kw___builtin_astype) + Res = Actions.ActOnAsTypeExpr(Expr.get(), DestTy.get(), StartLoc, + ConsumeParen()); + else + Res = Actions.ActOnConvertVectorExpr(Expr.get(), DestTy.get(), StartLoc, + ConsumeParen()); break; } case tok::kw___builtin_COLUMN: _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
