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

            Bug ID: 90442
           Summary: std::pmr::new_delete_resource->allocate results in
                    UBSan error member call on address ... which does not
                    point to an object of type 'memory_resource'
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: laurynas.biveinis at gmail dot com
  Target Milestone: ---

Created attachment 46344
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46344&action=edit
Preprocessed testcase

The following results in an UBSan error:

#include <memory_resource>

int main(void) {
  auto * const mem = std::pmr::new_delete_resource()->allocate(10);
}

compiled with g++-9 pmr_san.cpp -fsanitize=undefined -std=c++17 -o pmr_san
results in

../gcc-9/pmr_san2.cpp:4:63: runtime error: member call on address
0x00010752d440 which does not point to an object of type 'memory_resource'
0x00010752d440: note: object is of type '*NSt3pmr12_GLOBAL__N_112newdel_res_tE'
 01 00 00 00  c8 7e 51 07 01 00 00 00  00 00 00 00 00 00 00 00  e0 ee 50 07 01
00 00 00  98 ee 50 07
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for '*NSt3pmr12_GLOBAL__N_112newdel_res_tE'
/usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/memory_resource:99:25: runtime
error: member call on address 0x00010752d440 which does not point to an object
of type 'memory_resource'
0x00010752d440: note: object is of type '*NSt3pmr12_GLOBAL__N_112newdel_res_tE'
 01 00 00 00  c8 7e 51 07 01 00 00 00  00 00 00 00 00 00 00 00  e0 ee 50 07 01
00 00 00  98 ee 50 07
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for '*NSt3pmr12_GLOBAL__N_112newdel_res_tE'

I am not sure whether this is a libstdc++ or UBSan bug (or if I am doing
something wrong). I am attaching a preprocessed version too.

This looks similar to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80963,
triggered by Boost implementation of PMR.

Reply via email to