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

    <tr>
        <th>Summary</th>
        <td>
            clang crashes when compiling with a combination of -mx32, -Os and -fno-plt flags
        </td>
    </tr>

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

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

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

<pre>
    Tested clang versions: 14 and 15.
Works again if I replace clang with gcc, or remove any one of the flags -mx32, -Os or -fno-plt.
See below for the minimized test case. The additional files mentioned in the crash log are in an attached tgz, as github does not allow direct upload of those files.
[clang-crash.tar.gz](https://github.com/llvm/llvm-project/files/15379935/clang-crash.tar.gz)

```
$ cat clang-crash.c
#include <unistd.h>

void _start(){
        _exit(42);
}
$ clang -Os -mx32 -nostartfiles -fno-plt -c clang-crash.c
fatal error: error in backend: Cannot select: 0x19ca678: ch,glue = X86ISD::CALL 0x19ca408, 0x19ca5a8, Register:i32 $edi, RegisterMask:Untyped, 0x19ca408:1
  0x19ca5a8: i32,ch = load<(load (s32) from got)> 0x196df28, 0x19ca4d8, undef:i32
    0x19ca4d8: i32 = X86ISD::WrapperRIP TargetGlobalAddress:i32<void (i32)* @_exit> 0 [TF=5]
 0x19ca470: i32 = TargetGlobalAddress<void (i32)* @_exit> 0 [TF=5]
 0x19ca540: i32 = undef
  0x19ca3a0: i32 = Register $edi
  0x19ca610: Untyped = RegisterMask
  0x19ca408: ch,glue = CopyToReg 0x19ca338, Register:i32 $edi, Constant:i32<42>
    0x19ca3a0: i32 = Register $edi
 0x19ca268: i32 = Constant<42>
In function: _start
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 -Os -mx32 -nostartfiles -fno-plt -c clang-crash.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'clang-crash.c'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@_start'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamEi+0x31)[0x7f24a5ad1d01]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm3sys17RunSignalHandlersEv+0xee)[0x7f24a5acfa3e]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm3sys15CleanupOnSignalEm+0xfb)[0x7f24a5ad10ab]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(+0xd6bbea)[0x7f24a59fdbea]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(+0xd6bb8b)[0x7f24a59fdb8b]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm3sys7Process4ExitEib+0x27)[0x7f24a5acc007]
clang[0x4136d2]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm18report_fatal_errorERKNS_5TwineEb+0x113)[0x7f24a5a0c673]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(+0x1660e31)[0x7f24a62f2e31]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm16SelectionDAGISel16SelectCodeCommonEPNS_6SDNodeEPKhj+0x3908)[0x7f24a62f22d8]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(+0x3600c1a)[0x7f24a8292c1a]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm16SelectionDAGISel22DoInstructionSelectionEv+0x19f)[0x7f24a62eaecf]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm16SelectionDAGISel17CodeGenAndEmitDAGEv+0x5c4)[0x7f24a62ea594]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm16SelectionDAGISel20SelectAllBasicBlocksERKNS_8FunctionE+0x1778)[0x7f24a62e99c8]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm16SelectionDAGISel20runOnMachineFunctionERNS_15MachineFunctionE+0x8c7)[0x7f24a62e7557]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(+0x35f7a0d)[0x7f24a8289a0d]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE+0x12e)[0x7f24a5e5828e]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x3a0)[0x7f24a5c0c390]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x33)[0x7f24a5c13983]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x946)[0x7f24a5c0cf36]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang17EmitBackendOutputERNS_17DiagnosticsEngineERKNS_19HeaderSearchOptionsERKNS_14CodeGenOptionsERKNS_13TargetOptionsERKNS_11LangOptionsEN4llvm9StringRefEPNSE_6ModuleENS_13BackendActionESt10unique_ptrINSE_17raw_pwrite_streamESt14default_deleteISK_EE+0xbc1)[0x7f24acdbb201]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(+0x1b7c855)[0x7f24ad0e0855]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang8ParseASTERNS_4SemaEbb+0x244)[0x7f24abf68824]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang13CodeGenAction13ExecuteActionEv+0xb1)[0x7f24ad0dcb71]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang14FrontendAction7ExecuteEv+0x67)[0x7f24ada78b57]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang16CompilerInstance13ExecuteActionERNS_14FrontendActionE+0x336)[0x7f24ad9d03a6]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang25ExecuteCompilerInvocationEPNS_16CompilerInstanceE+0x29b)[0x7f24adaf245b]
clang(_Z8cc1_mainN4llvm8ArrayRefIPKcEES2_Pv+0x99b)[0x41328b]
clang[0x4114bc]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(+0x20eaed2)[0x7f24ad64eed2]
/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm20CrashRecoveryContext9RunSafelyENS_12function_refIFvvEEE+0xdd)[0x7f24a59fdb6d]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang6driver10CC1Command7ExecuteEN4llvm8ArrayRefINS2_8OptionalINS2_9StringRefEEEEEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPb+0x140)[0x7f24ad64e9c0]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang6driver11Compilation14ExecuteCommandERKNS0_7CommandERPS3_+0x3f3)[0x7f24ad619183]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang6driver11Compilation11ExecuteJobsERKNS0_7JobListERN4llvm15SmallVectorImplISt4pairIiPKNS0_7CommandEEEE+0x8a)[0x7f24ad61940a]
/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang6driver6Driver18ExecuteCompilationERNS0_11CompilationERN4llvm15SmallVectorImplISt4pairIiPKNS0_7CommandEEEE+0x1a7)[0x7f24ad633507]
clang(main+0x2816)[0x410f26]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f24a475fd90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f24a475fe40]
clang(_start+0x25)[0x40e3b5]
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Ubuntu clang version 14.0.0-1ubuntu1.1
Target: x86_64-pc-linux-gnux32
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: 
********************

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

********************
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWV1T2zq3_jXmRgNjyd8XXITEoXlLIUPY795n32RkadnRriP5SDIN_fVnJDuBhJ4Ou2mHKViS13rWh561ZFFjRCMBroPkJkhmF7S3G6WvudoKKb7WG_ntolL85foJjAWOWEtlg55BG6GkCaIJwjGikiOcXAXhLAgnfyr91SDaUCGRqNECaehaymB89ZuwG9QwFpApUhpp2KpnQFS-ICUBqRrZDaC6pY1Bl9tdRNy6ywfj1l7WUl12rR0VrQBQBa36hmql_WsO8lZ8B44sGIsYNXCFnjaAKOfCCiVpi2rRgkFbkO4ZOBLSv8o0NRvUqgZRDW6QSkStpWzjpDXfHQxqUCPspq8QV2CQVBbR1unnQgOzqO9aRflggzIwqBrBBsmNt__SK7qyVF8134NkFpB8Y23nPBmQeUDmg4YrprYBmbft8_7XZafVP8BsQOZebkDmOImyooiSgMx_IJsUo-bh_zQcf4ZHEiNGLXr7HttPRUKytueAgmjaS2Esv9oEUflW3LMSHK2NpdoGJHe6spv9fLGGnXDDMXET0X4im73R7XPBxdUHGV1K5YUN0dkHGl2yHyGsqaUtAq2Vdgno_3Ahqyj7CpK7sSmVLjwGWueyaILCHS4YTbPcPbBNQKZN2zsLZ-ivPF2sZi4A0WQ6ubsb18Zh7oI-PCTUPzxCI4wFp1ZEBAUkBi7eTnyh5msQTf6Q9qUD_vq-ExZN8IAfvREaTZDwSc42HozLoCCaBiT3uRSQ3LjpAtVabVGjrHdp6SWkvCZvMMbcP_SSQz0A3KtDb1YMCt8Z_qemXQf6cbFET1Q3YG9bVdF2wrkGY0Zx0dTHPSC5x1wEZIKCOBzi7UChILl5mgfRLHGpPWgfVWfhW9U_1PHr0pP4SPrgg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