<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 - a heisenbug: clang crashes on valid code at -O3 with "-mllvm -enable-newgvn": Assertion `isa<Instruction>(V) && "This should not be used for MemoryAccesses"' failed"
   href="https://bugs.llvm.org/show_bug.cgi?id=33194">33194</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>a heisenbug: clang crashes on valid code at -O3 with "-mllvm -enable-newgvn": Assertion `isa<Instruction>(V) && "This should not be used for MemoryAccesses"' failed
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>su@cs.ucdavis.edu
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>It was quite a challenge to get this one reduced due to its non-deterministic
behavior.  Perhaps it is due to memory corruption?  


$ clang -v
clang version 5.0.0 (trunk 304014)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-trunk/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.0.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.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.0.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
$ clang -O3 -mllvm -enable-newgvn -c -w small.c
clang-5.0:
/tmp/llvm-builder/llvm-source-trunk/lib/Transforms/Scalar/NewGVN.cpp:734:
unsigned int {anonymous}::NewGVN::InstrToDFSNum(const llvm::Value*) const:
Assertion `isa<Instruction>(V) && "This should not be used for MemoryAccesses"'
failed.
#0 0x00000000020ed34a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/local/clang-trunk/bin/clang-5.0+0x20ed34a)
#1 0x00000000020eb0ce llvm::sys::RunSignalHandlers()
(/usr/local/clang-trunk/bin/clang-5.0+0x20eb0ce)
#2 0x00000000020eb242 SignalHandler(int)
(/usr/local/clang-trunk/bin/clang-5.0+0x20eb242)
#3 0x00007f39493a1390 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#4 0x00007f3948114428 gsignal
/build/glibc-9tT8Do/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
#5 0x00007f394811602a abort /build/glibc-9tT8Do/glibc-2.23/stdlib/abort.c:91:0
#6 0x00007f394810cbd7 __assert_fail_base
/build/glibc-9tT8Do/glibc-2.23/assert/assert.c:92:0
#7 0x00007f394810cc82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
#8 0x0000000001fc7f78 (/usr/local/clang-trunk/bin/clang-5.0+0x1fc7f78)
#9 0x0000000001fdb143 (anonymous
namespace)::NewGVN::performCongruenceFinding(llvm::Instruction*,
llvm::GVNExpression::Expression const*)
(/usr/local/clang-trunk/bin/clang-5.0+0x1fdb143)
#10 0x0000000001fe4848 (anonymous
namespace)::NewGVN::iterateTouchedInstructions()
(/usr/local/clang-trunk/bin/clang-5.0+0x1fe4848)
#11 0x0000000001fe704a (anonymous namespace)::NewGVN::runGVN() [clone
.constprop.1276] (/usr/local/clang-trunk/bin/clang-5.0+0x1fe704a)
#12 0x0000000001fe8d27 NewGVNLegacyPass::runOnFunction(llvm::Function&) [clone
.part.1270] [clone .constprop.1274]
(/usr/local/clang-trunk/bin/clang-5.0+0x1fe8d27)
#13 0x0000000001c3cbc3 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/usr/local/clang-trunk/bin/clang-5.0+0x1c3cbc3)
#14 0x0000000002af41ee (anonymous
namespace)::CGPassManager::runOnModule(llvm::Module&)
(/usr/local/clang-trunk/bin/clang-5.0+0x2af41ee)
#15 0x0000000001c3c72d llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/usr/local/clang-trunk/bin/clang-5.0+0x1c3c72d)
#16 0x000000000229f309 clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout
const&, llvm::Module*, clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
(/usr/local/clang-trunk/bin/clang-5.0+0x229f309)
#17 0x0000000002983f19
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/usr/local/clang-trunk/bin/clang-5.0+0x2983f19)
#18 0x0000000002d47478 clang::ParseAST(clang::Sema&, bool, bool)
(/usr/local/clang-trunk/bin/clang-5.0+0x2d47478)
#19 0x00000000029832af clang::CodeGenAction::ExecuteAction()
(/usr/local/clang-trunk/bin/clang-5.0+0x29832af)
#20 0x0000000002641236 clang::FrontendAction::Execute()
(/usr/local/clang-trunk/bin/clang-5.0+0x2641236)
#21 0x0000000002612ff6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/usr/local/clang-trunk/bin/clang-5.0+0x2612ff6)
#22 0x00000000026cdd1a
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/usr/local/clang-trunk/bin/clang-5.0+0x26cdd1a)
#23 0x0000000000b64ac8 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/local/clang-trunk/bin/clang-5.0+0xb64ac8)
#24 0x0000000000af7683 main (/usr/local/clang-trunk/bin/clang-5.0+0xaf7683)
#25 0x00007f39480ff830 __libc_start_main
/build/glibc-9tT8Do/glibc-2.23/csu/../csu/libc-start.c:325:0
#26 0x0000000000b61179 _start (/usr/local/clang-trunk/bin/clang-5.0+0xb61179)
Stack dump:
0.      Program arguments: /usr/local/clang-trunk/bin/clang-5.0 -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name small.c
-mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64
-momit-leaf-frame-pointer -dwarf-column-info -debugger-tuning=gdb
-coverage-notes-file /home/su/small.gcno -resource-dir
/usr/local/clang-trunk/lib/clang/5.0.0 -internal-isystem /usr/local/include
-internal-isystem /usr/local/clang-trunk/lib/clang/5.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include -O3
-w -fdebug-compilation-dir /home/su -ferror-limit 19 -fmessage-length 116
-fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics
-vectorize-loops -vectorize-slp -mllvm -enable-newgvn -o small.o -x c small.c
1.      <eof> parser at end of file
2.      Per-module optimization passes
3.      Running pass 'CallGraph Pass Manager' on module 'small.c'.
4.      Running pass 'Global Value Numbering' on function '@fn2'
clang-5.0: error: unable to execute command: Aborted (core dumped)
clang-5.0: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 5.0.0 (trunk 304014)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-trunk/bin
clang-5.0: note: diagnostic msg: PLEASE submit a bug report to
<a href="http://llvm.org/bugs/">http://llvm.org/bugs/</a> and include the crash backtrace, preprocessed source, and
associated run script.
clang-5.0: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-5.0: note: diagnostic msg: /tmp/small-de32fe.c
clang-5.0: note: diagnostic msg: /tmp/small-de32fe.sh
clang-5.0: note: diagnostic msg:

********************
$


----------------------------------


int c, d, f, h, e, i, j;
volatile int k;

int fn1 ();

void fn2 ()

  int t = 5;
  while (c)
    { 
      for (; t; t++)
        for (; i < 4; i)
          ;
      int a = j;
      if (c < 1U)
        { 
          a = c;
          ~k / d;
        }
      c = a;
      int b = e | c, l;
      f = b % fn1 ();
    }
}</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>