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

    <tr>
        <th>Summary</th>
        <td>
            Why generate __throw_length_error, __throw_bad_array_new_length  in std::vector with -fno-exceptions?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++
      </td>
    </tr>

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

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

<pre>
    ```cpp
#include<vector>

void f(int);

void use_idx_const_size_resize() {
    std::vector<int> v;
    v.resize(100000);
    auto s = v.size();
    for (std::vector<int>::size_type i = 0; i < s; i++)
 f(v[i]);
}
```

$ clang++ -O3 -stdlib=libc++ -fno-exceptions -std=c++20

```asm
use_idx_const_size_resize():         # @use_idx_const_size_resize()
        push    r14
        push rbx
        sub     rsp, 24
        xorps   xmm0, xmm0
 movaps  xmmword ptr [rsp], xmm0
        mov     qword ptr [rsp + 16], 0
        mov     rdi, rsp
        mov     esi, 100000
        call std::__1::vector<int, std::__1::allocator<int> >::__append(unsigned long)
        mov     rdi, qword ptr [rsp]
        mov     rbx, qword ptr [rsp + 8]
        sub     rbx, rdi
        je      .LBB0_4
 sar     rbx, 2
        cmp     rbx, 1
        adc     rbx, 0
 xor     r14d, r14d
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
        mov     rax, qword ptr [rsp]
 mov     edi, dword ptr [rax + 4*r14]
        call    f(int)@PLT
 inc     r14
        cmp     rbx, r14
        jne     .LBB0_2
 mov     rdi, qword ptr [rsp]
.LBB0_4:
        test    rdi, rdi
 je      .LBB0_6
        mov     qword ptr [rsp + 8], rdi
        call operator delete(void*)@PLT
.LBB0_6:
        add     rsp, 24
 pop     rbx
        pop     r14
        ret
std::__1::vector<int, std::__1::allocator<int> >::__append(unsigned long): # @std::__1::vector<int, std::__1::allocator<int> >::__append(unsigned long)
        push rbp
        push    r15
        push    r14
        push    r13
 push    r12
        push    rbx
        sub     rsp, 24
 mov     r13, rsi
        mov     rbx, rdi
        mov     r15, qword ptr [rdi + 8]
        mov     rax, qword ptr [rdi + 16]
        mov rcx, rax
        sub     rcx, r15
        sar     rcx, 2
        cmp rcx, rsi
        jae     .LBB1_1
        mov     r14, qword ptr [rbx]
        mov     rdi, r15
        sub     rdi, r14
        mov r12, rdi
        sar     r12, 2
        lea     rdx, [r12 + r13]
 mov     rcx, rdx
        shr     rcx, 62
        jne .LBB1_20
        movabs  rcx, 4611686018427387903
        movabs  rsi, 9223372036854775800
        sub     rax, r14
        add     rsi, 4
 mov     rbp, rax
        sar     rbp
        cmp     rbp, rdx
        cmovbe  rbp, rdx
        cmp     rax, rsi
        cmovae rbp, rcx
        test    rbp, rbp
        mov     qword ptr [rsp + 16], rdi       # 8-byte Spill
        je      .LBB1_6
        cmp rbp, rcx
        ja      .LBB1_21
        lea     rdi, [4*rbp]
 call    operator new(unsigned long)@PLT
        mov     rcx, rax
 jmp     .LBB1_9
.LBB1_1:
        test    r13, r13
        je .LBB1_3
        lea     rdx, [4*r13]
        mov     rdi, r15
 xor     esi, esi
        call    memset@PLT
        lea     r15, [r15 + 4*r13]
.LBB1_3:
        mov     qword ptr [rbx + 8], r15
 jmp     .LBB1_19
.LBB1_6:
        xor     ecx, ecx
.LBB1_9:
 mov     qword ptr [rsp], r12            # 8-byte Spill
        lea r12, [rcx + 4*r12]
        mov     qword ptr [rsp + 8], rcx        # 8-byte Spill
        lea     rbp, [rcx + 4*rbp]
        lea     rdx, [4*r13]
        mov     rdi, r12
        xor     esi, esi
 call    memset@PLT
        lea     rax, [r12 + 4*r13]
        mov rdx, r15
        sub     rdx, r14
        je      .LBB1_18
 add     rdx, -4
        cmp     rdx, 76
        jae     .LBB1_12
 mov     rcx, r15
        jmp     .LBB1_17
.LBB1_12:
        mov rsi, qword ptr [rsp + 16]       # 8-byte Reload
        mov     rdi, qword ptr [rsp + 8]        # 8-byte Reload
        add     rsi, rdi
 mov     rcx, r15
        sub     rcx, rsi
        cmp     rcx, 32
        jae     .LBB1_14
        mov     rcx, r15
        jmp .LBB1_17
.LBB1_14:
        shr     rdx, 2
        inc     rdx
 movabs  r9, 9223372036854775800
        and     r9, rdx
        lea rsi, [4*r9]
        sub     r12, rsi
        mov     rcx, r15
 sub     rcx, rsi
        mov     rsi, qword ptr [rsp]            # 8-byte Reload
        lea     rsi, [rdi + 4*rsi]
        add     rsi, -16
        mov     rdi, rdx
        and     rdi, -8
        neg rdi
        xor     r8d, r8d
.LBB1_15:                               # =>This Inner Loop Header: Depth=1
        movups  xmm0, xmmword ptr [r15 + 4*r8 - 32]
        movups  xmm1, xmmword ptr [r15 + 4*r8 - 16]
 movups  xmmword ptr [rsi + 4*r8], xmm1
        movups  xmmword ptr [rsi + 4*r8 - 16], xmm0
        add     r8, -8
        cmp     rdi, r8
 jne     .LBB1_15
        cmp     rdx, r9
        je .LBB1_18
.LBB1_17:                               # =>This Inner Loop Header: Depth=1
        mov     edx, dword ptr [rcx - 4]
        add rcx, -4
        mov     dword ptr [r12 - 4], edx
        add     r12, -4
        cmp     rcx, r14
        jne     .LBB1_17
.LBB1_18:
 mov     qword ptr [rbx], r12
        mov     qword ptr [rbx + 8], rax
        mov     qword ptr [rbx + 16], rbp
        test    r14, r14
        je      .LBB1_19
        mov     rdi, r14
        add rsp, 24
        pop     rbx
        pop     r12
        pop r13
        pop     r14
        pop     r15
        pop     rbp
 jmp     operator delete(void*)@PLT                      # TAILCALL
.LBB1_19:
        add     rsp, 24
        pop     rbx
 pop     r12
        pop     r13
        pop     r14
        pop r15
        pop     rbp
        ret
.LBB1_20:
        mov rdi, rbx
        call    std::__1::vector<int, std::__1::allocator<int> >::__throw_length_error[abi:v180000]() const
.LBB1_21:
        call std::__throw_bad_array_new_length[abi:v180000]()
std::__1::vector<int, std::__1::allocator<int> >::__throw_length_error[abi:v180000]() const: # @std::__1::vector<int, std::__1::allocator<int> >::__throw_length_error[abi:v180000]() const
        push    rax
 lea     rdi, [rip + .L.str]
        call std::__1::__throw_length_error[abi:v180000](char const*)
std::__1::__throw_length_error[abi:v180000](char const*): # @std::__1::__throw_length_error[abi:v180000](char const*)
        push rax
        mov     rsi, rdi
        lea     rdi, [rip + .L.str.1]
 xor     eax, eax
        call std::__1::__libcpp_verbose_abort(char const*, ...)@PLT
std::__throw_bad_array_new_length[abi:v180000](): # @std::__throw_bad_array_new_length[abi:v180000]()
        push    rax
 lea     rdi, [rip + .L.str.2]
        xor     eax, eax
 call    std::__1::__libcpp_verbose_abort(char const*, ...)@PLT
.L.str:
 .asciz  "vector"

.L.str.1:
        .asciz  "length_error was thrown in -fno-exceptions mode with message \"%s\""

.L.str.2:
        .asciz  "bad_array_new_length was thrown in -fno-exceptions mode"
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWluPo74V_zTOi5UIbELgIQ8zkx31L43Uql2pj5EBb8KIAMUkk_l_-soXDPiSZHe6bdFqGeX4HB__ztUnIYyVh5rSLVg_g_VuQc79sem2x7IjRdl_kkXWFJ9bEAfyX962INiB4AkgXNZ5dS4owC8XmvdNB_A3RRP_X5qygD8ASsq6BygF-Nminhndl8V1nzc16_es_JPuO8pfACUApRBsFA-EELK-APgJ4KdhtxcuGH-DFy2aL7ustIgw4M90b76AnPsGMgjwDl5W42azNT-aDgKU-LaUHwp9-8-WwlJICwB-Fn--QCb-BOhZ_EuVYA7GBayfS7DezRDZ7NQfA8xTpACKYF6R-iDFweVfMVyyvqjKDOBdVWb5QPhRN0t6zWnbl03NxCKAd4qM5kKHnQg7yU_u2AJgAYx4AMIQRME9Do0mf9ozO_J3F0YOQpdd55-ycybeHWsBeoHIYLo2Xcv4-3QKOF285YpTcyGcdj2dPpqugG3fQbB-5oI46rO16jk1F_H-l8EAOaphrPg8TF1RciqX76RTJujKF2dLclJVo1vv96HD2dCLYwWpqiYnsyDQXrnfk7aldQFQcq5FbBewarj3pDcPYB6en9q9Pru61guwEotLG1Jy8c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