Skip to content

Commit

Permalink
Bug 1806779 - Fix C++20 -Wdeprecated-volatile warnings in mfbt/SHA1.c…
Browse files Browse the repository at this point in the history
…pp. r=glandium

C++20 deprecated decrement/increment of object of volatile-qualified types, e.g. v++.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1152r3.html

mfbt/SHA1.cpp:400:9 [-Wdeprecated-volatile] compound assignment to object of volatile-qualified type 'volatile unsigned int' is deprecated
mfbt/SHA1.cpp:401:9 [-Wdeprecated-volatile] compound assignment to object of volatile-qualified type 'volatile unsigned int' is deprecated
mfbt/SHA1.cpp:402:9 [-Wdeprecated-volatile] compound assignment to object of volatile-qualified type 'volatile unsigned int' is deprecated
mfbt/SHA1.cpp:403:9 [-Wdeprecated-volatile] compound assignment to object of volatile-qualified type 'volatile unsigned int' is deprecated
mfbt/SHA1.cpp:404:9 [-Wdeprecated-volatile] compound assignment to object of volatile-qualified type 'volatile unsigned int' is deprecated

shaCompress() has a comment emphasizing the importance of the X array being volatile. I verified that changing `XH(0) += A` to `XH(0) = XH(0) + A` generates the same -S assembly code (for clang -O2 on Apple Silicon).

Whether this comment about the volatile code generated by gcc 3.4.3 -O3 in 2012 is still relevant for clang 15 -O2 in 2023 is a different question.

Differential Revision: https://phabricator.services.mozilla.com/D165268
  • Loading branch information
cpeterso committed Dec 22, 2022
1 parent 24af801 commit a600dbe
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mfbt/SHA1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,9 @@ static void shaCompress(volatile unsigned* aX, const uint32_t* aBuf) {
SHA_MIX(15, 12, 7, 1);
SHA_RND4(A, B, C, D, E, 15);

XH(0) += A;
XH(1) += B;
XH(2) += C;
XH(3) += D;
XH(4) += E;
XH(0) = XH(0) + A;
XH(1) = XH(1) + B;
XH(2) = XH(2) + C;
XH(3) = XH(3) + D;
XH(4) = XH(4) + E;
}

0 comments on commit a600dbe

Please sign in to comment.