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

    <tr>
        <th>Summary</th>
        <td>
            [clang][ARM] ICE Segmented stacks do not support vararg functions.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    arm 
demo.c
```
#include <stdarg.h>
// #include <stdlib.h>

/* Use a noinline function to ensure that the buffer is not removed
   from the stack.  */
static void use_buffer (char *buf) __attribute__ ((noinline));
static void
use_buffer (char *buf)
{
  buf[0] = '\0';
}

/* When using gold, the call to abort will force a stack split.  */

static void
down (int i, ...)
{
  char buf[1];
 va_list ap;

  va_start (ap, i);
  if (va_arg (ap, int) != 1
 || va_arg (ap, int) != 2
      || va_arg (ap, int) != 3
      || va_arg (ap, int) != 4
      || va_arg (ap, int) != 5
      || va_arg (ap, int) != 6
      || va_arg (ap, int) != 7
      || va_arg (ap, int) != 8
      || va_arg (ap, int) != 9
      || va_arg (ap, int) != 10)
    //abort ();

  if (i > 0)
    {
      use_buffer (buf);
      down (i - 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
 }
}

int
main (void)
{
  down (1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  return 0;
}
```
`clang demo.c -fsplit-stack`

```
fatal error: error in backend: Segmented stacks do not support vararg functions.
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-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -S -target arm-linux-gnueabi --gcc-toolchain=/opt/compiler-explorer/arm/gcc-12.2.0/arm-unknown-linux-gnueabi --sysroot=/opt/compiler-explorer/arm/gcc-12.2.0/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot -fcolor-diagnostics -fno-crash-diagnostics -fsplit-stack <source>
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '<source>'.
4.      Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@down'
 #0 0x00000000034bd4a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x34bd4a8)
 #1 0x00000000034bb5f4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x34bb5f4)
 #2 0x0000000003409cf3 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3409cf3)
 #3 0x00000000034b2ffe llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x34b2ffe)
 #4 0x0000000000c09946 (/opt/compiler-explorer/clang-trunk/bin/clang+0xc09946)
 #5 0x0000000003412d23 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3412d23)
 #6 0x0000000003412e88 (/opt/compiler-explorer/clang-trunk/bin/clang+0x3412e88)
 #7 0x00000000013e8489 llvm::ARMFrameLowering::adjustForSegmentedStacks(llvm::MachineFunction&, llvm::MachineBasicBlock&) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x13e8489)
 #8 0x0000000002a9ac88 (anonymous namespace)::PEI::runOnMachineFunction(llvm::MachineFunction&) PrologEpilogInserter.cpp:0:0
 #9 0x0000000002976f30 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#10 0x0000000002e94f52 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x2e94f52)
#11 0x0000000002e950d1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x2e950d1)
#12 0x0000000002e96d50 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x2e96d50)
#13 0x0000000003729b79 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-trunk/bin/clang+0x3729b79)
#14 0x0000000003cf74f8 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3cf74f8)
#15 0x0000000005af9399 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x5af9399)
#16 0x0000000003cf6705 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x3cf6705)
#17 0x0000000003f75df1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f75df1)
#18 0x0000000003ef3e1b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3ef3e1b)
#19 0x00000000040550e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x40550e3)
#20 0x0000000000c0b6b6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xc0b6b6)
#21 0x0000000000c0410d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#22 0x0000000003d3dd19 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 0x0000000003409bf3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3409bf3)
#24 0x0000000003d3df39 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 0x0000000003d05f37 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x3d05f37)
#26 0x0000000003d068ed clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x3d068ed)
#27 0x0000000003d1065c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3d1065c)
#28 0x0000000000c08ab1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0xc08ab1)
#29 0x0000000000b031f1 main (/opt/compiler-explorer/clang-trunk/bin/clang+0xb031f1)
#30 0x00007fd8ae775083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#31 0x0000000000c0390e _start (/opt/compiler-explorer/clang-trunk/bin/clang+0xc0390e)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
```
https://godbolt.org/z/js35M51o8
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl1z46jS_jXKDWWXBNbXRS4cJ353tmZqUkn2PZcuJCGZDQIdQPnYX38KkGyhODOTjffcnKkZRQG6--Gh6W7BYKVowwm5DOKrIL6-wL3eC3m5EQ-UPxJ5UYjq9RLLFgThdRCuK9KKZenegyQc_rpfIaK8ZH1FQIA2SldYNst9gG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