Author: Vladislav Semykin Date: 2026-05-26T08:16:15Z New Revision: 970ecaef1db3701f04e63223ce9188a748be6083
URL: https://github.com/llvm/llvm-project/commit/970ecaef1db3701f04e63223ce9188a748be6083 DIFF: https://github.com/llvm/llvm-project/commit/970ecaef1db3701f04e63223ce9188a748be6083.diff LOG: [Clang][Sema] Fix crash in __builtin_dump_struct with immediate callables (#192880) ## Motivation `ComplexRemove` (used by `Sema::PopExpressionEvaluationContext` to strip nested `ConstantExpr` wrappers) inherits the default `TreeTransform::TransformOpaqueValueExpr`, which asserts on any `OpaqueValueExpr` with a non-null `SourceExpr` unless a binding has already been set up. `__builtin_dump_struct` binds the record pointer to an `OpaqueValueExpr` inside a `PseudoObjectExpr`. When the callable argument is immediate-escalated (e.g. via `__builtin_is_within_lifetime`), `RemoveNestedImmediateInvocation` roots `ComplexRemove` inside the PSE's semantic form, reaching that OVE without the binding the assert expects - triggering a crash. ## Closing Issues Closes #192846 --------- Signed-off-by: ViNN280801 <[email protected]> Co-authored-by: Corentin Jabot <[email protected]> Co-authored-by: Younan Zhang <[email protected]> Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExpr.cpp clang/test/SemaCXX/cxx2a-consteval.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f514c4ff3277f..cef93e25f1e7d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -719,6 +719,8 @@ Miscellaneous Clang Crashes Fixed - Fixed an assertion failure when parsing an invalid out-of-line enum definition with template parameters. (#GH187909) - Fixed an assertion failure on invalid template template parameter during typo correction. (#GH183983) - Fixed an assertion failure in ``isAtEndOfMacroExpansion`` on macro expansions crossing the boundary of two fileIDs. (#GH115007), (#GH21755) +- Fixed an assertion failure when ``__builtin_dump_struct`` is used with an + immediate-escalated callable. (#GH192846) OpenACC Specific Changes ------------------------ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 521a8516ac179..db0fbdc546fbc 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -18479,6 +18479,11 @@ static void RemoveNestedImmediateInvocation( // Lambdas have already been processed inside their eval contexts. return E; } + + // We do not have enough information to transform opaque expressions and + // assume they do not contain immediate subexpressions. + ExprResult TransformOpaqueValueExpr(OpaqueValueExpr *E) { return E; } + bool AlwaysRebuild() { return false; } bool ReplacingOriginal() { return true; } bool AllowSkippingCXXConstructExpr() { diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp b/clang/test/SemaCXX/cxx2a-consteval.cpp index 6440a4e85df83..7a017e513b2a3 100644 --- a/clang/test/SemaCXX/cxx2a-consteval.cpp +++ b/clang/test/SemaCXX/cxx2a-consteval.cpp @@ -1344,3 +1344,22 @@ void g() { f<int>(); } } // namespace GH156579 + +namespace GH192846 { + +struct S {}; + +consteval void F(S &out, const char *fmt, ...) {} + +template <class T> +class C { + T value = {}; +}; + +constexpr C<int> g_c{}; + +void bar() { + S s; + __builtin_dump_struct(&g_c, F, s); +} +} // namespace GH192846 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
