<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 --- - Assertion `NumPendingSTs > SrcST && "Cannot copy from dead ST register"' failed."
   href="http://llvm.org/bugs/show_bug.cgi?id=19226">19226</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Assertion `NumPendingSTs > SrcST && "Cannot copy from dead ST register"' 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>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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>solo-llvm@goeswhere.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The "aranym" Debian package causes Clang to segfault:
<a href="http://clang.debian.net/logs/2014-01-14/aranym_0.9.15-1_unstable_clang.log">http://clang.debian.net/logs/2014-01-14/aranym_0.9.15-1_unstable_clang.log</a>

Minimised testcase:
# 1 "<built-in>" 1
# 1 "clangcrash.cpp" 1
int toint(int a, long double x) {
  if (a) {
    return (int)x;
  }
  volatile unsigned int cw;
  long double value;
  __asm__ __volatile__("frndint" : "=t"(value) : "0"(x));
  __asm__ __volatile__("fldcw %0" : : "m"(cw));
  return (int)value;
}

I'm pretty sure that's minimised, e.g. the if (a) { .. is definitely needed.

The original code names the series of asm instructions "fp_round_to_zero" and
has initialised cw appropriately, but still segfaults.

<a href="http://sourceforge.net/p/aranym/code/ci/master/tree/src/uae_cpu/fpu/mathlib.h">http://sourceforge.net/p/aranym/code/ci/master/tree/src/uae_cpu/fpu/mathlib.h</a>


$ clang++ clangcrash.cpp -O1
clang: /home/faux/code/llvm/lib/Target/X86/X86FloatingPoint.cpp:1364: void
<anonymous namespace>::FPS::handleSpecialFP(MachineBasicBlock::iterator &):
Assertion `NumPendingSTs > SrcST && "Cannot copy from dead ST register"'
failed.
0  clang           0x000000000397414e llvm::sys::PrintStackTrace(_IO_FILE*) +
46
1  clang           0x000000000397442b
2  clang           0x00000000039757ee
3  libpthread.so.0 0x00007fcde6be6030
4  libc.so.6       0x00007fcde5882475 gsignal + 53
5  libc.so.6       0x00007fcde58856f0 abort + 384
6  libc.so.6       0x00007fcde587b621 __assert_fail + 241
7  clang           0x0000000002c94ec8
8  clang           0x0000000002c91c1d
9  clang           0x0000000002c9134b
10 clang           0x0000000003134bae
llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 110
11 clang           0x00000000038d83bb
llvm::FPPassManager::runOnFunction(llvm::Function&) + 427
12 clang           0x00000000038d86c8
llvm::FPPassManager::runOnModule(llvm::Module&) + 104
13 clang           0x00000000038d8d8a
14 clang           0x00000000038d897e
llvm::legacy::PassManagerImpl::run(llvm::Module&) + 302
15 clang           0x00000000038d9351
llvm::legacy::PassManager::run(llvm::Module&) + 33
16 clang           0x0000000000c720ac
17 clang           0x0000000000c719d2
clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions
const&, clang::TargetOptions const&, clang::LangOptions const&,
llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 114
18 clang           0x0000000000c6e690
19 clang           0x0000000000ef1c7c clang::ParseAST(clang::Sema&, bool, bool)
+ 796
20 clang           0x000000000096f379 clang::ASTFrontendAction::ExecuteAction()
+ 345
21 clang           0x0000000000c6da42 clang::CodeGenAction::ExecuteAction() +
1474
22 clang           0x000000000096eb3f clang::FrontendAction::Execute() + 191
23 clang           0x0000000000936dfd
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 797
24 clang           0x00000000008f5fa4
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1044
25 clang           0x00000000008e2bda cc1_main(char const**, char const**, char
const*, void*) + 698
26 clang           0x00000000008f0254 main + 772
27 libc.so.6       0x00007fcde586eead __libc_start_main + 253
28 clang           0x00000000008e2089
Stack dump:
0.      Program arguments: /home/faux/code/build/Debug+Asserts/bin/clang -cc1
-triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name
clangcrash.cpp -mrelocation-model static -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64
-target-linker-version 2.22 -momit-leaf-frame-pointer -resource-dir
/home/faux/code/build/Debug+Asserts/bin/../lib/clang/3.5.0 -internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7 -internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/x86_64-linux-gnu
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/backward
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/x86_64-linux-gnu/c++/4.7
-internal-isystem /usr/local/include -internal-isystem
/home/faux/code/build/Debug+Asserts/bin/../lib/clang/3.5.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include -O1
-fdeprecated-macro -fdebug-compilation-dir /home/faux -ferror-limit 19
-fmessage-length 254 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions
-fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o
/tmp/clangcrash-20245c.o -x c++ clangcrash.cpp
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'clangcrash.cpp'.
4.      Running pass 'X86 FP Stackifier' on function '@_Z5tointie'
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.5.0 (trunk 204538)
Target: x86_64-unknown-linux-gnu
Thread model: posix


 "/home/faux/code/build/Debug+Asserts/bin/clang" -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name clangcrash.cpp
-mrelocation-model static -fmath-errno -masm-verbose -mconstructor-aliases
-munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.22
-momit-leaf-frame-pointer -O1 -fdeprecated-macro -ferror-limit 19
-fmessage-length 254 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions
-fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -x
c++ clangcrash-526bcb.cpp</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>