<div dir="ltr">I don't think PointerUnion works with std::unique_ptr. I think you'll need to use PointerUnion<Record *, ForeachLoop *, Record::AssertionTuple *> and call the correct delete from the RecordsEntry destructor based on which type is active.<br><br>~Craig<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 15, 2021 at 11:48 AM Paul C. Anagnostopoulos <<a href="mailto:paul@windfall-software.com" target="_blank">paul@windfall-software.com</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">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>On 4/15/2021 1:47 PM, Craig Topper
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      <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">~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" target="_blank">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>
  </div>

</blockquote></div>