Commit ee79874
merge-recursive: silence -Wxor-used-as-pow warning
The merge-recursive code uses stage number constants like this:
add = &ci->ren1->dst_entry->stages[2 ^ 1];
...
add = &ci->ren2->dst_entry->stages[3 ^ 1];
The xor has the effect of flipping the "1" bit, so that "2 ^ 1" becomes
"3" and "3 ^ 1" becomes "2", which correspond to the "ours" and "theirs"
stages respectively.
Unfortunately, clang-10 and up issue a warning for this code:
merge-recursive.c:1759:40: error: result of '2 ^ 1' is 3; did you mean '1 << 1' (2)? [-Werror,-Wxor-used-as-pow]
add = &ci->ren1->dst_entry->stages[2 ^ 1];
~~^~~
1 << 1
merge-recursive.c:1759:40: note: replace expression with '0x2 ^ 1' to silence this warning
We could silence it by using 0x2, as the compiler mentions. Or by just
using the constants "2" and "3" directly. But after digging into it, I
do think this bit-flip is telling us something. If we just wrote:
add = &ci->ren2->dst_entry->stages[2];
for the second one, you might think that "ren2" and "2" correspond. But
they don't. The logic is: ren2 is theirs, which is stage 3, but we
are interested in the opposite side's stage, so flip it to 2.
So let's keep the bit-flipping, but let's also put it behind a named
function, which will make its purpose a bit clearer. This also has the
side effect of suppressing the warning (and an optimizing compiler
should be able to easily turn it into a constant as before).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>1 parent a0ba800 commit ee79874
1 file changed
+14
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1712 | 1712 | | |
1713 | 1713 | | |
1714 | 1714 | | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
1715 | 1724 | | |
1716 | 1725 | | |
1717 | 1726 | | |
| |||
1756 | 1765 | | |
1757 | 1766 | | |
1758 | 1767 | | |
1759 | | - | |
| 1768 | + | |
1760 | 1769 | | |
1761 | 1770 | | |
1762 | 1771 | | |
1763 | 1772 | | |
1764 | 1773 | | |
1765 | 1774 | | |
1766 | | - | |
| 1775 | + | |
1767 | 1776 | | |
1768 | 1777 | | |
1769 | 1778 | | |
| |||
1776 | 1785 | | |
1777 | 1786 | | |
1778 | 1787 | | |
1779 | | - | |
| 1788 | + | |
1780 | 1789 | | |
1781 | 1790 | | |
1782 | 1791 | | |
| |||
1797 | 1806 | | |
1798 | 1807 | | |
1799 | 1808 | | |
1800 | | - | |
| 1809 | + | |
1801 | 1810 | | |
1802 | 1811 | | |
1803 | 1812 | | |
| |||
1846 | 1855 | | |
1847 | 1856 | | |
1848 | 1857 | | |
1849 | | - | |
| 1858 | + | |
1850 | 1859 | | |
1851 | 1860 | | |
1852 | 1861 | | |
| |||
0 commit comments