<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><font face="Helvetica, Arial, sans-serif">C++ seems willing to
compile a PointerUnion of three unique_ptr's. Does that make
sense, or does it have to be unique_ptr * ?</font></p>
<p><font face="Helvetica, Arial, sans-serif">There is only one use
of unique_ptr with PointerUnion in the system, and it uses
unique_ptr *.</font><br>
</p>
<div class="moz-cite-prefix">On 4/15/2021 1:47 PM, Craig Topper
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAF7ks-MOJ+u-w1thykaHpG-h33PeRXcQJ-O98rLg_G-3a9FKzA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">Depending on the alignment requirement of the 3
types involved, you might be able to use PointerUnion to store
the discrimination enum in the lower 2 bits of the pointer.
<div><br clear="all">
<div>
<div dir="ltr" class="gmail_signature"
data-smartmail="gmail_signature">~Craig</div>
</div>
<br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Thu, Apr 15, 2021 at 10:33
AM Paul C. Anagnostopoulos via llvm-dev <<a
href="mailto:llvm-dev@lists.llvm.org" moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p><font face="Helvetica, Arial, sans-serif">In TableGen,
there is the following struct. In any given instance,
only one of the pointers is filled in.</font></p>
<blockquote>
<p><tt> struct RecordsEntry {<br>
std::unique_ptr<Record> Rec;<br>
std::unique_ptr<ForeachLoop> Loop;<br>
std::unique_ptr<Record::AssertionTuple>
Assertion;<br>
<br>
void dump() const;<br>
<br>
RecordsEntry() {}<br>
RecordsEntry(std::unique_ptr<Record> Rec) :
Rec(std::move(Rec)) {}<br>
RecordsEntry(std::unique_ptr<ForeachLoop>
Loop)<br>
: Loop(std::move(Loop)) {}<br>
RecordsEntry(std::unique_ptr<Record::AssertionTuple>
Assertion)<br>
: Assertion(std::move(Assertion)) {}<br>
};<br>
</tt></p>
</blockquote>
<p>It has been suggested that the three pointers be made a
union. This requires a discrimination enum. I believe that
would reduce the struct from 24 to 12 bytes, and I think
it requires a custom destructor.</p>
<p>What do people think about this? If I should do it, could
someone help me with the changes?<br>
</p>
</div>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>