[PATCH] D65189: [MC] Support returning a structured rich disassembly output
Seiya Nuta via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 30 05:28:07 PDT 2019
seiya marked an inline comment as done.
seiya added inline comments.
================
Comment at: llvm/include/llvm/MC/MCInstPrinter.h:63
+ // InnerSpans contains one MarkupSpan which represents `<reg:%rip>`.
+ std::unique_ptr<std::vector<MarkupSpan>> InnerSpans;
+
----------------
seiya wrote:
> jhenderson wrote:
> > Why is this a unique_ptr? Can't you just have a std::vector here directly?
> I think it should be a unique_ptr to prevent dangling pointer reference here:
>
> ```lang=cpp
> auto *InnerSpans =
> const_cast<std::vector<MarkupSpan> *>(Span.InnerSpans.get());
> M.State.Spans.back()->push_back(std::move(Span));
> // Span is now moved to the "M.State.Spans.back()" but InnerSpans is still valid
> // since Span.InnerSpans is an unique_ptr.
> M.State.Spans.push_back(InnerSpans);
> ```
>
>
Ah, I realized we don't need unique_ptr here. We can rewrite the code above as:
```lang=cpp
M.State.Spans.back()->push_back(std::move(Span));
M.State.Spans.push_back(&M.State.Spans.back()->back().InnerSpans);
```
I'll update the patch later.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65189/new/
https://reviews.llvm.org/D65189
More information about the llvm-commits
mailing list