<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - bugpoint SEGVs because Module destructor is called multiple times"
   href="https://llvm.org/bugs/show_bug.cgi?id=24853">24853</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>bugpoint SEGVs because Module destructor is called multiple times
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>bugpoint
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>anton@samba.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14892" name="attach_14892" title="Test case">attachment 14892</a> <a href="attachment.cgi?id=14892&action=edit" title="Test case">[details]</a></span>
Test case

I see a SEGV in bugpoint on ppc64le Linux when running:

# bugpoint -O2 -llc-safe testcase.bc

Looks like we are calling the Module destructor multiple times:

Breakpoint 3, 0x000000001052f2c8 in llvm::Module::~Module (this=0x10c4b540,
__in_chrg=<optimised out>)
    at /home/anton/llvm/lib/IR/Module.cpp:66
66    Module::~Module() {
#0  0x000000001052f2c8 in llvm::Module::~Module (this=0x10c4b540,
__in_chrg=<optimised out>)
    at /home/anton/llvm/lib/IR/Module.cpp:66
#1  0x0000000010120f7c in std::default_delete<llvm::Module>::operator()
(this=<optimised out>, __ptr=0x10c4b540)
    at /usr/include/c++/5/bits/unique_ptr.h:76
#2  std::unique_ptr<llvm::Module, std::default_delete<llvm::Module>
<span class="quote">>::~unique_ptr (this=0x3fffffffe570, </span >
    __in_chrg=<optimised out>) at /usr/include/c++/5/bits/unique_ptr.h:236
#3  TestOptimizer (BD=..., Test=<optimised out>, Safe=<optimised out>,
Error=...)
    at /home/anton/llvm/tools/bugpoint/Miscompilation.cpp:712
#4  0x0000000010124564 in (anonymous
namespace)::ReduceMiscompilingFunctions::TestFuncs (Funcs=..., Error=..., 
    this=0x3fffffffea68, this=0x3fffffffea68) at
/home/anton/llvm/tools/bugpoint/Miscompilation.cpp:278
#5  0x0000000010125894 in (anonymous
namespace)::ReduceMiscompilingFunctions::doTest (Error=..., Suffix=...,
Prefix=..., 
    this=0x3fffffffea68) at
/home/anton/llvm/tools/bugpoint/Miscompilation.cpp:197
#6  llvm::ListReducer<llvm::Function*>::reduceList (this=0x3fffffffea68,
TheList=..., Error=...)
    at /home/anton/llvm/tools/bugpoint/ListReducer.h:55
#7  0x0000000010128ac4 in DebugAMiscompilation (BD=..., 
    TestFn=0x10120d10 <TestOptimizer(llvm::BugDriver&, llvm::Module*,
llvm::Module*, std::__cxx11::string&)>, Error=...)
    at /home/anton/llvm/tools/bugpoint/Miscompilation.cpp:638
#8  0x000000001012b520 in llvm::BugDriver::debugMiscompilation
(this=0x3ffffffff020, Error=0x3fffffffedb8)
    at /home/anton/llvm/tools/bugpoint/Miscompilation.cpp:749
#9  0x00000000101083c4 in llvm::BugDriver::run (this=0x3ffffffff020,
ErrMsg=...)
    at /home/anton/llvm/tools/bugpoint/BugDriver.cpp:212
#10 0x00000000100f155c in main (argc=<optimised out>, argv=<optimised out>)
    at /home/anton/llvm/tools/bugpoint/bugpoint.cpp:204


Breakpoint 3, 0x000000001052f2c8 in llvm::Module::~Module (this=0x10c4b540,
__in_chrg=<optimised out>)
    at /home/anton/llvm/lib/IR/Module.cpp:66
66    Module::~Module() {
#0  0x000000001052f2c8 in llvm::Module::~Module (this=0x10c4b540,
__in_chrg=<optimised out>)
    at /home/anton/llvm/lib/IR/Module.cpp:66
#1  0x000000001012458c in (anonymous
namespace)::ReduceMiscompilingFunctions::TestFuncs (Funcs=..., Error=..., 
    this=0x3fffffffea68, this=0x3fffffffea68) at
/home/anton/llvm/tools/bugpoint/Miscompilation.cpp:280
#2  0x0000000010125894 in (anonymous
namespace)::ReduceMiscompilingFunctions::doTest (Error=..., Suffix=...,
Prefix=..., 
    this=0x3fffffffea68) at
/home/anton/llvm/tools/bugpoint/Miscompilation.cpp:197
#3  llvm::ListReducer<llvm::Function*>::reduceList (this=0x3fffffffea68,
TheList=..., Error=...)
    at /home/anton/llvm/tools/bugpoint/ListReducer.h:55
#4  0x0000000010128ac4 in DebugAMiscompilation (BD=..., 
    TestFn=0x10120d10 <TestOptimizer(llvm::BugDriver&, llvm::Module*,
llvm::Module*, std::__cxx11::string&)>, Error=...)
    at /home/anton/llvm/tools/bugpoint/Miscompilation.cpp:638
#5  0x000000001012b520 in llvm::BugDriver::debugMiscompilation
(this=0x3ffffffff020, Error=0x3fffffffedb8)
    at /home/anton/llvm/tools/bugpoint/Miscompilation.cpp:749
#6  0x00000000101083c4 in llvm::BugDriver::run (this=0x3ffffffff020,
ErrMsg=...)
    at /home/anton/llvm/tools/bugpoint/BugDriver.cpp:212
#7  0x00000000100f155c in main (argc=<optimised out>, argv=<optimised out>)
    at /home/anton/llvm/tools/bugpoint/bugpoint.cpp:204</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>