Bug 90442 - 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'
Summary: std::pmr::new_delete_resource->allocate results in UBSan error member call on...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 9.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-12 16:29 UTC by Laurynas Biveinis
Modified: 2019-05-12 22:52 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Preprocessed testcase (580 bytes, text/x-csrc)
2019-05-12 16:29 UTC, Laurynas Biveinis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Laurynas Biveinis 2019-05-12 16:29:45 UTC
Created attachment 46344 [details]
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.
Comment 1 Jonathan Wakely 2019-05-12 22:52:05 UTC
The type new_del_res_t is derived from memory_resource, so this is a false positive. UBsan can't see the truth, because src/c++17/memory_resource.o in libstdc++.so is not compiled with -fsanitize=undefined.