Bug 1806779 - Fix C++20 -Wdeprecated-volatile warnings in mfbt/SHA1.cpp. 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
This commit is contained in:
Chris Peterson 2022-12-22 02:58:24 +00:00
Родитель f5fbaa9482
Коммит 975ea3bc1e
1 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -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;
}