Skip to content

Why generate __throw_length_error, __throw_bad_array_new_length in std::vector with -fno-exceptions? #64132

Closed as not planned
@hiraditya

Description

@hiraditya
#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

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.invalidResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions