<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/100076>100076</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Loop vectorizer causes error in backend (COMDAT symbol of string literal does not exist)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vossjannik
</td>
</tr>
</table>
<pre>
### Problem Description
After upgrading from clang 14, we experience an error in the LLVM backend when compiling for `armv7a-none-windows-eabi`.
The problem seems to be in the loop vectorizer and happens only with string literals that are longer than 15 characters.
It happens with clang 15, 16, 17, and 18.
The way the string buffer is allocated seems to be important, I was not able to reproduce the error when allocating the string buffer with "operator new".
### Workaround
The code snippet in the repro steps includes an alternative implementation that apparently is optimized differently by the vectorizer.
### Repro steps
[Reproduce in Compiler Explorer](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:2,endLineNumber:30,positionColumn:1,positionLineNumber:1,selectionStartColumn:2,selectionStartLineNumber:30,startColumn:1,startLineNumber:1),source:'using+size_t+%3D+decltype(sizeof(0))%3B%0A%0Avoid*+malloc(size_t)%3B%0Avoid+free(void*)%3B%0A%0Ainline+void+move_chars(char*+dest,+const+char*+src,+size_t+nCount)+%7B%0A%09if+(src+%3C+dest)+%7B%0A%23if+1%0A++++++++//+broken%0A%09%09src++%2B%3D+nCount%3B%0A%09%09dest+%2B%3D+nCount%3B%0A%09%09for+(%3B+nCount+%3E+0%3B+--nCount)%0A%09%09%09*(--dest)+%3D+*(--src)%3B%0A%23else%0A++++++++//+working%0A++++%09for+(%3B+nCount+%3E+0%3B+--nCount)%0A%09%09%09dest%5BnCount+-+1%5D+%3D++src%5BnCount+-+1%5D%3B%0A%23endif%0A%09%7D%0A%09else%0A%09%09for+(%3B+nCount+%3E+0%3B+--nCount,+%2B%2Bsrc,+%2B%2Bdest)%0A%09%09%09*dest+%3D++*src%3B%0A%7D%0A%0Avoid+ReproduceCompilationError()%7B%0A++++//+strlen(%22Failed+to+flush.%22)+%3D%3D+16,+no+error+with+shorter+string+literals%0A%09char*+pData+%3D+static_cast%3Cchar*%3E(malloc(16+%2B+1))%3B%0A%09move_chars(pData,+%22Failed+to+flush.%22,+16)%3B%0A%09free(pData)%3B%0A%7D%0A'),l:'5',n:'1',o:'C%2B%2B+source+%231',t:'0')),k:49.95806793103728,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:clang1810,filters:(b:'1',binary:'1',binaryObject:'1',commentOnly:'1',debugCalls:'1',demangle:'0',directives:'1',execute:'1',intel:'0',libraryCode:'1',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-Og+-target+armv7a-none-windows-eabi+-fvectorize',overrides:!(),selection:(endColumn:45,endLineNumber:3,positionColumn:45,positionLineNumber:3,selectionStartColumn:45,selectionStartLineNumber:3,startColumn:45,startLineNumber:3),source:1),l:'5',n:'0',o:'+x86-64+clang+18.1.0+(Editor+%231)',t:'0')),k:50.04193206896273,l:'4',m:50,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+clang+17.0.1',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+18.1.0+(Compiler+%231)',t:'0')),header:(),l:'4',m:50,n:'0',o:'',s:0,t:'0')),k:50.04193206896273,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
Compile the code snippet with the following command line arguments:
`-Og -target armv7a-none-windows-eabi -fvectorize`
```cpp
using size_t = decltype(sizeof(0));
void* malloc(size_t);
void free(void*);
inline void move_chars(char* dest, const char* src, size_t nCount) {
if (src < dest) {
#if 1
// broken
src += nCount;
dest += nCount;
for (; nCount > 0; --nCount)
*(--dest) = *(--src);
#else
// working
for (; nCount > 0; --nCount)
dest[nCount - 1] = src[nCount - 1];
#endif
}
else
for (; nCount > 0; --nCount, ++src, ++dest)
*dest = *src;
}
void ReproduceCompilationError(){
// strlen("Failed to flush.") == 16, no error with shorter string literals
char* pData = static_cast<char*>(malloc(16 + 1));
move_chars(pData, "Failed to flush.", 16);
free(pData);
}
```
### Error Message
```txt
fatal error: error in backend: Associative COMDAT symbol '??_C@_0BB@GABOHBIL@Failed?5to?5flush?4?$AA@' does not exist.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-18.1.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -Og -target armv7a-none-windows-eabi -fvectorize <source>
1. <eof> parser at end of file
2. Code generation
#0 0x000000000351ae38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x351ae38)
#1 0x0000000003518f84 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3518f84)
#2 0x0000000003467543 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3467543)
#3 0x000000000351097e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x351097e)
#4 0x0000000000c17976 (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc17976)
#5 0x0000000003470593 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3470593)
#6 0x0000000002c16bda getComdatGVForCOFF(llvm::GlobalValue const*) TargetLoweringObjectFileImpl.cpp:0:0
#7 0x0000000002c174db llvm::TargetLoweringObjectFileCOFF::SelectSectionForGlobal(llvm::GlobalObject const*, llvm::SectionKind, llvm::TargetMachine const&) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2c174db)
#8 0x00000000049e2b65 llvm::TargetLoweringObjectFile::SectionForGlobal(llvm::GlobalObject const*, llvm::SectionKind, llvm::TargetMachine const&) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x49e2b65)
#9 0x000000000424d56d llvm::AsmPrinter::emitGlobalVariable(llvm::GlobalVariable const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x424d56d)
#10 0x00000000042553b9 llvm::AsmPrinter::doFinalization(llvm::Module&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x42553b9)
#11 0x0000000002edbc6d llvm::FPPassManager::doFinalization(llvm::Module&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2edbc6d)
#12 0x0000000002ee84d0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2ee84d0)
#13 0x000000000378ad99 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x378ad99)
#14 0x0000000003d5b2d1 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d5b2d1)
#15 0x0000000005b965d9 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x5b965d9)
#16 0x0000000003d5a725 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d5a725)
#17 0x0000000003fe2aa1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3fe2aa1)
#18 0x0000000003f6010b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3f6010b)
#19 0x00000000040c2473 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x40c2473)
#20 0x0000000000c19746 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc19746)
#21 0x0000000000c1211d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#22 0x0000000003da1979 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#23 0x0000000003467443 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3467443)
#24 0x0000000003da1b99 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#25 0x0000000003d69d17 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d69d17)
#26 0x0000000003d6a6cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d6a6cd)
#27 0x0000000003d7445c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d7445c)
#28 0x0000000000c16a21 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc16a21)
#29 0x0000000000b0fa84 main (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xb0fa84)
#30 0x00007461aa629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#31 0x00007461aa629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#32 0x0000000000c1191e _start (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc1191e)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkW1tz47aS_jX0C0oqEqQk8sEPEm0lk505nhrPyT6qQLIlIUMCXAD0Jb9-CxdSBCV7nByd3dralKMxiUb3141GXwCZSEkPDOA2WGyCxd0N6dSRi9snLuUfhDH646bg1ettgGP7g74KXtTQoDuQpaCtopwF4V0Qru3neq9AoK49CFJRdkB7wRtU1oQdUJQEOEfPgOClBUGBlYAIQyAEF4gypI6APn_-_QsqSPkDWIWej8BQyZuW1oYVFyhYhkQ0TysyY5zB7Jmyij_LGZCCBstwbjF8PwJqHUwJ0EikOCqgl1Fz3qInKBUX9E8QiLAKHUnbApOIs_oVPVN1RFIJLbSmCgSpJVJHohARejo7gNDPDEULVB6JIKUCIZ30T2rgZhg55Rda-WhpPlf6U4uN0jk6YX4mrwagE110-z0IRCUidc1LoqDy1WlaLhRhSnP7hJ6JRIwrRIoaNIWAVvCqK8HwtFY2FnXctIhzaQZygDFvQRDFBWLwHGA8H6_xyRn-k4sfRPCOVeNxrUvJK0CS0bYF1RveIEJSQSsRZWXdVSC1B5BagWBE0SejVA0NMEW0Zzmrty0RwFT9qo3BW0Ub-idUqKIash0orOlOy_oG4m8nDB7BYvNtsBdlKDdeBwLdv7Q1FyCCxV2A06NSrQzidYC3Ad4eeFXwWs25OJgX8cEMRQFOA5y-_XAM4rW2z31FFRcBz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