Skip to content

Commit 75efddb

Browse files
author
Tacet
authored
[ASan][libc++] Initialize __r_ variable with lambda (#77394)
This commit is a refactor (increases readability) and optimization fix. This is a fixed commit of #76200 First reverthed here: 1ea7a56 Please, check original PR for details. The difference is a return type of the lambda. Original description: This commit addresses optimization and instrumentation challenges encountered within comma constructors. 1) _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS does not work in comma constructors. 2) Code inside comma constructors is not always correctly optimized. Problematic code examples: - `: __r_(((__str.__is_long() ? 0 : (__str.__annotate_delete(), 0)), std::move(__str.__r_))) {` - `: __r_(__r_([&](){ if(!__s.__is_long()) __s.__annotate_delete(); return std::move(__s.__r_);}())) {` However, lambda with argument seems to be correctly optimized. This patch uses that fact. Use of lambda based on idea from @ldionne.
1 parent e7f7948 commit 75efddb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libcxx/include/string

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ public:
922922
// Turning off ASan instrumentation for variable initialization with _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
923923
// does not work consistently during initialization of __r_, so we instead unpoison __str's memory manually first.
924924
// __str's memory needs to be unpoisoned only in the case where it's a short string.
925-
: __r_(((__str.__is_long() ? 0 : (__str.__annotate_delete(), 0)), std::move(__str.__r_))) {
925+
: __r_([](basic_string &__s) -> decltype(__s.__r_)&& { if(!__s.__is_long()) __s.__annotate_delete(); return std::move(__s.__r_); }(__str)) {
926926
__str.__r_.first() = __rep();
927927
__str.__annotate_new(0);
928928
if (!__is_long())

0 commit comments

Comments
 (0)