<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 at -Os: Assertion `isa<SCEVConstant>(PHISCEV) && "Expected constant SCEV"' failed."
   href="https://bugs.llvm.org/show_bug.cgi?id=34812">34812</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang crashes at -Os: Assertion `isa<SCEVConstant>(PHISCEV) && "Expected constant SCEV"' 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>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>Level -O3 works fine.


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


$ clang-trunk -Os abc.c
abc.c:5:11: warning: implicit declaration of function 'fn2' is invalid in C99
[-Wimplicit-function-declaration]
  d = a | fn2();
          ^
abc.c:18:34: warning: & has lower precedence than ==; == will be evaluated
first [-Wparentheses]
      (c &= 2 <= 60) == (c += f) & (b *= c) ?: (h += 4);
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
abc.c:18:34: note: place parentheses around the '==' expression to silence this
warning
      (c &= 2 <= 60) == (c += f) & (b *= c) ?: (h += 4);
                                 ^
      (                         )
abc.c:18:34: note: place parentheses around the & expression to evaluate it
first
      (c &= 2 <= 60) == (c += f) & (b *= c) ?: (h += 4);
                                 ^
                        (                  )
abc.c:18:7: warning: expression result unused [-Wunused-value]
      (c &= 2 <= 60) == (c += f) & (b *= c) ?: (h += 4);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
abc.c:23:9: warning: incompatible pointer types initializing 'char *' with an
expression of type 'short *' [-Wincompatible-pointer-types]
  char *i = &h;
        ^   ~~
abc.c:24:3: warning: expression result unused [-Wunused-value]
  *i;
  ^~
clang-6.0: /home/absozero/trunk/llvm/lib/Analysis/ScalarEvolution.cpp:4527:
llvm::Optional<std::pair<const llvm::SCEV*, llvm::SmallVector<const
llvm::SCEVPredicate*, 3u> > >
llvm::ScalarEvolution::createAddRecFromPHIWithCastsImpl(const
llvm::SCEVUnknown*): Assertion `isa<SCEVConstant>(PHISCEV) && "Expected
constant SCEV"' failed.
#0 0x000000000205073a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x205073a)
#1 0x000000000204e5de llvm::sys::RunSignalHandlers()
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x204e5de)
#2 0x000000000204e732 SignalHandler(int)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x204e732)
#3 0x00007fdc64b6d330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#4 0x00007fdc636eac37 gsignal
/build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#5 0x00007fdc636ee028 abort
/build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
#6 0x00007fdc636e3bf6 __assert_fail_base
/build/eglibc-oGUzwX/eglibc-2.19/assert/assert.c:92:0
#7 0x00007fdc636e3ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#8 0x000000000173dc4c
llvm::ScalarEvolution::createAddRecFromPHIWithCastsImpl(llvm::SCEVUnknown
const*) (/home/absozero/trunk/root-clang/bin/clang-6.0+0x173dc4c)
#9 0x000000000173df6b
llvm::ScalarEvolution::createAddRecFromPHIWithCasts(llvm::SCEVUnknown const*)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x173df6b)
#10 0x0000000001742702 llvm::SCEVRewriteVisitor<(anonymous
namespace)::SCEVPredicateRewriter>::visit(llvm::SCEV const*)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1742702)
#11 0x0000000001742d4e llvm::ScalarEvolution::rewriteUsingPredicate(llvm::SCEV
const*, llvm::Loop const*, llvm::SCEVUnionPredicate&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1742d4e)
#12 0x0000000001744939 llvm::PredicatedScalarEvolution::getSCEV(llvm::Value*)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1744939)
#13 0x00000000020da1e0
llvm::InductionDescriptor::isInductionPHI(llvm::PHINode*, llvm::Loop const*,
llvm::PredicatedScalarEvolution&, llvm::InductionDescriptor&, bool)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x20da1e0)
#14 0x00000000021766ec (anonymous
namespace)::LoopVectorizationLegality::canVectorizeInstrs()
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x21766ec)
#15 0x000000000217733e (anonymous
namespace)::LoopVectorizationLegality::canVectorize() [clone .constprop.1671]
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x217733e)
#16 0x000000000218069e llvm::LoopVectorizePass::processLoop(llvm::Loop*)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x218069e)
#17 0x0000000002183487 llvm::LoopVectorizePass::runImpl(llvm::Function&,
llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&,
llvm::DominatorTree&, llvm::BlockFrequencyInfo&, llvm::TargetLibraryInfo*,
llvm::DemandedBits&, llvm::AAResults&, llvm::AssumptionCache&,
std::function<llvm::LoopAccessInfo const& (llvm::Loop&)>&,
llvm::OptimizationRemarkEmitter&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x2183487)
#18 0x0000000002183b0d (anonymous
namespace)::LoopVectorize::runOnFunction(llvm::Function&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x2183b0d)
#19 0x0000000001b9d653 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1b9d653)
#20 0x0000000001b9d71c llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1b9d71c)
#21 0x0000000001b9d1ed llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x1b9d1ed)
#22 0x00000000021fdc66 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+0x21fdc66)
#23 0x0000000002a10e27
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x2a10e27)
#24 0x0000000002bf0218 clang::ParseAST(clang::Sema&, bool, bool)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x2bf0218)
#25 0x0000000002a101dc clang::CodeGenAction::ExecuteAction()
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x2a101dc)
#26 0x00000000025a9d8e clang::FrontendAction::Execute()
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x25a9d8e)
#27 0x0000000002579506
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x2579506)
#28 0x000000000263cca3
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x263cca3)
#29 0x0000000000a453c8 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/absozero/trunk/root-clang/bin/clang-6.0+0xa453c8)
#30 0x00000000009c4185 main
(/home/absozero/trunk/root-clang/bin/clang-6.0+0x9c4185)
#31 0x00007fdc636d5f45 __libc_start_main
/build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321:0
#32 0x0000000000a418d9 _start
(/home/absozero/trunk/root-clang/bin/clang-6.0+0xa418d9)
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 142 -fobjc-runtime=gcc -fdiagnostics-show-option
-fcolor-diagnostics -vectorize-loops -vectorize-slp -o /tmp/abc-52ecea.o -x c
abc.c 
1.      <eof> parser at end of file
2.      Per-module optimization passes
3.      Running pass 'Function Pass Manager' on module 'abc.c'.
4.      Running pass 'Loop Vectorization' on function '@fn3'
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 314651)
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-5823d9.c
clang-6.0: note: diagnostic msg: /tmp/abc-5823d9.sh
clang-6.0: note: diagnostic msg: 

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



$ cat abc.c
char a, b;
int c, d, f;
long e, g;
void fn1() {
  d = a | fn2();
  for (; a;)
    ;
  e = 2;
  g++;
  for (; e;)
    ;
}
void fn3() {
  short h;
  fn1();
  if (f)
    for (;;) {
      (c &= 2 <= 60) == (c += f) & (b *= c) ?: (h += 4);
      f = 4;
      for (; c <= 7;)
        ;
    }
  char *i = &h;
  *i;
}</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>