Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 May 2024 22:28:48 +0000
From:      bugzilla-noreply@freebsd.org
To:        toolchain@FreeBSD.org
Subject:   [Bug 279443] LIBCPP assertions are enabled in optimized builds when -DNDEBUG is given to clang
Message-ID:  <bug-279443-29464-CPjtAaJhEI@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-279443-29464@https.bugs.freebsd.org/bugzilla/>
References:  <bug-279443-29464@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D279443

Mark Millard <marklmi26-fbsd@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marklmi26-fbsd@yahoo.com

--- Comment #1 from Mark Millard <marklmi26-fbsd@yahoo.com> ---
I tried the code that is based on:

            std::copy(
                &buf[0],
                &buf[cb], // !!! ASSERTs HERE !!!
                std::back_inserter(r)
            );

via:

# c++ -g get_executable_filename.cpp
# gdb a.out
. . .
Reading symbols from a.out...
(gdb) run
Starting program: /usr/home/root/c_tests/a.out=20

Program received signal SIGILL, Illegal instruction.
Privileged opcode.
0x0000000000203faa in std::__1::vector<char, std::__1::allocator<char>
>::operator[][abi:se180100](unsigned long) (this=3D0x7fffffffe940, __n=3D29=
) at
/usr/include/c++/v1/vector:1393
1393      _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index=
 out
of bounds");

Then I tried that sequence based on:

            std::copy(
                &buf[0],
                //&buf[cb], // !!! ASSERTs HERE !!!
                &buf[0] + cb,=20
                std::back_inserter(r)
            );

# c++ -g get_executable_filename.cpp
# gdb a.out
. . .
Reading symbols from a.out...
(gdb) run
Starting program: /usr/home/root/c_tests/a.out=20
/usr/home/root/c_tests/a.out
[Inferior 1 (process 66199) exited normally]

I'm not so sure that C++ defines &buf[cb] as equivalent to &buf[0] + cb
for std::contiguous_iterator contexts relative to all issues.

cppreference.com reports for std::contiguous_iterator :

QUOTE
Semantic requirements
Let a and b be dereferenceable iterators and c be a non-dereferenceable
iterator of type I such that b is reachable from a and c is reachable from =
b.
The type I models contiguous_iterator only if all the concepts it subsumes =
are
modeled and:
std::to_address(a) =3D=3D std::addressof(*a),
std::to_address(b) =3D=3D std::to_address(a) + std::iter_difference_t<I>(b =
- a),
and
std::to_address(c) =3D=3D std::to_address(a) + std::iter_difference_t<I>(c =
- a).
END QUOTE

&buf[0] + cb notation does avoid any suggestion of dereferencing buf[cb] at
any stage.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-279443-29464-CPjtAaJhEI>