https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103481
Bug ID: 103481
Summary: asan and ubsan work correctly on windows with clang +
compiler-rt, however, libstdc++ does not correctly
support it
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: unlvsur at live dot com
Target Milestone: ---
Created attachment 51902
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51902&action=edit
use -fsanitize=address,undefined with clang + GCC libstdc++ on windows
#include<vector>
int main()
{
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#endif
#endif
std::vector<int> vec;
vec.reserve(20);
vec.push_back(20);
vec[4]=5;
}
Since libstdc++ detects __SANITIZE_ADDRESS__ not #if
__has_feature(address_sanitizer),
notice that gcc doesn't have __has_feature macro.
-D_GLIBCXX_SANITIZE_STD_ALLOCATOR=1 -D_GLIBCXX_SANITIZE_VECTOR=1
D:\hg\fast_io\examples\0007.legacy>clang++ -o test test.cc -Ofast -std=c++20
-flto -march=native -I../../include -fuse-ld=lld
-D_GLIBCXX_SANITIZE_STD_ALLOCATOR=1 -D_GLIBCXX_SANITIZE_VECTOR=1
-fsanitize=address,undefined
D:\hg\fast_io\examples\0007.legacy>test
=================================================================
==33828==ERROR: AddressSanitizer: container-overflow on address 0x01ceffa06bd0
at pc 0x7ff6223d2b48 bp 0x007a6651f500 sp 0x007a6651f548
This could work without issues.
I suggest to add detection for both __SANITIZE_ADDRESS__ and
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#endif
#endif
This is also exactly what libsanitizer is doing.
https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libsanitizer/include/sanitizer/asan_interface.h
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)