https://github.com/tru updated https://github.com/llvm/llvm-project/pull/154210
>From 7d6969bc6f86265ac938112b0d4d5f7dfea0510d Mon Sep 17 00:00:00 2001 From: Oliver Hunt <oli...@apple.com> Date: Mon, 18 Aug 2025 14:38:50 -0700 Subject: [PATCH] [clang][ObjC] Fix incorrect return type inference for discarded blocks (#154109) When parsing a block expression we were not entering a new eval context and as a result when parsing the block body we continue to treat any return statements as discarded so infer a `void` result. This fixes the problem by introducing an evaluation context around the parsing of the body. (cherry picked from commit ec4e6aaac4612af26322b2b10b8f518ecf053c74) --- clang/lib/Parse/ParseExpr.cpp | 3 ++- .../SemaObjCXX/discarded-block-type-inference.mm | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaObjCXX/discarded-block-type-inference.mm diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index bc238a9517a37..3515343202de1 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -3342,7 +3342,8 @@ ExprResult Parser::ParseBlockLiteralExpression() { Actions.ActOnBlockError(CaretLoc, getCurScope()); return ExprError(); } - + EnterExpressionEvaluationContextForFunction PotentiallyEvaluated( + Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); StmtResult Stmt(ParseCompoundStatementBody()); BlockScope.Exit(); if (!Stmt.isInvalid()) diff --git a/clang/test/SemaObjCXX/discarded-block-type-inference.mm b/clang/test/SemaObjCXX/discarded-block-type-inference.mm new file mode 100644 index 0000000000000..8e2587724a7f6 --- /dev/null +++ b/clang/test/SemaObjCXX/discarded-block-type-inference.mm @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fobjc-arc -fblocks %s + +void block_receiver(int (^)() ); + +int f1() { + if constexpr (0) + (block_receiver)(^{ return 2; }); + return 1; +} + +int f2() { + if constexpr (0) + return (^{ return 2; })(); + return 1; +} _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits