<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/73123>73123</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Invalid assembly crashes LLVM assembler
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
stuxnot
</td>
</tr>
</table>
<pre>
Fuzzing an assembler using LLVMs backend i found that some assembly inputs can crash the LLVM assembler (only when using intel syntax). This can be reproduced with clang version 16.0.6. One reduced example of this is the string `"a a|"`. Using this string in inline assembly and trying to assemble the file with `clang -masm=intel` leads to a crash reporting:
```
fatal error: error in backend: SmallVector unable to grow. Requested capacity (4294967296) is larger than maximum value for size type (4294967295)
```
In [debug.zip](https://github.com/llvm/llvm-project/files/13440352/debug.zip) you can find preprocessed srcs and the run script for an example program.
The associated stack dump is:
```
Stack dump:
0. Program arguments: clang -c test.c -masm=intel
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'test.c'.
4. Running pass 'X86 Assembly Printer' on function '@main'
#0 0x00007f0f8861f503 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM-16.so+0xe1f503)
#1 0x00007f0f8861c7bf llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-16.so+0xe1c7bf)
#2 0x00007f0f88508d9a llvm::CrashRecoveryContext::HandleExit(int) (/usr/lib/libLLVM-16.so+0xd08d9a)
#3 0x00007f0f886158d4 llvm::sys::Process::Exit(int, bool) (/usr/lib/libLLVM-16.so+0xe158d4)
#4 0x000055f89d67f463 (/usr/bin/clang-16+0xf463)
#5 0x00007f0f8851f002 llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/lib/libLLVM-16.so+0xd1f002)
#6 0x00007f0f8858a42b (/usr/lib/libLLVM-16.so+0xd8a42b)
#7 0x00007f0f8858a6af llvm::SmallVectorBase<unsigned int>::grow_pod(void*, unsigned long, unsigned long) (/usr/lib/libLLVM-16.so+0xd8a6af)
#8 0x00007f0f8c3ce806 (/usr/lib/libLLVM-16.so+0x4bce806)
#9 0x00007f0f8c3e3c91 (/usr/lib/libLLVM-16.so+0x4be3c91)
#10 0x00007f0f8c3e86a6 (/usr/lib/libLLVM-16.so+0x4be86a6)
#11 0x00007f0f8a457951 (/usr/lib/libLLVM-16.so+0x2c57951)
#12 0x00007f0f8a476578 (/usr/lib/libLLVM-16.so+0x2c76578)
#13 0x00007f0f8a4687c0 (/usr/lib/libLLVM-16.so+0x2c687c0)
#14 0x00007f0f8919abab llvm::AsmPrinter::emitInlineAsm(llvm::StringRef, llvm::MCSubtargetInfo const&, llvm::MCTargetOptions const&, llvm::MDNode const*, llvm::InlineAsm::AsmDialect) const (/usr/lib/libLLVM-16.so+0x199abab)
#15 0x00007f0f8919b948 llvm::AsmPrinter::emitInlineAsm(llvm::MachineInstr const*) const (/usr/lib/libLLVM-16.so+0x199b948)
#16 0x00007f0f8919730b llvm::AsmPrinter::emitFunctionBody() (/usr/lib/libLLVM-16.so+0x199730b)
#17 0x00007f0f8c08a163 (/usr/lib/libLLVM-16.so+0x488a163)
#18 0x00007f0f88aea945 (/usr/lib/libLLVM-16.so+0x12ea945)
#19 0x00007f0f887ab989 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/libLLVM-16.so+0xfab989)
#20 0x00007f0f887abd34 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/libLLVM-16.so+0xfabd34)
#21 0x00007f0f887ac6ac llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/libLLVM-16.so+0xfac6ac)
#22 0x00007f0f912f3fb3 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>>) (/usr/lib/libclang-cpp.so.16+0x16f3fb3)
#23 0x00007f0f91619229 (/usr/lib/libclang-cpp.so.16+0x1a19229)
#24 0x00007f0f904ecfb0 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/libclang-cpp.so.16+0x8ecfb0)
#25 0x00007f0f91d1e7c9 clang::FrontendAction::Execute() (/usr/lib/libclang-cpp.so.16+0x211e7c9)
#26 0x00007f0f91cc0d2f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/libclang-cpp.so.16+0x20c0d2f)
#27 0x00007f0f91d7bf02 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/libclang-cpp.so.16+0x217bf02)
#28 0x000055f89d684a6f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang-16+0x14a6f)
#29 0x000055f89d688b10 (/usr/bin/clang-16+0x18b10)
#30 0x00007f0f919ec779 (/usr/lib/libclang-cpp.so.16+0x1dec779)
#31 0x00007f0f88508c87 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib/libLLVM-16.so+0xd08c87)
#32 0x00007f0f919f30c4 (/usr/lib/libclang-cpp.so.16+0x1df30c4)
#33 0x00007f0f91a11431 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib/libclang-cpp.so.16+0x1e11431)
#34 0x00007f0f91a117ed clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/usr/lib/libclang-cpp.so.16+0x1e117ed)
#35 0x00007f0f91a155dc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/usr/lib/libclang-cpp.so.16+0x1e155dc)
#36 0x000055f89d68b99f clang_main(int, char**) (/usr/bin/clang-16+0x1b99f)
#37 0x00007f0f87245cd0 (/usr/lib/libc.so.6+0x27cd0)
#38 0x00007f0f87245d8a __libc_start_main (/usr/lib/libc.so.6+0x27d8a)
#39 0x000055f89d67ced5 _start (/usr/bin/clang-16+0xced5)
clang-16: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 16.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
Note that without the `-c` flag, clang fails without producing a backtrace, but with the same error.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WV1v27jS_jXMDRFDor4vcuE69btdtNui6bs4dwZFjmyelUgtSSVxf_0BKdkR3TixzwIHKFJZHD7zzHA4MxSpMWIrAe5Q9gFl9zd0sDul74wdnqWyN7Xi-7v18POnkFtMJabGQFe3oPFg3KvPn__8YnBN2V8gORa4UYPk2O6oxUZ1cJDfYyH7wRrMqMRMU7PDdgd-9gwSkVLJdo-fdiAnfCEttNjspaXPiFQL_GMnRpQasIZeKz4w4PhJ2B1mLZVb_AjaCCVxnC-iRb7A-Kt0oqMcPNOubwGrBluHJIwnYqx22lAeIUIopqhYIUJQHi3w_3seXniSEhIL2Qo5s446o_XeS6qjRR66ES2M9FAejQxvO2o6lNx741Ae4RYoN37m5BwNvdJWyC1Klii6R9HSURv_-Z8NtbTFoLXSKFmOD47YtBLu3UNH2_ZPYFZpPEjq-Si81eppgb_D3wMYCxwz2lMm7N45PyVVWuUFqXJEKuealuotaLecEnf0WXRDhx9pOwBulMZG_ARs9z0EczNEqlcpj38_SYyyDxzqYbv4KXqU3SNS7qztjTOVrBFZb4XdDfWCqQ6Rdds-Hv677bX6NzCLyNo51SCyjpM0jZKMILJ-gSQV3qvBB0kjJMe9jxMGxgDHRjMzLtcOsB4kNkyL3nqDqDzGR6_VVtNuMZL-sfNrrZigzmfGUvYX5kPXY2HOrdDDUegoES1QVH0bkTHV26EDaR3AFLm3DFswdsFOIsRPjt1klKxANSj5iHuqDWhMLXYbTzU-zkZJ4iRXigPeggRNrVByHEncyPdBSheoPTUGI1KsB8mcCP7mXnyhkm5BI1JgJXGn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