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

    <tr>
        <th>Summary</th>
        <td>
            Compiler crash when compiling for AVR with -mmcu=avr1
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AVR,
            clang:codegen
      </td>
    </tr>

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

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

<pre>
    ```
int gl_a;

int fn()
{
  return gl_a;
}
```
```
$ ./bin/clang --target=avr -S /tmp/test_add.c -o - -mmcu=avr1
```
```
 .text
.set __tmp_reg__, 0
.set __zero_reg__, 1
.set __SREG__, 63
.set __SP_H__, 62
.set __SP_L__, 61
        .file "test_add.c"
fatal error: error in backend: Cannot select: t4: i16,ch = load<(dereferenceable load (s16) from @gl_a, align 1)> t0, t10, undef:i16
 t10: i16 = WRAPPER TargetGlobalAddress:i16<ptr @gl_a> 0
    t9: i16 = TargetGlobalAddress<ptr @gl_a> 0
  t3: i16 = undef
In function: fn
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: ./bin/clang --target=avr -S /tmp/test_add.c -o - -mmcu=avr1
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '/tmp/test_add.c'.
4.      Running pass 'AVR DAG->DAG Instruction Selection' on function '@fn'
 #0 0x0000aaaabdaacbb4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./bin/clang+0x3715bb4)
 #1 0x0000aaaabdaaa9b0 llvm::sys::RunSignalHandlers() (./bin/clang+0x37139b0)
 #2 0x0000aaaabdaabf10 llvm::sys::CleanupOnSignal(unsigned long) (./bin/clang+0x3714f10)
 #3 0x0000aaaabda1fd54 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
 #4 0x0000aaaabda1fce4 llvm::CrashRecoveryContext::HandleExit(int) (./bin/clang+0x3688ce4)
 #5 0x0000aaaabdaa72f0 llvm::sys::Process::Exit(int, bool) (./bin/clang+0x37102f0)
 #6 0x0000aaaabb5fee18 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>::~IntrusiveRefCntPtr() (./bin/clang+0x1267e18)
 #7 0x0000aaaabda28140 llvm::report_fatal_error(llvm::Twine const&, bool) (./bin/clang+0x3691140)
 #8 0x0000aaaabe92cb20 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (./bin/clang+0x4595b20)
 #9 0x0000aaaabe92bb88 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (./bin/clang+0x4594b88)
#10 0x0000aaaabbfec7bc (anonymous namespace)::AVRDAGToDAGISel::Select(llvm::SDNode*) AVRISelDAGToDAG.cpp:0:0
#11 0x0000aaaabe9224bc llvm::SelectionDAGISel::DoInstructionSelection() (./bin/clang+0x458b4bc)
#12 0x0000aaaabe921570 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (./bin/clang+0x458a570)
#13 0x0000aaaabe91f22c llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (./bin/clang+0x458822c)
#14 0x0000aaaabe91ca84 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (./bin/clang+0x4585a84)
#15 0x0000aaaabe91a4f8 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (./bin/clang+0x45834f8)
#16 0x0000aaaabcfde6ec llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (./bin/clang+0x2c476ec)
<...>
```
Compiler Explorer: https://godbolt.org/z/ePa98xGe1

I see that GCC only supports assembly for this CPU, perhaps that is a sign that codegen here is very difficult?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V11zozoS_TXyS1dcIMDgBz8Q_HFTNXevy56drX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