https://github.com/akash-manna-sky updated https://github.com/llvm/llvm-project/pull/220593
>From 9f94c52814939bdb4b116866f4ea349b98160532 Mon Sep 17 00:00:00 2001 From: Akash Manna <[email protected]> Date: Wed, 2 Sep 2026 19:03:31 +0530 Subject: [PATCH 1/2] [clang][Sema] Give calls synthesized by __builtin_invoke a valid source range BuiltinInvoke wrapped the synthesized obj.*memptr expression in a ParenExpr with invalid source locations, so the member call built from it had an invalid begin location whenever there were no trailing arguments to fall back on. The constant evaluator stores each call expression's range as the frame's CallRange and asserts it is valid when building the "in call to" note chain, so diagnosing a failure inside such a call crashed. Use the builtin call's own locations for the ParenExpr so the synthesized call maps back to the __builtin_invoke call site. Fixes #185241 --- clang/docs/ReleaseNotes.md | 3 +++ clang/lib/Sema/SemaChecking.cpp | 3 ++- clang/test/SemaCXX/builtin-invoke.cpp | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 4c2bf55f6ebdd..0a7e628aa1880 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -492,6 +492,9 @@ features cannot lower the translation-unit ABI level; such as when the call is used as an `auto` non-type template argument. - Fixed a crash in ``__builtin_dump_struct`` when ``-Werror`` promotes format warnings to errors. (#GH211943) +- Fixed an assertion failure when diagnosing a constant evaluation failure + inside a member function call synthesized by ``__builtin_invoke``. + (#GH185241) #### Bug Fixes to Attribute Support diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 7b4dca61f70dc..564369da4ddea 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3015,8 +3015,9 @@ static ExprResult BuiltinInvoke(Sema &S, CallExpr *TheCall) { if (MPT->isMemberDataPointer()) return BinOp; + // Give the synthesized expression a valid source range for diagnostics. auto *MemCall = new (S.Context) - ParenExpr(SourceLocation(), SourceLocation(), BinOp.get()); + ParenExpr(TheCall->getBeginLoc(), TheCall->getRParenLoc(), BinOp.get()); return S.ActOnCallExpr(S.getCurScope(), MemCall, TheCall->getBeginLoc(), Args.drop_front(2), TheCall->getRParenLoc()); diff --git a/clang/test/SemaCXX/builtin-invoke.cpp b/clang/test/SemaCXX/builtin-invoke.cpp index d7694d619c692..e92ccc4e62d8f 100644 --- a/clang/test/SemaCXX/builtin-invoke.cpp +++ b/clang/test/SemaCXX/builtin-invoke.cpp @@ -238,3 +238,17 @@ static_assert([]() { return true; }()); + +namespace GH185241 { +struct S { + constexpr int func() {} // expected-note {{control reached end of constexpr function}} +}; + +static_assert([]() { // expected-error {{static assertion expression is not an integral constant expression}} \ + expected-note {{in call to '[]() {}.operator()()'}} + S s; + if (__builtin_invoke(&S::func, s)) // expected-note {{in call to 's.func()'}} + return false; + return true; +}()); +} // namespace GH185241 >From c1ed37a5ea1edfed79dff782f62a8c9dcf9e2901 Mon Sep 17 00:00:00 2001 From: Akash Manna <[email protected]> Date: Thu, 3 Sep 2026 11:25:44 +0530 Subject: [PATCH 2/2] Apply release note formatting as per suggestion. --- clang/docs/ReleaseNotes.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 0a7e628aa1880..939b6ac3cf764 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -493,8 +493,7 @@ features cannot lower the translation-unit ABI level; - Fixed a crash in ``__builtin_dump_struct`` when ``-Werror`` promotes format warnings to errors. (#GH211943) - Fixed an assertion failure when diagnosing a constant evaluation failure - inside a member function call synthesized by ``__builtin_invoke``. - (#GH185241) + inside a member function call synthesized by ``__builtin_invoke``. (#GH185241) #### Bug Fixes to Attribute Support _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
