<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/113774>113774</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            AVR backend doesn't reject bad asm, again
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          workingjubilee
      </td>
    </tr>
</table>

<pre>
    This code falls through to binary code emission, at which point it hits an `llvm_unreachable`. This may save you from getting any further if you've enabled the right CMake variable.

It is probably bad code that should get rejected way earlier.

```llvmir
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
target triple = "avr-unknown-unknown"

define void @main() addrspace(1) #0 {
 call addrspace(0) void asm sideeffect alignstack "st ${0}, ${1}", "e,r,~{sreg},~{memory}"(ptr nonnull inttoptr (i16 37 to ptr), i8 0)
 unreachable
}

attributes #0 = { "target-cpu"="atmega328p" }
```

And speaking of "should get rejected way earlier": It does IF you have debug assertions enabled!

<details><summary>Backtrace</summary>

```
llc: /root/build/lib/Target/AVR/AVRGenAsmWriter.inc:1424: static const char* llvm::AVRInstPrinter::getRegisterName(llvm::MCRegister, unsigned int): Assertion `*(AsmStrsptr+RegAsmOffsetptr[RegNo-1]) && "Invalid alt name index for register!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel <source>
1.      Running pass 'Function Pass Manager' on module '<source>'.
2.      Running pass 'AVR Assembly Printer' on function '@main'
 #0 0x0000000003ba9ae8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3ba9ae8)
 #1 0x0000000003ba749c SignalHandler(int) Signals.cpp:0:0
 #2 0x0000780202242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007802022969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x0000780202242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007802022287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000078020222871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x0000780202239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x00000000023ddeda llvm::AVRInstPrinter::printOperand(llvm::MCInst const*, unsigned int, llvm::raw_ostream&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x23ddeda)
 #9 0x00000000023debb3 llvm::AVRInstPrinter::printInst(llvm::MCInst const*, unsigned long, llvm::StringRef, llvm::MCSubtargetInfo const&, llvm::raw_ostream&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x23debb3)
#10 0x000000000323fd02 llvm::MCTargetStreamer::prettyPrintAsm(llvm::MCInstPrinter&, unsigned long, llvm::MCInst const&, llvm::MCSubtargetInfo const&, llvm::raw_ostream&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x323fd02)
#11 0x00000000032a8faa (anonymous namespace)::MCAsmStreamer::emitInstruction(llvm::MCInst const&, llvm::MCSubtargetInfo const&) MCAsmStreamer.cpp:0:0
#12 0x00000000009691c5 (anonymous namespace)::AVRAsmParser::matchAndEmitInstruction(llvm::SMLoc, unsigned int&, llvm::SmallVectorImpl<std::unique_ptr<llvm::MCParsedAsmOperand, std::default_delete<llvm::MCParsedAsmOperand>>>&, llvm::MCStreamer&, unsigned long&, bool) AVRAsmParser.cpp:0:0
#13 0x0000000004bd205a (anonymous namespace)::AsmParser::parseAndMatchAndEmitTargetInstruction((anonymous namespace)::ParseStatementInfo&, llvm::StringRef, llvm::AsmToken, llvm::SMLoc) AsmParser.cpp:0:0
#14 0x0000000004bea616 (anonymous namespace)::AsmParser::parseStatement((anonymous namespace)::ParseStatementInfo&, llvm::MCAsmParserSemaCallback*) (.part.0) AsmParser.cpp:0:0
#15 0x0000000004bdf553 (anonymous namespace)::AsmParser::Run(bool, bool) AsmParser.cpp:0:0
#16 0x0000000002872b2f llvm::AsmPrinter::emitInlineAsm(llvm::StringRef, llvm::MCSubtargetInfo const&, llvm::MCTargetOptions const&, llvm::MDNode const*, llvm::InlineAsm::AsmDialect) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2872b2f)
#17 0x00000000028739d7 llvm::AsmPrinter::emitInlineAsm(llvm::MachineInstr const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x28739d7)
#18 0x000000000286cbe6 llvm::AsmPrinter::emitFunctionBody() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x286cbe6)
#19 0x00000000014923c5 llvm::AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x14923c5)
#20 0x0000000002b263d9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#21 0x00000000031213c0 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31213c0)
#22 0x0000000003121771 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3121771)
#23 0x0000000003122027 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3122027)
#24 0x000000000086aefc compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#25 0x0000000000756ae6 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x756ae6)
#26 0x0000780202229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x0000780202229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x0000000000861c0e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x861c0e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```

</details>

h/t @DianQK
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWU1z2zgS_TXwBSUVCUr8OPhAy9Gsa-OJ10p5j64m2aQwBgEuADrWZX_7FkDSFhVPHGdcU5tyRBEgul8_PDSaEBjDG4l4TtYXZH15Br3dK33-TekHLps_-oILxLNCVYfzr3tuaKkqpDUIYajda9U3e2oVLbgEfRg6seXGcCUJ21Cw9Nuel3vaKS4t5ZbuuTUUJCVxIMRje99LjVDuoRBI4mBJvZMWDtTAI9KD6mmtVUsbtJbLhoI80LrXdo-a8tr1E5Y8IkXpLFTU7pFq3uwt3VzDA9JH0Nz1LElwSYJ8-LyylBvaaVVAIQ60gGpAbvdgqdmrXlTOIdX4B5YWK_oNDhRBC456ZojEwfDnQuF6aLSg3eAKLAg4qN5SEl1SwhgubsJFR6I8jEmUpwueDpfpNmLDNV75az3e1-O9TBfgvhDGZo6s5p3AyQk86kUvH6T6Jqfr84Dhs8KaS6SPileUrIIWuCQsJSyjUFXadFAiYWnoGgiLAkqSi2EgLUGI2UOBe8gbAtNSwyvEusbSUhC8kcZC-eAwGUsJW5HkIiDJpZPFcBf6OzY0MCRsownb_JckF0ZjMzzq7lpslT5MD6ed1VQqKXshKJfWKtdAWMrDmEaJU2NnNWGZs8tT6jCO-I-1NhCSXB4zA9ZqXvQWzRi5ozS5cOgGrhdl1zsQkYMCtsUGIpZ2hDH6YmrSxLHlXFbUdAhuTVFVe1J-rDPvJqdXllYKDb3a-rWwd4uiwqJvKBiD2nIlzSR-wsKZOKNNhRa4MCT6RKKN6dsW9IFEny6gfLDaTWG0IWz70vGqtodbIUqHh7CtVsoSti16LirCtoIXhG2_en4I2-Z3t8Pnbyhz0_5bc4t6yaUbHa6YkzI1FiwvaamksbTcgyYsp24JkSgnUZ7f3V5JY280lxb10NagvcWGG4v6d2id9l6ev95MXW7Ke-kTWuW04aY-ymk-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