[libcxx-commits] [libcxx] [ASan][libc++] Annotating `std::basic_string` with all allocators (PR #75845)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 19 13:14:14 PST 2023


================
@@ -0,0 +1,78 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: asan
+// UNSUPPORTED: c++03
+
+// <string>
+
+// Test based on: https://bugs.chromium.org/p/chromium/issues/detail?id=1419798#c5
+// Some allocators during deallocation may not call destructors and just reuse memory.
----------------
AdvenamTacet wrote:

This test case check a solution to the only known, potential issue with annotating all allocators, situations when memory is repurposed and destructors are not called.
Related issue: https://github.com/llvm/llvm-project/issues/60384

That's the only issue from past, I'm aware of (except bugs). That was addressed here: https://reviews.llvm.org/D145628
And it successfully works in `std::vector` and `std::deque`.

But is it UB? I remember that it's not clear.
Related discussion: https://reviews.llvm.org/D136765#4155262

As pointed out by @AntonBikineev 
> A program may end the lifetime of an object of class type without invoking the destructor, by reusing or releasing the storage as described above[.](https://eel.is/c++draft/basic.life#5.sentence-1)
> [...]
> [Note [4](https://eel.is/c++draft/basic.life#note-4): The correct behavior of a program often depends on the destructor being invoked for each object of class type[.](https://eel.is/c++draft/basic.life#5.sentence-4)
— end note]

Source:  https://eel.is/c++draft/basic.life#6

Therefore, it's not clear if it's UB. But even if it is, we want to make sure that it works that way, because people rely on this behavior.

https://github.com/llvm/llvm-project/pull/75845


More information about the libcxx-commits mailing list