<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 --- - SimplifyCFG/SimplifyCleanupReturn: Use still stuck around after Def is destroyed: cleanupret from %cleanuppad2"
   href="https://llvm.org/bugs/show_bug.cgi?id=28005">28005</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SimplifyCFG/SimplifyCleanupReturn: Use still stuck around after Def is destroyed:  cleanupret from %cleanuppad2
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>arielb1@mail.tau.ac.il
          </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=16474" name="attach_16474" title="code that asserts when touched">attachment 16474</a> <a href="attachment.cgi?id=16474&action=edit" title="code that asserts when touched">[details]</a></span>
code that asserts when touched

Running the SimplifyCFG pass on the above IR causes an LLVM assertion to be
triggered.

I am trying to compile code that works with SEH exceptions on Windows. I am
cross-compiling from my Linux but it is broken in a similar way on Windows.

Expected Result:
Optimization Succeeds

Actual Result:
$ opt -version
LLVM (<a href="http://llvm.org/">http://llvm.org/</a>):
  LLVM version 3.8.0
  Optimized build with assertions.
  Built May 21 2016 (13:09:50).
  Default target: x86_64-unknown-linux-gnu
  Host CPU: broadwell
$ opt simplify-cfg-assert.ll -simplifycfg -S
While deleting: token %cleanuppad2
Use still stuck around after Def is destroyed:  cleanupret from %cleanuppad2
unwind label %bb18
Use still stuck around after Def is destroyed:  cleanupret from %cleanuppad2
unwind label %bb18
opt: /opt/llvm/lib/IR/Value.cpp:82: virtual llvm::Value::~Value(): Assertion
`use_empty() && "Uses remain when a value is destroyed!"' failed.
0  opt             0x0000000001826fe5
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  opt             0x0000000001824956 llvm::sys::RunSignalHandlers() + 54
2  opt             0x0000000001824b6a
3  libpthread.so.0 0x00007f91f3127d30
4  libc.so.6       0x00007f91f230e478 gsignal + 56
5  libc.so.6       0x00007f91f230f8fa abort + 362
6  libc.so.6       0x00007f91f23073a7
7  libc.so.6       0x00007f91f2307452
8  opt             0x00000000017c33fb
9  opt             0x00000000015caaa7
10 opt             0x0000000001659b2c llvm::BasicBlock::~BasicBlock() + 140
11 opt             0x0000000001659dbb llvm::BasicBlock::eraseFromParent() + 139
12 opt             0x00000000005c1594
13 opt             0x00000000013c1d76
14 opt             0x00000000013c2d31 llvm::SimplifyCFG(llvm::BasicBlock*,
llvm::TargetTransformInfo const&, unsigned int, llvm::AssumptionCache*) + 65
15 opt             0x00000000013c0f02
16 opt             0x00000000013c2d31 llvm::SimplifyCFG(llvm::BasicBlock*,
llvm::TargetTransformInfo const&, unsigned int, llvm::AssumptionCache*) + 65
17 opt             0x00000000005c4e2c
18 opt             0x00000000013c1dcd
19 opt             0x00000000013c2d31 llvm::SimplifyCFG(llvm::BasicBlock*,
llvm::TargetTransformInfo const&, unsigned int, llvm::AssumptionCache*) + 65
20 opt             0x00000000011d6ff9
21 opt             0x0000000001796ca3
llvm::FPPassManager::runOnFunction(llvm::Function&) + 643
22 opt             0x0000000001796db9
llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 137
23 opt             0x0000000001796f04
llvm::legacy::FunctionPassManager::run(llvm::Function&) + 36
24 opt             0x00000000005d5d09 main + 7321
25 libc.so.6       0x00007f91f22fb610 __libc_start_main + 240
26 opt             0x0000000000615129 _start + 41
Stack dump:
0.      Program arguments: opt simplify-cfg-assert.ll -simplifycfg -S -O3 
1.      Running pass 'Simplify the CFG' on function
'@_ZN4core4iter8iterator8Iterator4fold17h0471ccca27326883E'
Aborted

Backtrace on less-minified code:
#0  0x00007faab0f6f478 in __GI_raise (sig=sig@entry=6) at
../sysdeps/unix/sysv/linux/raise.c:55
#1  0x00007faab0f708fa in __GI_abort () at abort.c:89
#2  0x00007faab0f683a7 in __assert_fail_base (fmt=<optimized out>, 
    assertion=assertion@entry=0x7faaabbf0628 "use_empty() && \"Uses remain when
a value is destroyed!\"", 
    file=file@entry=0x7faaabbefe40 "llvm/lib/IR/Value.cpp", line=line@entry=82, 
    function=function@entry=0x7faaabbf29b0
<llvm::Value::~Value()::__PRETTY_FUNCTION__> "virtual llvm::Value::~Value()")
at assert.c:92
#3  0x00007faab0f68452 in __GI___assert_fail (assertion=0x7faaabbf0628
"use_empty() && \"Uses remain when a value is destroyed!\"", 
    file=0x7faaabbefe40 "llvm/lib/IR/Value.cpp", line=82, 
    function=0x7faaabbf29b0 <llvm::Value::~Value()::__PRETTY_FUNCTION__>
"virtual llvm::Value::~Value()") at assert.c:101
#4  0x00007faaaaf18f6b in llvm::Value::~Value() ()
   from librustc_llvm-fe3cdf61.so
#5  0x00007faaa9c03237 in llvm::FuncletPadInst::~FuncletPadInst
(this=0x7faaa3ef7af8, __in_chrg=<optimized out>)
    at llvm//include/llvm/IR/InstrTypes.h:1117
#6  llvm::CleanupPadInst::~CleanupPadInst (this=0x7faaa3ef7af8,
__in_chrg=<optimized out>)
    at llvm//include/llvm/IR/Instructions.h:4030
#7  llvm::CleanupPadInst::~CleanupPadInst (this=0x7faaa3ef7af8,
__in_chrg=<optimized out>)
    at llvm//include/llvm/IR/Instructions.h:4030
#8  0x00007faaaada3e4c in llvm::BasicBlock::~BasicBlock() ()
   from librustc_llvm-fe3cdf61.so
#9  0x00007faaaada40db in llvm::BasicBlock::eraseFromParent() ()
   from librustc_llvm-fe3cdf61.so
#10 0x00007faaa9bad62e in (anonymous
namespace)::SimplifyCFGOpt::SimplifyCleanupReturn(llvm::CleanupReturnInst*)
[clone .isra.636] [clone .constprop.703] ()
   from librustc_llvm-fe3cdf61.so
#11 0x00007faaaaacb226 in (anonymous
namespace)::SimplifyCFGOpt::run(llvm::BasicBlock*) [clone .constprop.691] ()
   from librustc_llvm-fe3cdf61.so
#12 0x00007faaaaacc1e1 in llvm::SimplifyCFG(llvm::BasicBlock*,
llvm::TargetTransformInfo const&, unsigned int, llvm::AssumptionCache*) ()
   from librustc_llvm-fe3cdf61.so
#13 0x00007faaaaaca3b2 in (anonymous
namespace)::SimplifyCFGOpt::run(llvm::BasicBlock*) [clone .constprop.691] ()
   from librustc_llvm-fe3cdf61.so
#14 0x00007faaaaacc1e1 in llvm::SimplifyCFG(llvm::BasicBlock*,
llvm::TargetTransformInfo const&, unsigned int, llvm::AssumptionCache*) ()
   from librustc_llvm-fe3cdf61.so
#15 0x00007faaa9bb0ec6 in (anonymous
namespace)::SimplifyCFGOpt::SimplifySwitch(llvm::SwitchInst*,
llvm::IRBuilder<true, llvm::ConstantFolder,
llvm::IRBuilderDefaultInserter<true> >&) [clone .constprop.693] () from
librustc_llvm-fe3cdf61.so
#16 0x00007faaaaacb27d in (anonymous
namespace)::SimplifyCFGOpt::run(llvm::BasicBlock*) [clone .constprop.691] ()
   from librustc_llvm-fe3cdf61.so
#17 0x00007faaaaacc1e1 in llvm::SimplifyCFG(llvm::BasicBlock*,
llvm::TargetTransformInfo const&, unsigned int, llvm::AssumptionCache*) ()
   from librustc_llvm-fe3cdf61.so
#18 0x00007faaaa916ed9 in simplifyFunctionCFG(llvm::Function&,
llvm::TargetTransformInfo const&, llvm::AssumptionCache*, int) [clone
.constprop.113] ()
   from librustc_llvm-fe3cdf61.so
#19 0x00007faaaaeec4d3 in llvm::FPPassManager::runOnFunction(llvm::Function&)
()
   from librustc_llvm-fe3cdf61.so
#20 0x00007faaaaeec5e9 in
llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) ()
   from librustc_llvm-fe3cdf61.so
#21 0x00007faaaaeec734 in
llvm::legacy::FunctionPassManager::run(llvm::Function&) ()
   from librustc_llvm-fe3cdf61.so</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>