Skip to content

Commit c68a9d2

Browse files
author
Tacet
authored
[ASan][libc++] String annotations optimizations fix with lambda (#76200)
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. The patch employs this. Use of lambda based on an idea from @ldionne.
1 parent 0e7199c commit c68a9d2

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){ 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)