<html>
    <head>
      <base href="http://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 --- - SROA calls PromoteMemToReg on something it can't handle"
   href="http://llvm.org/bugs/show_bug.cgi?id=16867">16867</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SROA calls PromoteMemToReg on something it can't handle
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nlewycky@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>chandlerc@gmail.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase module:

target datalayout =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
target triple = "i386-unknown-linux-gnu"

%type = type { i8* }

define void @test() {
bb:
  %tmp = alloca i8*, align 4
  unreachable

bb51:
  %tmp52 = bitcast i8** %tmp to %type*
  %tmp53 = bitcast %type* %tmp52 to i8**
  %tmp54 = load i8** %tmp53, align 4
  unreachable
}

Triggers this crash:

$ opt -sroa c.ll
opt: /usr/local/google/home/nlewycky/llvm/include/llvm/Support/Casting.h:239:
typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X =
llvm::StoreInst, Y = llvm::Instruction, typename llvm::cast_retty<X,
Y*>::ret_type = llvm::StoreInst*]: Assertion `isa<X>(Val) && "cast<Ty>()
argument of incompatible type!"' failed.
0  opt             0x000000000199a05f llvm::sys::PrintStackTrace(_IO_FILE*) +
38
1  opt             0x000000000199a2e6
2  opt             0x0000000001999d2a
3  libpthread.so.0 0x00007f5afe5e4cb0
4  libc.so.6       0x00007f5afd60f425 gsignal + 53
5  libc.so.6       0x00007f5afd612b8b abort + 379
6  libc.so.6       0x00007f5afd6080ee
7  libc.so.6       0x00007f5afd608192
8  opt             0x00000000012bffd0 llvm::cast_retty<llvm::StoreInst,
llvm::Instruction*>::ret_type llvm::cast<llvm::StoreInst,
llvm::Instruction>(llvm::Instruction*) + 62
9  opt             0x0000000001568994
10 opt             0x0000000001568ea3
11 opt             0x000000000156b3a2
llvm::PromoteMemToReg(llvm::ArrayRef<llvm::AllocaInst*>, llvm::DominatorTree&,
llvm::DataLayout const*, llvm::AliasSetTracker*) + 154
12 opt             0x0000000001432369
13 opt             0x0000000001432c9e
14 opt             0x000000000191f6dc
llvm::FPPassManager::runOnFunction(llvm::Function&) + 390
15 opt             0x000000000191f8d7
llvm::FPPassManager::runOnModule(llvm::Module&) + 89
16 opt             0x000000000191fc4f
llvm::MPPassManager::runOnModule(llvm::Module&) + 573
17 opt             0x0000000001920264 llvm::PassManagerImpl::run(llvm::Module&)
+ 254
18 opt             0x0000000001920477 llvm::PassManager::run(llvm::Module&) +
39
19 opt             0x000000000095bf45 main + 5778
20 libc.so.6       0x00007f5afd5fa76d __libc_start_main + 237
21 opt             0x000000000094dd79
Stack dump:
0.      Program arguments: llvm/Debug+Asserts/bin/opt -sroa c.ll 
1.      Running pass 'Function Pass Manager' on module 'c.ll'.
2.      Running pass 'SROA' on function '@test'
Aborted (core dumped)

>From GDB:

#5  0x0000000001568994 in promoteSingleBlockAlloca (AI=0x29e2068, Info=..., 
    LBI=..., AST=0x0) at PromoteMemoryToRegister.cpp:564
564         StoreInst *SI = cast<StoreInst>(AI->use_back());
(gdb) call AI->use_empty()
$1 = false
(gdb) call AI->use_back() 
$2 = (llvm::Instruction *) 0x29e18b8
(gdb) call AI->use_back()->dump()
  %tmp52 = bitcast i8** %tmp to %type*</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>