<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 - early-cse and early-cse-memssa crash: Assertion `I->getParent()->getParent() == Q.CxtI->getParent()->getParent() && "Got assumption for the wrong function!"' failed."
   href="https://bugs.llvm.org/show_bug.cgi?id=43422">43422</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>early-cse and early-cse-memssa crash: Assertion `I->getParent()->getParent() == Q.CxtI->getParent()->getParent() && "Got assumption for the wrong function!"' failed.
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>cszide@163.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22550" name="attach_22550" title=".bc file of the source code">attachment 22550</a> <a href="attachment.cgi?id=22550&action=edit" title=".bc file of the source code">[details]</a></span>
.bc file of the source code

$clang -v
clang version 10.0.0 (trunk 372364)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

$clang -O3 -c -emit-llvm -femit-all-decls -mllvm -disable-llvm-optzns small.c


$opt -loop-versioning-licm -lowerswitch -mem2reg -inline -simplifycfg
-functionattrs -licm -loop-unroll -hotcoldsplit -early-cse  small.bc -o
small-opt.bc
opt:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/lib/Analysis/ValueTracking.cpp:595:
void computeKnownBitsFromAssume(const llvm::Value*, llvm::KnownBits&, unsigned
int, const {anonymous}::Query&): Assertion `I->getParent()->getParent() ==
Q.CxtI->getParent()->getParent() && "Got assumption for the wrong function!"'
failed.
Stack dump:
0.      Program arguments:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt
-loop-versioning-licm -lowerswitch -mem2reg -inline -simplifycfg -functionattrs
-licm -loop-unroll -hotcoldsplit -early-cse small.bc -o small-opt.bc 
1.      Running pass 'Function Pass Manager' on module 'small.bc'.
2.      Running pass 'Early CSE' on function '@main'
 #0 0x000055bd4a20ddca llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x277adca)
 #1 0x000055bd4a20baa4 llvm::sys::RunSignalHandlers()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x2778aa4)
 #2 0x000055bd4a20bbe2 SignalHandler(int)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x2778be2)
 #3 0x00007f90dc390890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
 #4 0x00007f90db042e97 raise
/build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007f90db044801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00007f90db03439a __assert_fail_base
/build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
 #7 0x00007f90db034412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
 #8 0x000055bd49601d8e computeKnownBitsFromAssume(llvm::Value const*,
llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b6ed8e)
 #9 0x000055bd496023d8 computeKnownBits(llvm::Value const*, llvm::KnownBits&,
unsigned int, (anonymous namespace)::Query const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b6f3d8)
#10 0x000055bd49605b7a computeKnownBits(llvm::Value const*, unsigned int,
(anonymous namespace)::Query const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b72b7a)
#11 0x000055bd49605c34 llvm::computeKnownBits(llvm::Value const*,
llvm::DataLayout const&, unsigned int, llvm::AssumptionCache*,
llvm::Instruction const*, llvm::DominatorTree const*,
llvm::OptimizationRemarkEmitter*, bool)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b72c34)
#12 0x000055bd4948d969 llvm::SimplifyInstruction(llvm::Instruction*,
llvm::SimplifyQuery const&, llvm::OptimizationRemarkEmitter*)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x19fa969)
#13 0x000055bd49f5c43e (anonymous namespace)::EarlyCSE::run()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x24c943e)
#14 0x000055bd49f5f37e (anonymous
namespace)::EarlyCSELegacyCommonPass<false>::runOnFunction(llvm::Function&)
(.part.648)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x24cc37e)
#15 0x000055bd49b4d2e9 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x20ba2e9)
#16 0x000055bd49b4d3e1 llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x20ba3e1)
#17 0x000055bd49b4c541 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x20b9541)
#18 0x000055bd48320aef main
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x88daef)
#19 0x00007f90db025b97 __libc_start_main
/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0
#20 0x000055bd483987ca _start
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x9057ca)
Aborted (core dumped)

$opt -loop-versioning-licm -lowerswitch -mem2reg -inline -simplifycfg
-functionattrs -licm -loop-unroll -hotcoldsplit -early-cse-memssa  small.bc -o
small-opt.bc
opt:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/lib/Analysis/ValueTracking.cpp:595:
void computeKnownBitsFromAssume(const llvm::Value*, llvm::KnownBits&, unsigned
int, const {anonymous}::Query&): Assertion `I->getParent()->getParent() ==
Q.CxtI->getParent()->getParent() && "Got assumption for the wrong function!"'
failed.
Stack dump:
0.      Program arguments:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt
-loop-versioning-licm -lowerswitch -mem2reg -inline -simplifycfg -functionattrs
-licm -loop-unroll -hotcoldsplit -early-cse-memssa small.bc -o small-opt.bc 
1.      Running pass 'Function Pass Manager' on module 'small.bc'.
2.      Running pass 'Early CSE w/ MemorySSA' on function '@main'
 #0 0x00005605b148ddca llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x277adca)
 #1 0x00005605b148baa4 llvm::sys::RunSignalHandlers()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x2778aa4)
 #2 0x00005605b148bbe2 SignalHandler(int)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x2778be2)
 #3 0x00007fb3b3d69890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
 #4 0x00007fb3b2a1be97 raise
/build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007fb3b2a1d801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00007fb3b2a0d39a __assert_fail_base
/build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
 #7 0x00007fb3b2a0d412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
 #8 0x00005605b0881d8e computeKnownBitsFromAssume(llvm::Value const*,
llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b6ed8e)
 #9 0x00005605b08823d8 computeKnownBits(llvm::Value const*, llvm::KnownBits&,
unsigned int, (anonymous namespace)::Query const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b6f3d8)
#10 0x00005605b0885b7a computeKnownBits(llvm::Value const*, unsigned int,
(anonymous namespace)::Query const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b72b7a)
#11 0x00005605b0885c34 llvm::computeKnownBits(llvm::Value const*,
llvm::DataLayout const&, unsigned int, llvm::AssumptionCache*,
llvm::Instruction const*, llvm::DominatorTree const*,
llvm::OptimizationRemarkEmitter*, bool)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b72c34)
#12 0x00005605b070d969 llvm::SimplifyInstruction(llvm::Instruction*,
llvm::SimplifyQuery const&, llvm::OptimizationRemarkEmitter*)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x19fa969)
#13 0x00005605b11dc43e (anonymous namespace)::EarlyCSE::run()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x24c943e)
#14 0x00005605b11dfa8b (anonymous
namespace)::EarlyCSELegacyCommonPass<true>::runOnFunction(llvm::Function&)
(.part.649)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x24cca8b)
#15 0x00005605b0dcd2e9 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x20ba2e9)
#16 0x00005605b0dcd3e1 llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x20ba3e1)
#17 0x00005605b0dcc541 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x20b9541)
#18 0x00005605af5a0aef main
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x88daef)
#19 0x00007fb3b29feb97 __libc_start_main
/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0
#20 0x00005605af6187ca _start
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x9057ca)
Aborted (core dumped)

By using bugpoint, the optimization sequence can be further reduced to
"-loop-unroll -hotcoldsplit -early-cse"

$opt bugpoint-reduced-simplified.bc -loop-unroll -hotcoldsplit -early-cse
WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.

opt:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/lib/Analysis/ValueTracking.cpp:595:
void computeKnownBitsFromAssume(const llvm::Value*, llvm::KnownBits&, unsigned
int, const {anonymous}::Query&): Assertion `I->getParent()->getParent() ==
Q.CxtI->getParent()->getParent() && "Got assumption for the wrong function!"'
failed.
Stack dump:
0.      Program arguments:
/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt
bugpoint-reduced-simplified.bc -loop-unroll -hotcoldsplit -early-cse 
1.      Running pass 'Function Pass Manager' on module
'bugpoint-reduced-simplified.bc'.
2.      Running pass 'Early CSE' on function '@main'
 #0 0x000055d2e6b79dca llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x277adca)
 #1 0x000055d2e6b77aa4 llvm::sys::RunSignalHandlers()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x2778aa4)
 #2 0x000055d2e6b77be2 SignalHandler(int)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x2778be2)
 #3 0x00007fc0cd0b2890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
 #4 0x00007fc0cbd64e97 raise
/build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007fc0cbd66801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00007fc0cbd5639a __assert_fail_base
/build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
 #7 0x00007fc0cbd56412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
 #8 0x000055d2e5f6dd8e computeKnownBitsFromAssume(llvm::Value const*,
llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b6ed8e)
 #9 0x000055d2e5f6e3d8 computeKnownBits(llvm::Value const*, llvm::KnownBits&,
unsigned int, (anonymous namespace)::Query const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b6f3d8)
#10 0x000055d2e5f71b7a computeKnownBits(llvm::Value const*, unsigned int,
(anonymous namespace)::Query const&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b72b7a)
#11 0x000055d2e5f71c34 llvm::computeKnownBits(llvm::Value const*,
llvm::DataLayout const&, unsigned int, llvm::AssumptionCache*,
llvm::Instruction const*, llvm::DominatorTree const*,
llvm::OptimizationRemarkEmitter*, bool)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x1b72c34)
#12 0x000055d2e5df9969 llvm::SimplifyInstruction(llvm::Instruction*,
llvm::SimplifyQuery const&, llvm::OptimizationRemarkEmitter*)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x19fa969)
#13 0x000055d2e68c843e (anonymous namespace)::EarlyCSE::run()
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x24c943e)
#14 0x000055d2e68cb37e (anonymous
namespace)::EarlyCSELegacyCommonPass<false>::runOnFunction(llvm::Function&)
(.part.648)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x24cc37e)
#15 0x000055d2e64b92e9 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x20ba2e9)
#16 0x000055d2e64b93e1 llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x20ba3e1)
#17 0x000055d2e64b8541 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x20b9541)
#18 0x000055d2e4c8caef main
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x88daef)
#19 0x00007fc0cbd47b97 __libc_start_main
/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0
#20 0x000055d2e4d047ca _start
(/home/jack-zhou/Documents/llvm/llvm_truck/llvm2/build10/bin/opt+0x9057ca)
Aborted (core dumped)

----------------------------------------------------------
struct a {
  int b;
};
int c, d, e;
short(f)();
static int *g(struct a h) {
j : {
  int i;
  if (0 == h.b) {
    int k[6];
    for (; e;) {
      h.b;
      goto j;
    }
    for (;; c = f(c, 8)) {
      char i = 0;
      for (; i; i++)
        ;
      if (k[5])
        continue;
    }
  }
}
  return &d;
}
void main() {
  struct a l = {10};
  g(l);
}</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>