This is an archive of the discontinued LLVM Phabricator instance.

[Visualizers] Fix SmallVector<T> visualizer for T inside an anonymous namespace. Use `value_type` instead of `$T1`.
ClosedPublic

Authored by curdeius on Jan 24 2022, 11:58 PM.

Diff Detail

Event Timeline

curdeius requested review of this revision.Jan 24 2022, 11:58 PM
curdeius created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 24 2022, 11:58 PM
RKSimon added inline comments.Jan 25 2022, 2:13 AM
llvm/utils/LLVMVisualizers/llvm.natvis
203

We have other users of $T1* - such as for llvm::Optional<>- do they still work?

I've just tried this and current trunk seems to work fine with VS2022 - please do you have a specific repro?

I hit this problem when working on clang-format.
In particular AnnotatingParser has SmallVector<Context, 8> Contexts; that did not work.
I'm using MSVC 2022 (14.31.31103, 17.1.0 preview 3.0, but that problem is there for a few weeks at least).

Using $T1 I get:

Using value_type, I get:


and

Maybe I should file a bug to MSVC?

BTW, the visualizer for llvm::Optional doesn't look good either.
It should be something like this:

<Type Name="llvm::Optional&lt;*&gt;">
  <DisplayString Condition="!Storage.hasVal">None</DisplayString>
  <DisplayString Condition="Storage.hasVal">{Storage.value}</DisplayString>
  <Expand>
    <Item Name="[underlying]" Condition="Storage.hasVal">Storage.value</Item>
  </Expand>
</Type>

so use Storage.value instead of *(($T1 *)(unsigned char *)Storage.storage.buffer).
It was changed back in February 2019 in commit https://github.com/llvm/llvm-project/commit/fb9730575086b3c2ba38a1aabf3106b01339888b.
Should I create a patch for Opional visualizer?

Strangely enough, using $T1 and $T1 * in other contexts than AnnotatingParser::Contexts works ok.

Ah - that might be it - I was checking it with SmallVector<int> - non-POD might still break it.

A llvm::Optional<> fix would be appreciated - cheers.

Do you see any warning spam when you enable Natvis diagnostics in VisualStudio?
https://docs.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects

Oh, natvis diagnostics enabled shows an error:

Natvis: E:\src\llvm-project\llvm\utils\LLVMVisualizers\llvm.natvis(30,23): Error: identifier "clang::format::`anonymous namespace'" is undefined
    Error while evaluating '(clang::format::`anonymous namespace'::AnnotatingParser::Context*)BeginX' in the context of type 'FormatTests.exe!llvm::SmallVectorImpl<clang::format::`anonymous namespace'::AnnotatingParser::Context>'.

so the anonymous namespace is making things fail.
To my understanding, it's probably because $T1 works like a macro, so a textual replacement...

curdeius retitled this revision from [Visualizers] Fix SmallVector visualizer. Use `value_type` instead of `$T1`. to [Visualizers] Fix SmallVector<T> visualizer for T inside an anonymous namespace. Use `value_type` instead of `$T1`..Jan 25 2022, 3:10 AM
RKSimon accepted this revision.Jan 26 2022, 5:20 AM

LGTM - cheers

This revision is now accepted and ready to land.Jan 26 2022, 5:20 AM
This revision was landed with ongoing or failed builds.Jan 26 2022, 6:59 AM
This revision was automatically updated to reflect the committed changes.