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

    <tr>
        <th>Summary</th>
        <td>
            Clang-18 crash when compiled with -O3 -fsanitize=safe-stack -femulat ed-tls -c
        </td>
    </tr>

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

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

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

<pre>
    Clang-18 with -O3 -fsanitize=safe-stack -femulat ed-tls -c crashes on the test case.
Compiler explorer:[https://godbolt.org/z/T9q7o1bYd](url)
```
$cat mutant.c
extern void _setjmp (void);
typedef struct {
  double real;
  double imag;
} Py_complex;
Py_complex a;
Py_complex fn1();
Py_complex fn2() { return fn1(); }
void fn3() {
 _setjmp();
  a = fn2();
}

$clang-18 -O3 -fsanitize=safe-stack -femulated-tls -c mutant.c
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: clang-18 -O3 -fsanitize=safe-stack -femulated-tls -c mutant.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'mutant.c'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@fn3'
 #0 0x00007fc6a438d266 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd2b266)
 #1 0x00007fc6a438b170 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd29170)
 #2 0x00007fc6a438c8c4 llvm::sys::CleanupOnSignal(unsigned long) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd2a8c4)
 #3 0x00007fc6a42dabb0 (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xc78bb0)
 #4 0x00007fc6aee6e980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007fc6a4b8c079 llvm::SelectionDAG::getGlobalAddress(llvm::GlobalValue const*, llvm::SDLoc const&, llvm::EVT, long, bool, unsigned int) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0x152a079)
 #6 0x00007fc6a4c2cfd8 llvm::TargetLowering::LowerToTLSEmulatedModel(llvm::GlobalAddressSDNode const*, llvm::SelectionDAG&) const (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0x15cafd8)
 #7 0x00007fc6a4a7961b (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0x141761b)
 #8 0x00007fc6a4a78e4c llvm::SelectionDAG::Legalize() (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0x1416e4c)
 #9 0x00007fc6a4bd57b0 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0x15737b0)
#10 0x00007fc6a4bd4b71 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0x1572b71)
#11 0x00007fc6a4bd2cf6 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0x1570cf6)
#12 0x00007fc6a6f6b52f (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0x390952f)
#13 0x00007fc6a4741552 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0x10df552)
#14 0x00007fc6a44d30df llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xe710df)
#15 0x00007fc6a44d8dc3 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xe76dc3)
#16 0x00007fc6a44d37d4 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xe717d4)
#17 0x00007fc6acb7009f 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>>) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1ade09f)
#18 0x00007fc6acf065fe (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e745fe)
#19 0x00007fc6abb22866 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0xa90866)
#20 0x00007fc6ad97a645 clang::FrontendAction::Execute() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x28e8645)
#21 0x00007fc6ad8f8cc4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x2866cc4)
#22 0x00007fc6ad9f51c0 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x29631c0)
#23 0x0000564e4b169837 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-18/bin/clang+0x13837)
#24 0x0000564e4b166905 (/usr/lib/llvm-18/bin/clang+0x10905)
#25 0x00007fc6ad590909 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x24fe909)
#26 0x00007fc6a42da94c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xc7894c)
#27 0x00007fc6ad5902ae clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x24fe2ae)
#28 0x00007fc6ad5580f1 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x24c60f1)
#29 0x00007fc6ad55833e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x24c633e)
#30 0x00007fc6ad57439c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x24e239c)
#31 0x0000564e4b16625c clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-18/bin/clang+0x1025c)
#32 0x0000564e4b173f32 main (/usr/lib/llvm-18/bin/clang+0x1df32)
#33 0x00007fc6a2871c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#34 0x0000564e4b1631ea _start (/usr/lib/llvm-18/bin/clang+0xd1ea)
clang-18: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 18.0.0 (++20231018091808+48a53509e851-1~exp1~20231018091910.1571)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-18: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-18: note: diagnostic msg: /tmp/mutant-701c83.c
clang-18: note: diagnostic msg: /tmp/mutant-701c83.sh
clang-18: note: diagnostic msg: 

********************
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Wktz4yjX_jXKhrILofsiC8WOu3sqPUl1Mv1977txITiyNS2BBlDamcX89reQZFu44-mb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