<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 - clang crashes with "-mllvm -enable-newgvn": Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed"
   href="https://bugs.llvm.org/show_bug.cgi?id=33086">33086</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang crashes with "-mllvm -enable-newgvn": Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' 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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>helloqirun@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following code crashes the current trunk version at "-O2" and "-Os" only
with "-mllvm -enable-newgvn". 


$ clang-trunk --version
clang version 5.0.0 (trunk 303238)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin


$ clang-trunk -mllvm -enable-newgvn -O2 abc.c
abc.c:12:14: warning: relational comparison result unused [-Wunused-comparison]
    (g = *h) <= (c = a = c);
    ~~~~~~~~~^~~~~~~~~~~~~~
clang-5.0: /home/absozero/trunk/llvm/include/llvm/Support/Casting.h:247:
typename cast_retty<X, Y>::ret_type llvm::cast(Y &) [X =
llvm::GVNExpression::VariableExpression, Y = const
llvm::GVNExpression::Expression]: Assertion `isa<X>(Val) && "cast<Ty>()
argument of incompatible type!"' failed.
#0 0x0000000001ce3324 PrintStackTraceSignalHandler(void*)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x1ce3324)
#1 0x0000000001ce3656 SignalHandler(int)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x1ce3656)
#2 0x00007f6fea9aa330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#3 0x00007f6fe9527c37 gsignal
/build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#4 0x00007f6fe952b028 abort
/build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
#5 0x00007f6fe9520bf6 __assert_fail_base
/build/eglibc-oGUzwX/eglibc-2.19/assert/assert.c:92:0
#6 0x00007f6fe9520ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#7 0x0000000001be66d2 (/home/absozero/trunk/root-clang/bin/clang-5.0+0x1be66d2)
#8 0x0000000001bd14d8 (anonymous namespace)::NewGVN::runGVN()
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x1bd14d8)
#9 0x0000000001bcd885 NewGVNLegacyPass::runOnFunction(llvm::Function&)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x1bcd885)
#10 0x000000000187584f llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x187584f)
#11 0x00000000026e8006 (anonymous
namespace)::CGPassManager::runOnModule(llvm::Module&)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x26e8006)
#12 0x0000000001875fa5 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x1875fa5)
#13 0x0000000001e6e46b 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> >)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x1e6e46b)
#14 0x00000000025754d7
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x25754d7)
#15 0x00000000029d8ed6 clang::ParseAST(clang::Sema&, bool, bool)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x29d8ed6)
#16 0x0000000002247eb8 clang::FrontendAction::Execute()
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x2247eb8)
#17 0x00000000021fa2d1
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x21fa2d1)
#18 0x00000000022cb8cd
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x22cb8cd)
#19 0x000000000083e5dc cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/absozero/trunk/root-clang/bin/clang-5.0+0x83e5dc)
#20 0x000000000083c4a5 main
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x83c4a5)
#21 0x00007f6fe9512f45 __libc_start_main
/build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321:0
#22 0x00000000008395b9 _start
(/home/absozero/trunk/root-clang/bin/clang-5.0+0x8395b9)
Stack dump:
0.      Program arguments: /home/absozero/trunk/root-clang/bin/clang-5.0 -cc1
-triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name abc.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 -resource-dir
/home/absozero/trunk/root-clang/lib/clang/5.0.0 -internal-isystem
/usr/local/include -internal-isystem
/home/absozero/trunk/root-clang/lib/clang/5.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include -O2
-fdebug-compilation-dir /home/absozero/projects/reduction/crash -ferror-limit
19 -fmessage-length 172 -fobjc-runtime=gcc -fdiagnostics-show-option
-fcolor-diagnostics -vectorize-loops -vectorize-slp -mllvm -enable-newgvn -o
/tmp/abc-f54f1f.o -x c abc.c
1.      <eof> parser at end of file
2.      Per-module optimization passes
3.      Running pass 'CallGraph Pass Manager' on module 'abc.c'.
4.      Running pass 'Global Value Numbering' on function '@fn1'
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 303238)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/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/abc-31e55e.c
clang-5.0: note: diagnostic msg: /tmp/abc-31e55e.sh
clang-5.0: note: diagnostic msg:

********************


$ cat abc.c
char a;
long b, e;
short c, d;
void fn1() {
  if (d) {
    short f, g;
    for (; f <= 54; f += 1)
      for (; b;)
        ;
    short *h = &g;
  l1:
    (g = *h) <= (c = a = c);
    for (; g;)
      ;
  }
  for (; e;)
    goto l1;
}</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>