angr.analyses.decompiler.known_patterns.std_string_internals¶
libstdc++ std::string internals that are not accessors: the SSO test and the two length-setting idioms.
_M_set_length(n) is what every mutating operation ends with. It stores the
new length and re-terminates the buffer:
s->_M_string_length = n;
s->_M_p[n] = '\0';
768K DWARF inline sites across 242 binaries of the -O2 benchmark corpus, third
after the destructor and the SSO test. It is self-guarding because n appears
twice: once as the stored length and once as the offset added to the data
pointer, against a base the two field displacements already pin down.
clear() is the same idiom with n == 0, and is a different pattern: with
no offset to add there is no second occurrence of n to unify on, so the shape
degrades to “zero a word at +8 and a byte through the pointer at +0”. That is a
plausible reset of any pointer-and-count pair, so it is opt-in and corroborated.
_M_is_local() is the SSO test on its own, _M_p == &_M_local_buf, the
same comparison the destructor guards on and capacity() selects on. It is
opt-in for a different reason: wherever it appears as part of one of those, the
larger match wins and this one is redundant; what is left over is the handful of
places where the test stands alone.
Calibrated against tests/x86_64/decompiler/known_patterns_stl5 (g++ 12.2.0 -O2).