public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107927] New: vector::push_back gives array bounds warning with optimization and undefined sanitizer
@ 2022-11-30  2:15 larsbj at gullik dot org
  2022-11-30 12:44 ` [Bug tree-optimization/107927] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: larsbj at gullik dot org @ 2022-11-30  2:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107927

            Bug ID: 107927
           Summary: vector::push_back gives array bounds warning with
                    optimization and undefined sanitizer
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: larsbj at gullik dot org
  Target Milestone: ---

Created attachment 53988
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53988&action=edit
Pre-processed source

This looks very similar to Bug 107852, but different to warrant a report imho.

gcc --version
gcc (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)

The preprocessed file has been reduced from something much larger with 
Compiling the pre-processed file with cvise. The seemingly similar test case:

   #include <initializer_list>
   #include <vector>

   struct Foo {
       Foo(std::initializer_list<unsigned> l) : v(l) { v.push_back(5); }
       struct::vector<unsigned> v;
   };

   void make() { Foo{{}}; }

does not exibit the same error as the original or preprocessed code.

g++ g++ -Warray-bounds -O2 -fsanitize=undefined -std=gnu++20 -c test.ii

(note that the original code requires -fsanitize=undefined to fail, the
preprocessed code does not.)

gives:

In function ‘int std::construct_at(_Tp) [with _Tp = unsigned int*]’,
    inlined from ‘static int std::allocator_traits<std::allocator<_Tp>
>::construct(allocator_type, _Up) [with _Up = unsigned int*; _Tp = unsigned
int]’ at :59:17,
    inlined from ‘int std::vector::push_back(int)’ at :114:46,
    inlined from ‘RTCPfeedback::RTCPfeedback(std::initializer_list<unsigned
int>)’ at :128:71,
    inlined from ‘int makeEmptyRR()’ at :131:17:
:4:56: warning: array subscript 1 is outside array bounds of ‘unsigned int [1]’
[-Warray-bounds]
In member function ‘unsigned int* std::__new_allocator::allocate(long int)’,
    inlined from ‘static _Tp* std::allocator_traits<std::allocator<_Tp>
>::allocate(allocator_type, size_type) [with _Tp = unsigned int]’ at :56:24,
    inlined from ‘unsigned int* std::_Vector_base::_M_allocate(long int)’ at
:103:53,
    inlined from ‘void std::vector::_M_range_initialize(_ForwardIterator,
_ForwardIterator, random_access_iterator_tag) [with _ForwardIterator = unsigned
int*]’ at :120:20,
    inlined from ‘std::vector::vector(std::initializer_list<unsigned int>)’ at
:112:24,
    inlined from ‘RTCPfeedback::RTCPfeedback(std::initializer_list<unsigned
int>)’ at :128:53,
    inlined from ‘int makeEmptyRR()’ at :131:17:
:7:48: note: at offset 4 into object of size 4 allocated by ‘operator new’

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-01 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-30  2:15 [Bug libstdc++/107927] New: vector::push_back gives array bounds warning with optimization and undefined sanitizer larsbj at gullik dot org
2022-11-30 12:44 ` [Bug tree-optimization/107927] " rguenth at gcc dot gnu.org
2022-11-30 12:48 ` redi at gcc dot gnu.org
2022-12-01  1:12 ` larsbj at gullik dot org
2022-12-01 14:22 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).