angr.analyses.decompiler.known_patterns.std_swap

Inlined std::swap, the three-move exchange of two memory locations.

Three statement orders occur, and all three are common:

  • as written, with the second value read inline:

    t = *a;  *a = *b;  *b = t;
    
  • as scheduled, with both loads hoisted, which is what any instruction scheduler produces, and what gcc emits for a struct assignment that swaps field by field:

    t1 = *a;  t2 = *b;  *a = t2;  *b = t1;
    
  • the same, storing in the other order:

    t1 = *a;  t2 = *b;  *b = t1;  *a = t2;
    

    which differs from the previous one with a and b renamed: that renaming also swaps the two loads, so the sequence differs either way round. gcc emits it for consecutive field swaps, where it lets the store to one field sit next to the load of the next.

They cannot share a pattern object, since a statement sequence is one object, so each is its own template. The width is a parameter; see _SWAP_WIDTHS.

The addresses are PField captures rather than bare variables because swapping fields is the usual case (std::swap(lhs.n, rhs.n) inside a move assignment): the address arrives as obj + 8, and the outliner materializes the pointer for the call.

Calibrated against tests/x86_64/decompiler/known_patterns_multiblock (g++ -O2).

angr.analyses.decompiler.known_patterns.std_swap.STD_SWAP = KnownPatternTemplate(call_name='std::swap (1b)', build=<function _make_swap_template.<locals>.build>, arches=frozenset({'AMD64', 'X86'}), languages=frozenset({'cpp'}), runtimes=None, platforms=None, default_enabled=False, name='std_swap_1', gate=None)

the word-sized, as-written spelling, the one the fixture tests