[libcxx-commits] [libcxx] [libc++][hardening] Add a bounds check for `valarray` and `bitset`. (PR #120685)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Dec 20 12:01:01 PST 2024
================
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <bitset>
+
+// Test hardening assertions for std::bitset using ABI v1 (where the const overload of `operator[]` returns
----------------
ldionne wrote:
I think the way we'd normally do it is:
```c++
int main() {
#if _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
// test for this ABI
#else
// test for the normal ABI
#endif
}
```
That would be in a single test file. In practice, the second ABI setting is tested by our CI job that enables the ABI v2.
Enabling `-D_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL=1` on the command-line is technically incorrect because we'd need to ensure that the dylib is also built with that configuration. In general, these ABI settings shouldn't be tweaked on a per-TU basis (just like we tell our users!). In practice it probably works because the dylib isn't affected by `std::bitset`'s ABI, but we shouldn't rely on that.
https://github.com/llvm/llvm-project/pull/120685
More information about the libcxx-commits
mailing list