Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not shadow variables (gcc set) #8808

Merged
merged 2 commits into from
Mar 3, 2017

Conversation

paveljanik
Copy link
Contributor

Followup to #8105.

The current set of PRs made clang compile Wshadow clean. Compiling with gcc revealed new needed changes. gcc is more strict in warnings. This is non-Qt part. I do not have an environment to test gcc+Qt build now.

@paveljanik
Copy link
Contributor Author

Hmm, two failures in p2p-segwit.py. Is there some issue with this test script?

@maflcko
Copy link
Member

maflcko commented Sep 26, 2016

Travis fails reliably. Is the commit producing identical binaries?

@paveljanik
Copy link
Contributor Author

This commit should produce same binaries, yes.

@@ -92,7 +92,7 @@ class CBlock : public CBlockHeader
ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int _nVersion) {
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this particular change is causing my clang on OS X build to fail -rescan with:

2016-09-26 19:53:08 ERROR: ReadBlockFromDisk: Deserialize or I/O error - ReadCompactSize(): size too large: unspecified iostream_category error at CBlockDiskPos(nFile=49, nPos=4208853)

So reverting it.

But do not ask me, why it is the cause... I do not know yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I figured this out, see #8658 (comment) and the comment below that.

@laanwj
Copy link
Member

laanwj commented Sep 28, 2016

This introduces binary changes in these serialization functions:

void CDiskBlockIndex::SerializationOp<CDataStream, CSerActionSerialize>(CDataStream&, CSerActionSerialize, int, int)
void CDiskBlockIndex::SerializationOp<CDataStream, CSerActionUnserialize>(CDataStream&, CSerActionUnserialize, int, int)
void CDiskBlockIndex::SerializationOp<CSizeComputer, CSerActionSerialize>(CSizeComputer&, CSerActionSerialize, int, int)
void CMerkleTx::SerializationOp<CDataStream, CSerActionSerialize>(CDataStream&, CSerActionSerialize, int, int)
void CMerkleTx::SerializationOp<CDataStream, CSerActionUnserialize>(CDataStream&, CSerActionUnserialize, int, int)
void CWalletTx::SerializationOp<CDataStream, CSerActionSerialize>(CDataStream&, CSerActionSerialize, int, int)
void CWalletTx::SerializationOp<CDataStream, CSerActionUnserialize>(CDataStream&, CSerActionUnserialize, int, int)

Edit: and in contrast to #8658, these do not go away with -O2

@paveljanik paveljanik force-pushed the 20160925_Wshadow_gcc branch 2 times, most recently from fca66b4 to dd08dc7 Compare October 2, 2016 17:44
@paveljanik
Copy link
Contributor Author

OK, rebased and removed problematic parts (all serialization related, nVersion)...

@paveljanik
Copy link
Contributor Author

Rebased.

@paveljanik
Copy link
Contributor Author

@MarcoFalke Marco, can you please test for the same binaries here?

@maflcko
Copy link
Member

maflcko commented Nov 7, 2016

There seems to be a small diff:

319294c319294
<   17d0f1: lea    0x2dd1b2(%rip),%rdi        # 45a2aa <leveldb::Status::Status(leveldb::Status::Code, leveldb::Slice const&, leveldb::Slice const&)::__PRETTY_FUNCTION__+0xaa>
---
>   17d0f1: lea    0x2dd1b1(%rip),%rdi        # 45a2a9 <leveldb::Status::Status(leveldb::Status::Code, leveldb::Slice const&, leveldb::Slice const&)::__PRETTY_FUNCTION__+0xa9>

used the following command:

commit=416654b4bdcc9f91cf84d4e3c645826d62979c1d && git checkout bitcoin/master && git reset --hard HEAD && curl https://raw.githubusercontent.com/laanwj/bitcoin-maintainer-tools/6e4425587736144b067f67ad792d9ee904e74fd7/patches/stripbuildinfo.patch | patch -p 1 && make -j 2 && objdump -d -r -C --no-show-raw-insn src/bitcoind > /tmp/d_old && curl https://github.com/bitcoin/bitcoin/commit/"${commit}".diff | patch -p 1 && make -j 2 && objdump -d -r -C --no-show-raw-insn src/bitcoind > /tmp/d_new && diff /tmp/d_old /tmp/d_new | wc

@paveljanik
Copy link
Contributor Author

This seems unrelated.

@fanquake
Copy link
Member

fanquake commented Nov 9, 2016

I haven't done the identical binary checking yet, but it looks like the difference could be here ? 170 (0xaa) vs 169 (0xa9)

@paveljanik
Copy link
Contributor Author

@fanquake surely not...

@paveljanik
Copy link
Contributor Author

JFYI: I'm now building with other gcc version and there are a few other warnings 8)

@@ -173,9 +173,9 @@ unsigned int base_uint<BITS>::bits() const
{
for (int pos = WIDTH - 1; pos >= 0; pos--) {
if (pn[pos]) {
for (int bits = 31; bits > 0; bits--) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change _bits to nbits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@maflcko
Copy link
Member

maflcko commented Nov 9, 2016

Concept ACK when this is the last patch/pull with regard to Wshadow.

Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filling up locals with _ prefixes in big pieces of code is less good than using better names, and also incompatible with a common convention of using _prefixes for function parameters.

src/streams.h Outdated
throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed");
} else {
nSrcPos += read;
nSrcPos += _read;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change _read to nBytes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

src/timedata.h Outdated
int size = vSorted.size();
assert(size > 0);
if (size & 1) // Odd number of elements
int _size = vSorted.size();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vecsize

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vSortedSize ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like vSortedSize, will do.

@@ -293,7 +293,7 @@ inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, in
const bool fAllowWitness = !(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS);

READWRITE(*const_cast<int32_t*>(&tx.nVersion));
unsigned char flags = 0;
unsigned char _flags = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sflags (this was less obvious to me, but my suggestion and @sipa thought it was okay)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializeFlags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like both.

@@ -280,17 +280,17 @@ bool CWallet::LoadWatchOnly(const CScript &dest)
bool CWallet::Unlock(const SecureString& strWalletPassphrase)
{
CCrypter crypter;
CKeyingMaterial vMasterKey;
CKeyingMaterial _vMasterKey;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I believe changing the name of CCryptoKeyStore master key will, I think change only four lines. Might be good to get an opinion from someone who's worked more on this code? @TheBlueMatt @pstratem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great and even better solution, yes. Will wait.

@gmaxwell
Copy link
Contributor

gmaxwell commented Nov 9, 2016

I checked each of the changes so far, they appear correct to me (+/- the suggestion I made about changing the name of the member vMasterKey that I asked for others input on). I didn't check that they resulted in the same code.

@paveljanik
Copy link
Contributor Author

paveljanik commented Nov 10, 2016

Rebased, updated.

It is now -Wshadow clean for both old gcc (tested on gcc version 4.8.3 20140627 [gcc-4_8-branch revision 212064](SUSE Linux)) and also on the ultimate gcc (gcc version 6.2.1 20160830 [gcc-6-branch revision 239856](SUSE Linux)). And of course stays clean on other systems I regularly test on.

@maflcko
Copy link
Member

maflcko commented Nov 10, 2016

@paveljanik Mind to cherry-pick fd5654c, so we don't have to open another pull?

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 21, 2019
ad1ae7a Check and enable -Wshadow by default. (Pavel Janík)
9de90bb Do not shadow variables (gcc set) (Pavel Janík)

Tree-SHA512: 9517feb423dc8ddd63896016b25324673bfbe0bffa97f22996f59d7a3fcbdc2ebf2e43ac02bc067546f54e293e9b2f2514be145f867321e9031f895c063d9fb8
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Jan 21, 2019
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 25, 2019
ad1ae7a Check and enable -Wshadow by default. (Pavel Janík)
9de90bb Do not shadow variables (gcc set) (Pavel Janík)

Tree-SHA512: 9517feb423dc8ddd63896016b25324673bfbe0bffa97f22996f59d7a3fcbdc2ebf2e43ac02bc067546f54e293e9b2f2514be145f867321e9031f895c063d9fb8
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Jan 25, 2019
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 29, 2019
ad1ae7a Check and enable -Wshadow by default. (Pavel Janík)
9de90bb Do not shadow variables (gcc set) (Pavel Janík)

Tree-SHA512: 9517feb423dc8ddd63896016b25324673bfbe0bffa97f22996f59d7a3fcbdc2ebf2e43ac02bc067546f54e293e9b2f2514be145f867321e9031f895c063d9fb8
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Jan 29, 2019
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 1, 2019
ad1ae7a Check and enable -Wshadow by default. (Pavel Janík)
9de90bb Do not shadow variables (gcc set) (Pavel Janík)

Tree-SHA512: 9517feb423dc8ddd63896016b25324673bfbe0bffa97f22996f59d7a3fcbdc2ebf2e43ac02bc067546f54e293e9b2f2514be145f867321e9031f895c063d9fb8
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 1, 2019
ad1ae7a Check and enable -Wshadow by default. (Pavel Janík)
9de90bb Do not shadow variables (gcc set) (Pavel Janík)

Tree-SHA512: 9517feb423dc8ddd63896016b25324673bfbe0bffa97f22996f59d7a3fcbdc2ebf2e43ac02bc067546f54e293e9b2f2514be145f867321e9031f895c063d9fb8
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Feb 1, 2019
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 1, 2019
ad1ae7a Check and enable -Wshadow by default. (Pavel Janík)
9de90bb Do not shadow variables (gcc set) (Pavel Janík)

Tree-SHA512: 9517feb423dc8ddd63896016b25324673bfbe0bffa97f22996f59d7a3fcbdc2ebf2e43ac02bc067546f54e293e9b2f2514be145f867321e9031f895c063d9fb8
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants