[llvm-bugs] [Bug 50325] New: clang crash in llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1536: bool (anonymous namespace)::LSRUse::InsertFormula(const (anonymous namespace)::Formula &, const llvm::Loop &): Assertion `F.isCanonical(L) && "Invalid canonical representation"' failed

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 13 00:01:11 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50325

            Bug ID: 50325
           Summary: clang crash in
                    llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1536
                    : bool (anonymous
                    namespace)::LSRUse::InsertFormula(const (anonymous
                    namespace)::Formula &, const llvm::Loop &): Assertion
                    `F.isCanonical(L) && "Invalid canonical
                    representation"' failed
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: llvm-bugs at lists.llvm.org

Hi all,

This program makes clang (only the trunk version) crash under -O3. The crash
file is the same as bug 49697 but with a different line, and I am not sure if
they are caused by the same issue. From the assertion and the stack
information, I don't think they are the same bugs.

$cat small.c
#include <stdint.h>
int a, b, c, d, e;
void f() {
  e = 30;
  for (; e <= 37; e++) {
    {
      uint8_t *g = &a;
      for (d = 3; d;)
        d = *g -= c;
      {
        uint16_t *i = b;
        uint8_t *j = &a;
        if (*j -= *i) {
          int32_t k;
          for (c = 0; k;)
            ;
        }
      }
    }
    uint8_t *g = &a;
    for (d = 3; d;)
      d = *g -= c;
  }
  e = 30;
  for (; e <= 37; e++) {
    {
      uint8_t *g = &a;
      for (d = 3; d;)
        d = *g -= c;
      {
        uint16_t *i = b;
        uint8_t *j = &a;
        if (*j -= *i) {
          int32_t k;
          for (c = 0; k;)
            ;
        }
      }
    }
  }
}


$clang -w -O3 small.c
clang-13:
/home/tuhaoxin/compilers/llvm-project/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1536:
bool (anonymous namespace)::LSRUse::InsertFormula(const (anonymous
namespace)::Formula &, const llvm::Loop &): Assertion `F.isCanonical(L) &&
"Invalid canonical representation"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments:
/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13 -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free
-main-file-name small.c -mrelocation-model static -mframe-pointer=none
-fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables
-target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb
-fcoverage-compilation-dir=/home/tuhaoxin/dut-research/covsmith-test
-resource-dir /home/tuhaoxin/compilers/llvm-project/build/lib/clang/13.0.0
-c-isystem /usr/local/include/csmith-2.4.0 -cxx-isystem
/usr/local/include/csmith-2.4.0 -internal-isystem
/home/tuhaoxin/compilers/llvm-project/build/lib/clang/13.0.0/include
-internal-isystem /usr/local/include -internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include -O3
-w -fdebug-compilation-dir=/home/tuhaoxin/dut-research/covsmith-test
-ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops
-vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-015664.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 'Loop Pass Manager' on function '@f'
5.      Running pass 'Loop Strength Reduction' on basic block '%for.cond1.2'
 #0 0x0000000002a8bbd3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2a8bbd3)
 #1 0x0000000002a8991e llvm::sys::RunSignalHandlers()
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2a8991e)
 #2 0x0000000002a8bf5f SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f04664f63c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007f0465f8b18b raise
/build/glibc-eX1tMB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f0465f6a859 abort /build/glibc-eX1tMB/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f0465f6a729 get_sysdep_segment_value
/build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f0465f6a729 _nl_load_domain
/build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f0465f7bf36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
 #9 0x00000000028a45c3 (anonymous
namespace)::LSRInstance::InsertFormula((anonymous namespace)::LSRUse&, unsigned
int, (anonymous namespace)::Formula const&) LoopStrengthReduce.cpp:0:0
#10 0x00000000028948bc (anonymous
namespace)::LSRInstance::GenerateAllReuseFormulae() LoopStrengthReduce.cpp:0:0
#11 0x000000000288fcf3 (anonymous
namespace)::LSRInstance::LSRInstance(llvm::Loop*, llvm::IVUsers&,
llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&,
llvm::TargetTransformInfo const&, llvm::AssumptionCache&,
llvm::TargetLibraryInfo&, llvm::MemorySSAUpdater*) LoopStrengthReduce.cpp:0:0
#12 0x00000000028885a8 ReduceLoopStrength(llvm::Loop*, llvm::IVUsers&,
llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&,
llvm::TargetTransformInfo const&, llvm::AssumptionCache&,
llvm::TargetLibraryInfo&, llvm::MemorySSA*) LoopStrengthReduce.cpp:0:0
#13 0x00000000028b2d01 (anonymous
namespace)::LoopStrengthReduce::runOnLoop(llvm::Loop*, llvm::LPPassManager&)
LoopStrengthReduce.cpp:0:0
#14 0x0000000001c1730b llvm::LPPassManager::runOnFunction(llvm::Function&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x1c1730b)
#15 0x00000000022d4ff8 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x22d4ff8)
#16 0x00000000022db7f8 llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x22db7f8)
#17 0x00000000022d56a7 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x22d56a7)
#18 0x0000000002d1110c (anonymous
namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >) BackendUtil.cpp:0:0
#19 0x0000000002d0a7dd clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef,
llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2d0a7dd)
#20 0x00000000039c0218
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x39c0218)
#21 0x00000000043721d3 clang::ParseAST(clang::Sema&, bool, bool)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x43721d3)
#22 0x0000000003340e73 clang::FrontendAction::Execute()
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x3340e73)
#23 0x00000000032b1883
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x32b1883)
#24 0x00000000033f0d52
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x33f0d52)
#25 0x00000000009db5c8 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x9db5c8)
#26 0x00000000009d93cd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
driver.cpp:0:0
#27 0x00000000009d90b4 main
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x9d90b4)
#28 0x00007f0465f6c0b3 __libc_start_main
/build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:342:3
#29 0x00000000009d606e _start
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x9d606e)
clang-13: error: unable to execute command: Aborted (core dumped)
clang-13: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 13.0.0 (https://github.com/llvm/llvm-project.git
ea64200b6197d8db97a11db15a5906fc1eb5ef4a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/tuhaoxin/compilers/llvm-project/build/bin
clang-13: note: diagnostic msg: 
********************

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

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

Thanks,
Haoxin

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210513/f4670124/attachment-0001.html>


More information about the llvm-bugs mailing list