This is an archive of the discontinued LLVM Phabricator instance.

[llvm][utils] Fix SmallVector formatter when type is a pointer
ClosedPublic

Authored by Michael137 on Aug 15 2023, 3:45 AM.

Details

Summary

Previously types such as SmallVector<clang::Attr, 4> * would
trigger the assertion inside the SmallVector formatter:

assert self.type_size != 0

This happens because the_type.GetTemplateArgumentType(0) returns
None (since the_type is a pointer to the SmallVector).

This patch dereferences the_type if it's a pointer type. We do this
for references already.

Diff Detail

Event Timeline

Michael137 created this revision.Aug 15 2023, 3:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2023, 3:45 AM
Michael137 requested review of this revision.Aug 15 2023, 3:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2023, 3:45 AM
  • Remove drive-by change
kastiglione accepted this revision.Aug 15 2023, 10:16 AM
This revision is now accepted and ready to land.Aug 15 2023, 10:16 AM
  • Reword commit message
Michael137 retitled this revision from [llvm][utils] Support SmallVector with pointer-type template parameter to [llvm][utils] Fix SmallVector formatter when type is a pointer.Aug 15 2023, 3:09 PM
Michael137 edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Aug 15 2023, 3:10 PM
This revision was automatically updated to reflect the committed changes.

Hmm - it seems weird that the formatter for SmallVector would be involved directly in the formatting of SmallVector*? Could we fix that, so the SmallVector formatter is only used for SmallVector objects, not pointers? (if lldb wants to automatically dereference pointers and print the result - that's a generic feature in lldb that the SmallVector pretty printer wouldn't need to know about?)

(like what does lldb do with int*? Does it print the int (if any) that's pointed to?)

Could we fix that, so the SmallVector formatter is only used for SmallVector objects, not pointers?

type synthetic add has:

-p ( --skip-pointers )
     Don't use this format for pointers-to-type objects.

Could we fix that, so the SmallVector formatter is only used for SmallVector objects, not pointers?

type synthetic add has:

-p ( --skip-pointers )
     Don't use this format for pointers-to-type objects.

Hmm, that seems like an awkward way for lldb to expose this functionality. Judging by the examples here: https://lldb.llvm.org/use/variable.html if you -p, then lldb will still print the contents of what a pointer points to, but using innate printing, instead of teh pretty printer? (the example with a pretty printer for int with -p - if you print out a pointer, you also get the builtin int printing for the thing the pointer points to, but then if you dereference, you get the custom pretty printing) but then if you don't use -p your pretty printer has to handle being passed a pointer? (what about a pointer to pointer? Is it just one level of indirection that's special cased)

Ugh :/

Thanks for listening/pointing me to the docs at least - guess this patch is the right way to go, given lldb's features. Not sure how to make sense of the feature, though.