Skip to content

Use static_pointer_cast to do SyntheticChildrenSP -> ScriptedSyntheticChildrenSP (#216181) - #216203

Open
jimingham wants to merge 1 commit into
llvm:release/23.xfrom
jimingham:static-ptr-23.x
Open

Use static_pointer_cast to do SyntheticChildrenSP -> ScriptedSyntheticChildrenSP (#216181)#216203
jimingham wants to merge 1 commit into
llvm:release/23.xfrom
jimingham:static-ptr-23.x

Conversation

@jimingham

Copy link
Copy Markdown
Contributor

FormatManager::GetSyntheticForType was taking a pointer out one shared pointer and making a new shared pointer referring to it which messes up the lifecycle of the object.

This is just a little thinko from the original implementation. We do the same thing in several other places in the TypeCategory, etc. and it's done correctly in all the other places.

I'm not adding a test here because trying to guess what you have to do to cause one or the other shared_pointer to get their reference count to 0 isn't particularly stable.

The testing for SBTypeSynthetic is pretty minimal - it would be better to write a complete test for this class, which would have tripped this. But that's a bigger task, and I want to get this obvious crasher fix in now.

This fixes:

github.com//issues/213628

(cherry picked from commit ae3ea1b)

…cChildrenSP (llvm#216181)

FormatManager::GetSyntheticForType was taking a pointer out one shared
pointer and making a new shared pointer referring to it which messes up
the lifecycle of the object.

This is just a little thinko from the original implementation. We do the
same thing in several other places in the TypeCategory, etc. and it's
done correctly in all the other places.

I'm not adding a test here because trying to guess what you have to do
to cause one or the other shared_pointer to get their reference count to
0 isn't particularly stable.

The testing for SBTypeSynthetic is pretty minimal - it would be better
to write a complete test for this class, which would have tripped this.
But that's a bigger task, and I want to get this obvious crasher fix in
now.

This fixes:

github.com/llvm/issues/213628

(cherry picked from commit ae3ea1b)
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-lldb

Author: jimingham

Changes

FormatManager::GetSyntheticForType was taking a pointer out one shared pointer and making a new shared pointer referring to it which messes up the lifecycle of the object.

This is just a little thinko from the original implementation. We do the same thing in several other places in the TypeCategory, etc. and it's done correctly in all the other places.

I'm not adding a test here because trying to guess what you have to do to cause one or the other shared_pointer to get their reference count to 0 isn't particularly stable.

The testing for SBTypeSynthetic is pretty minimal - it would be better to write a complete test for this class, which would have tripped this. But that's a bigger task, and I want to get this obvious crasher fix in now.

This fixes:

github.com//issues/213628

(cherry picked from commit ae3ea1b)


Full diff: https://github.com/llvm/llvm-project/pull/216203.diff

1 Files Affected:

  • (modified) lldb/source/DataFormatters/FormatManager.cpp (+5-5)
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp
index 6342fd89cc9be..e9f0e51e34149 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -388,14 +388,14 @@ FormatManager::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) {
     category_sp = GetCategoryAtIndex(category_id);
     if (!category_sp->IsEnabled())
       continue;
-    lldb::ScriptedSyntheticChildrenSP synth_current_sp(
-        (ScriptedSyntheticChildren *)category_sp->GetSyntheticForType(type_sp)
-            .get());
-    if (synth_current_sp &&
+    auto synth_current_sp = category_sp->GetSyntheticForType(type_sp);
+
+    if (synth_current_sp && synth_current_sp->IsScripted() &&
         (synth_chosen_sp.get() == nullptr ||
          (prio_category > category_sp->GetEnabledPosition()))) {
       prio_category = category_sp->GetEnabledPosition();
-      synth_chosen_sp = synth_current_sp;
+      synth_chosen_sp =
+          std::static_pointer_cast<ScriptedSyntheticChildren>(synth_current_sp);
     }
   }
   return synth_chosen_sp;

@zwuis

zwuis commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

@zwuis zwuis added this to the LLVM 23.x Release milestone Aug 14, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in LLVM Release Status Aug 14, 2026
@dyung dyung moved this from Needs Triage to Needs Review in LLVM Release Status Aug 14, 2026
@jimingham

Copy link
Copy Markdown
Contributor Author

@dyung

dyung commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

@JDevlieghere and @adrian-prantl, could one of you review whether this change looks like something we should include on the 23.x release branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

3 participants