diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 4c2bf55f6ebdd..93fc97e6848ac 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -490,6 +490,8 @@ features cannot lower the translation-unit ABI level; - Fixed a crash when classifying a call to a builtin with dependent arguments, such as when the call is used as an `auto` non-type template argument. +- Fixed an assertion failure when diagnosing a constant evaluation failure + inside a member function call synthesized by ``__builtin_invoke``. (#GH185241) - Fixed a crash in ``__builtin_dump_struct`` when ``-Werror`` promotes format warnings to errors. (#GH211943) 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