<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 on valid code at -Os and above on x86_64-linux-gnu: Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"' failed"
   href="https://bugs.llvm.org/show_bug.cgi?id=34991">34991</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang crashes on valid code at -Os and above on x86_64-linux-gnu: Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"' failed
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>Tested with trunk rev. 316071. 

$ clangpolly -v
clang version 6.0.0 (<a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a>
aed3a60e367b760d907954563f404458f9dbd478) (<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a>
cbd850f350921d0afdbdee35d5599b257cd1e8b3)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/su/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
$
$ clangpolly -O1 small.c
$
$ clangpolly -Os small.c
clang-6.0: /home/su/software/tmp/polly/llvm/lib/IR/Constants.cpp:1440: static
llvm::Constant* llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*,
llvm::Type*, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid
constantexpr cast!"' failed.
#0 0x0000000002079e2a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/home/su/software/tmp/polly/llvm/lib/Support/Unix/Signals.inc:402:0
#1 0x0000000002077c9e llvm::sys::RunSignalHandlers()
/home/su/software/tmp/polly/llvm/lib/Support/Signals.cpp:50:0
#2 0x0000000002077e12 SignalHandler(int)
/home/su/software/tmp/polly/llvm/lib/Support/Unix/Signals.inc:242:0
#3 0x00007f7aca453390 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#4 0x00007f7ac91c5428 gsignal
/build/glibc-bfm8X4/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
#5 0x00007f7ac91c702a abort /build/glibc-bfm8X4/glibc-2.23/stdlib/abort.c:91:0
#6 0x00007f7ac91bdbd7 __assert_fail_base
/build/glibc-bfm8X4/glibc-2.23/assert/assert.c:92:0
#7 0x00007f7ac91bdc82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
#8 0x0000000001b49bc6 llvm::ConstantExpr::getCast(unsigned int,
llvm::Constant*, llvm::Type*, bool)
/home/su/software/tmp/polly/llvm/lib/IR/Constants.cpp:1439:0
#9 0x00000000017c9ee5 lookThroughCast(llvm::CmpInst*, llvm::Value*,
llvm::Value*, llvm::Instruction::CastOps*)
/home/su/software/tmp/polly/llvm/lib/Analysis/ValueTracking.cpp:4423:0
#10 0x00000000017cf0c3 llvm::matchSelectPattern(llvm::Value*, llvm::Value*&,
llvm::Value*&, llvm::Instruction::CastOps*)
/home/su/software/tmp/polly/llvm/lib/Analysis/ValueTracking.cpp:4456:0
#11 0x0000000001d49216 llvm::InstCombiner::visitSelectInst(llvm::SelectInst&)
/home/su/software/tmp/polly/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:1428:0
#12 0x0000000001ce0ef4 llvm::InstCombiner::run()
/home/su/software/tmp/polly/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:3003:0
#13 0x0000000001ce2ec7 combineInstructionsOverFunction(llvm::Function&,
llvm::InstCombineWorklist&, llvm::AAResults*, llvm::AssumptionCache&,
llvm::TargetLibraryInfo&, llvm::DominatorTree&,
llvm::OptimizationRemarkEmitter&, bool, llvm::LoopInfo*)
/home/su/software/tmp/polly/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:3237:0
#14 0x0000000001ce3859
llvm::InstructionCombiningPass::runOnFunction(llvm::Function&)
/home/su/software/tmp/polly/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:3296:0
#15 0x0000000001bda5ab llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1514:0
#16 0x000000000169684e RunPassOnSCC
/home/su/software/tmp/polly/llvm/lib/Analysis/CallGraphSCCPass.cpp:156:0
#17 0x000000000169684e RunAllPassesOnSCC
/home/su/software/tmp/polly/llvm/lib/Analysis/CallGraphSCCPass.cpp:424:0
#18 0x000000000169684e (anonymous
namespace)::CGPassManager::runOnModule(llvm::Module&)
/home/su/software/tmp/polly/llvm/lib/Analysis/CallGraphSCCPass.cpp:479:0
#19 0x0000000001bda1ad runOnModule
/home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1591:0
#20 0x0000000001bda1ad llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1694:0
#21 0x000000000221f03e llvm::PrettyStackTraceString::~PrettyStackTraceString()
/home/su/software/tmp/polly/llvm/include/llvm/Support/PrettyStackTrace.h:52:0
#22 0x000000000221f03e EmitAssembly
/home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:788:0
#23 0x000000000221f03e 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/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:1145:0
#24 0x0000000002a2a2f7 std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >::~unique_ptr()
/usr/include/c++/5/bits/unique_ptr.h:235:0
#25 0x0000000002a2a2f7
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
/home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:292:0
#26 0x0000000002bfdde8 void std::swap<bool>(bool&, bool&)
/usr/include/c++/5/bits/move.h:187:0
#27 0x0000000002bfdde8 clang::ParseAST(clang::Sema&, bool, bool)
/home/su/software/tmp/polly/llvm/tools/clang/lib/Parse/ParseAST.cpp:161:0
#28 0x0000000002a2978f clang::CodeGenAction::ExecuteAction()
/home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:1032:0
#29 0x00000000025c9de6 clang::FrontendAction::Execute()
/home/su/software/tmp/polly/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:897:0
#30 0x000000000259a3d6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/home/su/software/tmp/polly/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:992:0
#31 0x0000000002658472
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/home/su/software/tmp/polly/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:252:0
#32 0x0000000000a899c8 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*)
/home/su/software/tmp/polly/llvm/tools/clang/tools/driver/cc1_main.cpp:221:0
#33 0x0000000000a048c2 ExecuteCC1Tool
/home/su/software/tmp/polly/llvm/tools/clang/tools/driver/driver.cpp:309:0
#34 0x0000000000a048c2 main
/home/su/software/tmp/polly/llvm/tools/clang/tools/driver/driver.cpp:388:0
#35 0x00007f7ac91b0830 __libc_start_main
/build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:325:0
#36 0x0000000000a862e9 _start
(/home/su/software/tmp/polly/llvm_build/bin/clang-6.0+0xa862e9)
Stack dump:
0.      Program arguments: /home/su/software/tmp/polly/llvm_build/bin/clang-6.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 -dwarf-column-info -debugger-tuning=gdb
-momit-leaf-frame-pointer -resource-dir
/home/su/software/tmp/polly/llvm_build/lib/clang/6.0.0 -internal-isystem
/usr/local/include -internal-isystem
/home/su/software/tmp/polly/llvm_build/lib/clang/6.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include -Os
-fdebug-compilation-dir
/home/su/projects/c-hunter-latest/test/compilertesting/scripts/speculative-execution/good/20171018-clangpolly-m32-O3-mllvm-polly-build-063035/delta
-ferror-limit 19 -fmessage-length 116 -fobjc-runtime=gcc
-fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp
-o /tmp/small-28275b.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 'Combine redundant instructions' on function '@fn2'
clang-6.0: error: unable to execute command: Aborted (core dumped)
clang-6.0: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 6.0.0 (<a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a>
aed3a60e367b760d907954563f404458f9dbd478) (<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a>
cbd850f350921d0afdbdee35d5599b257cd1e8b3)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/su/bin
clang-6.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-6.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-6.0: note: diagnostic msg: /tmp/small-328ed2.c
clang-6.0: note: diagnostic msg: /tmp/small-328ed2.sh
clang-6.0: note: diagnostic msg:

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


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


int a;
char b;

short fn1 (short d, int e)

  return e > 1 ? d : e;
}

void fn2 ()

  int g = 0;
  a = fn1 (g, b);
}

int main ()

  fn2 ();
  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>