<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - CFG shows temporary destructors in wrong order"
   href="https://bugs.llvm.org/show_bug.cgi?id=46462">46462</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>CFG shows temporary destructors in wrong order
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>liblit@acm.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23651" name="attach_23651" title="source file demonstrating the problem">attachment 23651</a> <a href="attachment.cgi?id=23651&action=edit" title="source file demonstrating the problem">[details]</a></span>
source file demonstrating the problem

Temporaries are destroyed in reverse order of the completion of their
construction.  In a comma expression with temporaries of type Alpha and Beta...

    Alpha(), Beta();

...the Alpha temporary is constructed first and so should be destructed last. 
However, a CFG dumped for this code shows the destructors running in the wrong
order:

    [B1]
      1: Alpha() (CXXConstructExpr, [B1.2], struct Alpha)
      2: [B1.1] (BindTemporary)
      3: Beta() (CXXConstructExpr, [B1.4], struct Beta)
      4: [B1.3] (BindTemporary)
      5: ... , [B1.4]
      6: ~Alpha() (Temporary object destructor)
      7: ~Beta() (Temporary object destructor)

Notice that ~Alpha() in statement 6 *precedes* ~Beta() in statement 7.

Bizarrely, by the time we reach bitcode or a runnable executable, the order is
correct.  The actual generated code runs ~Beta() before ~Alpha() as it should. 
But the CFG does not reflect this order for some reason.

Complete source file suitable for seeing the problem:

    struct Alpha {
      Alpha();
      ~Alpha();
    };

    struct Beta {
      Beta();
      ~Beta();
    };

    void test() {
      Alpha(), Beta();
    }

Save this as "test.cc", then dump the CFG by running "clang++ -fsyntax-only
-Xclang -analyze -Xclang -analyzer-checker=debug.DumpCFG test.cc".</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>