Thanks to visit codestin.com
Credit goes to github.com

Skip to content

<vector>: x86 ASAN failure with pmr::monotonic_buffer_resource #3205

@Caball009

Description

@Caball009

Might be related to: #3164

Initializing std::vector + std::pmr::monotonic_buffer_resource causes ASAN to throw an exception in x86 mode under certain conditions.

The following code shows this, but unfortunately I was unable to add ASAN to MSVC in compiler explorer, so instead GCC x86 and x64 were added to show there's no problem there.
https://godbolt.org/z/sM931fbP3
https://godbolt.org/z/vbzEa4cba

The code from the first link for posterity's sake:

#include <array>
#include <iostream>
#include <memory_resource>
#include <vector>

int main()
{
    using T = std::pmr::vector<std::uint8_t>;

    std::array<std::uint8_t, 8192> buffer{};
    std::pmr::monotonic_buffer_resource mbr(buffer.data(), buffer.size(), 
        std::pmr::null_memory_resource());
    
    T vec1(128, &mbr);
    T vec2(128, &mbr);

    std::cout << "So far so good\n";

    T vec3(100, &mbr);
    T vec4(128, &mbr); // <-- asan throws exception here

    std::cout << "All good\n";
}

Visual Studio 2022 versions:

  • v17.4.0, various preview versions (preview 2.1, preview 6)
  • v17.5.0

Notable compiler settings / flags

  • Debug mode
  • x86 (NOT x64)
  • C++17 / C++20
  • Address sanitizer enabled (/fsanitize=address)

NB: ASAN would only thow an exception in x86 mode + Visual Studio 2022. I was unable to reproduce the issue with Visual Studio 2019, neither x86 nor x64 (I don't have a VS2019 version number at hand, but it was quite recent).

Metadata

Metadata

Assignees

No one assigned

    Labels

    ASanAddress SanitizerbugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions