<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 --- - clang crashes on valid code at -O0 with -ftrapv (affecting all clang versions)"
   href="http://llvm.org/bugs/show_bug.cgi?id=18363">18363</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang crashes on valid code at -O0 with -ftrapv (affecting all clang versions)
          </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>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>su@cs.ucdavis.edu
          </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 current clang trunk (as well as the earlier versions) crashes when
compiling the following testcase at -O0 with -ftrapv enabled in both 32-bit and
64-bit modes. The crash doesn't happen at -O1 and above with -ftrapv, or at all
levels when -ftrapv is disabled. 

It seems to affect both x86_64-linux-gnu and MacOS X. 

$ clang-trunk -v
clang version 3.5 (trunk 198325) (llvm/trunk 198324)
Target: x86_64-unknown-linux-gnu
Thread model: posix
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.6
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.3
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6

$ clang-trunk -O0 -c small.c
$ clang-trunk -O1 -ftrapv -c small.c
$ clang-trunk -O0 -ftrapv -c small.c
clang: /tmp/llvm/include/llvm/Support/Casting.h:225: typename
enable_if_c<!is_simple_type<Y>::value, typename cast_retty<X, const
Y>::ret_type>::type llvm::cast(const Y &) [X = llvm::ConstantSDNode, Y =
llvm::SDValue]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible
type!"' failed.
0  clang           0x0000000002322ac5 llvm::sys::PrintStackTrace(_IO_FILE*) +
37
1  clang           0x00000000023232b3
2  libpthread.so.0 0x00007f0afd1cccb0
3  libc.so.6       0x00007f0afbfee425 gsignal + 53
4  libc.so.6       0x00007f0afbff1b8b abort + 379
5  libc.so.6       0x00007f0afbfe70ee
6  libc.so.6       0x00007f0afbfe7192
7  clang           0x0000000001ade402
8  clang           0x0000000001ae3ed0
llvm::X86TargetLowering::LowerOperation(llvm::SDValue, llvm::SelectionDAG&)
const + 912
9  clang           0x0000000001c5077e
10 clang           0x0000000001c4f5cb llvm::SelectionDAG::Legalize() + 363
11 clang           0x0000000001c28cf9
llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 2729
12 clang           0x0000000001c27523
llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 5795
13 clang           0x0000000001c24e8f
llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1391
14 clang           0x0000000001d921fc
llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 124
15 clang           0x000000000223905a
llvm::FPPassManager::runOnFunction(llvm::Function&) + 362
16 clang           0x00000000022392eb
llvm::FPPassManager::runOnModule(llvm::Module&) + 43
17 clang           0x0000000002239887
llvm::legacy::PassManagerImpl::run(llvm::Module&) + 999
18 clang           0x000000000086163d
clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions
const&, clang::TargetOptions const&, clang::LangOptions const&,
llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) +
6301
19 clang           0x000000000085f0f1
20 clang           0x00000000009e63b3 clang::ParseAST(clang::Sema&, bool, bool)
+ 515
21 clang           0x000000000085df4e clang::CodeGenAction::ExecuteAction() +
142
22 clang           0x00000000006c9140 clang::FrontendAction::Execute() + 112
23 clang           0x00000000006a656d
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 925
24 clang           0x000000000068d1c0
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 2880
25 clang           0x000000000068543f cc1_main(char const**, char const**, char
const*, void*) + 687
26 clang           0x000000000068b420 main + 9184
27 libc.so.6       0x00007f0afbfd976d __libc_start_main + 237
28 clang           0x00000000006850c9
Stack dump:
0.    Program arguments: /usr/local/clang-trunk/bin/clang -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
small.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version
2.22 -coverage-file
/data2/c-hunter-results/C/trans-bugs/20140102-clang-m32-m64-O0-build-test1/small.o
-resource-dir /usr/local/clang-trunk/bin/../lib/clang/3.5 -internal-isystem
/usr/local/include -internal-isystem
/usr/local/clang-trunk/bin/../lib/clang/3.5/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -O0 -fdebug-compilation-dir
/data2/c-hunter-results/C/trans-bugs/20140102-clang-m32-m64-O0-build-test1
-ferror-limit 19 -fmessage-length 103 -ftrapv -mstackrealign -fobjc-runtime=gcc
-fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o small.o -x c
small.c 
1.    <eof> parser at end of file
2.    Code generation
3.    Running pass 'Function Pass Manager' on module 'small.c'.
4.    Running pass 'X86 DAG->DAG Instruction Selection' on function '@foo'
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.5 (trunk 198325) (llvm/trunk 198324)
Target: x86_64-unknown-linux-gnu
Thread model: posix
clang: 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: note: diagnostic msg: 
********************

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

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



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


int a;

int *
foo ()
{
  switch (a)
    {
    case 1:
      return __builtin_return_address (0 + 0);
    default: 
      return 0; 
    }
}</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>