<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 `i_nocapture < OperandTraits<PHINode>::operands(this) && "getOperand() out of range!"' failed."
   href="https://bugs.llvm.org/show_bug.cgi?id=35123">35123</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang crashes with "-mllvm -enable-newgvn": Assertion `i_nocapture < OperandTraits<PHINode>::operands(this) && "getOperand() out of range!"' 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>It happens at -Os only.

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



$ clang-trunk -mllvm -enable-newgvn abc.c -Os
abc.c:9:14: warning: control reaches end of non-void function [-Wreturn-type]
char(fn1)() {}
             ^
abc.c:17:18: warning: use of logical '&&' with constant operand
[-Wconstant-logical-operand]
      c = (p1.f4 && 7) > (e && f || j);
                 ^  ~
abc.c:17:18: note: use '&' for a bitwise operation
      c = (p1.f4 && 7) > (e && f || j);
                 ^~
                 &
abc.c:17:18: note: remove constant to silence this warning
      c = (p1.f4 && 7) > (e && f || j);
                ~^~~~
abc.c:17:29: warning: '&&' within '||' [-Wlogical-op-parentheses]
      c = (p1.f4 && 7) > (e && f || j);
                          ~~^~~~ ~~
abc.c:17:29: note: place parentheses around the '&&' expression to silence this
warning
      c = (p1.f4 && 7) > (e && f || j);
                            ^
                          (     )
abc.c:26:5: warning: expression result unused [-Wunused-value]
  g.f0;
  ~ ^~
clang-6.0: /home/absozero/trunk/llvm/include/llvm/IR/Instructions.h:2772:
llvm::Value* llvm::PHINode::getOperand(unsigned int) const: Assertion
`i_nocapture < OperandTraits<PHINode>::operands(this) && "getOperand() out of
range!"' failed.
#0 0x00000000020c2eca llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x20c2eca)
#1 0x00000000020c0d6e llvm::sys::RunSignalHandlers()
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x20c0d6e)
#2 0x00000000020c0ec2 SignalHandler(int)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x20c0ec2)
#3 0x00007f6d0ea59330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#4 0x00007f6d0d5d6c37 gsignal
/build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#5 0x00007f6d0d5da028 abort
/build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
#6 0x00007f6d0d5cfbf6 __assert_fail_base
/build/eglibc-oGUzwX/eglibc-2.19/assert/assert.c:92:0
#7 0x00007f6d0d5cfca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#8 0x000000000175902f (/home/absozero/trunk/root-clang/bin/clang-6.0+0x175902f)
#9 0x0000000001d70917 llvm::InstCombiner::visitPHINode(llvm::PHINode&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1d70917)
#10 0x0000000001d0f2d4 llvm::InstCombiner::run()
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1d0f2d4)
#11 0x0000000001d1115f combineInstructionsOverFunction(llvm::Function&,
llvm::InstCombineWorklist&, llvm::AAResults*, llvm::AssumptionCache&,
llvm::TargetLibraryInfo&, llvm::DominatorTree&,
llvm::OptimizationRemarkEmitter&, bool, llvm::LoopInfo*)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1d1115f)
#12 0x0000000001d11ae9
llvm::InstructionCombiningPass::runOnFunction(llvm::Function&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1d11ae9)
#13 0x0000000001bf9623 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1bf9623)
#14 0x000000000169015e (anonymous
namespace)::CGPassManager::runOnModule(llvm::Module&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x169015e)
#15 0x0000000001bf91bd llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1bf91bd)
#16 0x0000000002273536 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-6.0+0x2273536)
#17 0x0000000002a953a7
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x2a953a7)
#18 0x0000000002c75878 clang::ParseAST(clang::Sema&, bool, bool)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x2c75878)
#19 0x0000000002a9475c clang::CodeGenAction::ExecuteAction()
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x2a9475c)
#20 0x000000000262977e clang::FrontendAction::Execute()
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x262977e)
#21 0x00000000025f8be6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x25f8be6)
#22 0x00000000026bc2c3
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x26bc2c3)
#23 0x0000000000a52c08 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/absozero/trunk/root-clang/bin/clang-6.0+0xa52c08)
#24 0x00000000009cf145 main
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x9cf145)
#25 0x00007f6d0d5c1f45 __libc_start_main
/build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321:0
#26 0x0000000000a4f119 _start
(/home/absozero/trunk/root-clang/bin/clang-6.0+0xa4f119)
Stack dump:
0.      Program arguments: /home/absozero/trunk/root-clang/bin/clang-6.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
-dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -resource-dir
/home/absozero/trunk/root-clang/lib/clang/6.0.0 -internal-isystem
/usr/local/include -internal-isystem
/home/absozero/trunk/root-clang/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/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-9e8ffa.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 '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 (trunk 316860)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/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/abc-ec67e8.c
clang-6.0: note: diagnostic msg: /tmp/abc-ec67e8.sh
clang-6.0: note: diagnostic msg:

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



$ cat abc.c
short a;
union U1 {
  unsigned f0 : 8;
  int f1;
  char f4;
};
int b, c, e;
volatile short d;
char(fn1)() {}
static short fn2(union U1 p1) {
  short f;
  int j;
  for (;;) {
    b = 0;
    for (; b <= 2; b++) {
      f = a % d;
      c = (p1.f4 && 7) > (e && f || j);
      p1.f1 = 2;
      j = fn1();
    }
  }
}
int main() {
  union U1 g;
  fn2(g);
  g.f0;
}</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>