[llvm-bugs] [Bug 46462] New: CFG shows temporary destructors in wrong order

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 25 19:01:11 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46462

            Bug ID: 46462
           Summary: CFG shows temporary destructors in wrong order
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: liblit at acm.org
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 23651
  --> https://bugs.llvm.org/attachment.cgi?id=23651&action=edit
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".

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200626/37402afe/attachment.html>


More information about the llvm-bugs mailing list