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

Fail CI builds on compiler warnings + some fixes #6675

Merged
merged 27 commits into from
Sep 2, 2023

Conversation

ricrogz
Copy link
Contributor

@ricrogz ricrogz commented Aug 30, 2023

This causes the Linux and Mac builds to fail if any compiler warnings are raised during the build. We do this by setting the env var CXXFLAGS="-Wall -Werror". This spares C code, as we don't want to fail due to warnings in thirdparty code like Inchi, Avalon or Yaehmop, and there's too many of them...

Note that different compilers/versions raise different warnings, but any supported gcc or clang version should be able to catch the major issues (plus a bunch of annoying stuff like comparing signed vs unsigned). I'm not enabling -Werror on windows because the MSVC compiler is way too zealous...

Besides enabling the flags, this fixes the warnings that are currently showing up in the builds, so that they don't start failing right after we merge this. And then some mem errors too.

@ricrogz ricrogz changed the title Fail CI builds on warnings + some fixes Fail CI builds on compiler warnings + some fixes Aug 30, 2023
@@ -542,7 +542,7 @@ TEST_CASE("single fragment") {
res = rascalMCES(*m1, *m2, opts);
REQUIRE(res.front().getNumFrags() == 1);
REQUIRE(res.front().getBondMatches().size() == std::get<3>(test));
REQUIRE(res.front().getLargestFragSize() ==
REQUIRE(static_cast<unsigned>(res.front().getLargestFragSize()) ==
Copy link
Collaborator

Choose a reason for hiding this comment

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

getLargestFragSize() should only return a positive integer or 0 - it's the number of atoms in a molecule fragment. However, to support lazy evaluation, the member variable in RascalResult is an int initialised to -1. What's the best way of handling that? getLargestFragSize() could return an unsigned int and then this cast will be unnecessary.

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 think we can make getLargestFragSize() return unsigned int. It makes sense, since it returns a size. I can take care of that.

@@ -117,7 +117,7 @@ void sorted_degree_seqs(
}

// Make labels for the atoms - by default the atomic symbol.
void get_atom_labels(const ROMol &mol, const RascalOptions &opts,
void get_atom_labels(const ROMol &mol, const RascalOptions & /* opts */,
Copy link
Collaborator

Choose a reason for hiding this comment

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

opts was passed in here in a particularly poor attempt to support chirality matching in the MCES. When it was pointed out just how wrong it was, I took all the code out. I would like to come back to it again at some point, but in the meantime there is no good reason for it. If you think it would be cleaner, I could take it out for now. It's not, and never will be, in the public API and realistically I may never get round to handle chirality.

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 it's fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Somehow it missed @greglandrum's "get rid of the underscores" purge, and calc_cost immediately below. If you could fix that in this PR that would be cool, otherwise I'll pop one in after this is accepted.

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 fix the underscores, should I also rip out the opt arg, or are thinking we might add the chirality option somewhere in the future? I remove the arg before going for this fix, and it results in chain removal from some other functions too, but it's fine, I just need to bring back those changes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Leave the arg in, I think. It’s a long trek back to the start, and you should probably be spared having to fight through my code like that.

Copy link
Contributor Author

@ricrogz ricrogz Aug 30, 2023

Choose a reason for hiding this comment

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

Oh, it's no problem... like I said, I already did it once, and, exactly because it's a long trek, I though it might be better to leave it in place in case we wanted to implement options later on :)

@@ -40,8 +40,8 @@ struct RDKIT_RASCALMCES_EXPORT RascalOptions {
bool returnEmptyMCES = false; /* if true, if the similarity thresholds aren't
matched still return a RascalResult with the
tier1 and tier2 sims filled in. */
int maxBondMatchPairs = 1000; /* Too many matching bond (vertex) pairs can
cause it to run out of memory. This is a
unsigned maxBondMatchPairs = 1000; /* Too many matching bond (vertex) pairs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we make this explicitly 'unsigned int'? Paolo just spent what I'm sure was a very entertaining time changing all the 'unsigned' to 'unsigned int' in rdFMCS, and it would seem a shame to start the rot again so soon.

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.

@ricrogz ricrogz force-pushed the werror_build branch 2 times, most recently from 361aeb6 to 820bf55 Compare August 31, 2023 19:39
Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

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

two minor suggestions (well, the same thing twice) to simplify a bit

@@ -148,7 +152,8 @@ bool has_query_feature(const ROMol &mol) {
void add_mol_to_elem(bpt::ptree &elem, const ROMol &mol) {
std::string pkl;
MolPickler::pickleMol(mol, pkl);
std::unique_ptr<char> b64(Base64Encode(pkl.c_str(), pkl.length()));
std::unique_ptr<char, charArrayDeleter> b64(
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 this is simpler as:

Suggested change
std::unique_ptr<char, charArrayDeleter> b64(
std::unique_ptr<char[]> b64(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, interesting, I had never used that.

@@ -228,7 +233,8 @@ RWMol *pt_to_mol(bpt::ptree &pt) {
auto b64pkl = pt.get<std::string>("pkl", "");
if (!b64pkl.empty()) {
unsigned int len;
std::unique_ptr<char> cpkl(Base64Decode(b64pkl.c_str(), &len));
std::unique_ptr<char, charArrayDeleter> cpkl(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::unique_ptr<char, charArrayDeleter> cpkl(
std::unique_ptr<char[]> cpkl(

@greglandrum greglandrum added Cleanup Code cleanup and refactoring infrastructure build infrastructure and the like labels Sep 1, 2023
@greglandrum greglandrum added this to the 2023_09_1 milestone Sep 1, 2023
Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

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

One really minor consistency suggestion

unsigned int dummyIdx = mol.addAtom(dummyAt);
bool updateLabel = true;
bool takeOwnwership = true;
unsigned int dummyIdx = mol.addAtom(dummyAt, updateLabel, takeOwnwership);
Copy link
Member

Choose a reason for hiding this comment

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

wow, I'm surprised this leak hasn't been noticed before.
Bad code review on my part when this was merged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was surprised too

Copy link
Collaborator

Choose a reason for hiding this comment

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

Bad code on my part in the first place :-(. It's quite new code, only in the current release I think, so not so much chance for it to show up.
Much as I like developing on a Mac, I really do miss valgrind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have you tried asan?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven’t. I will take a look, thanks.

@@ -102,7 +102,7 @@ TEST_CASE("Small Butina test", "[basics]") {
}
RDKit::RascalMCES::RascalClusterOptions clusOpts;
auto clusters = RDKit::RascalMCES::rascalButinaCluster(mols, clusOpts);
int numMols = 0;
unsigned numMols = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
unsigned numMols = 0;
unsigned int numMols = 0;

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.

auto newMarvinPlus = new MarvinPlus();
rxn.pluses.push_back(
std::move(std::unique_ptr<MarvinPlus>(newMarvinPlus)));
auto &newMarvinPlus = rxn.pluses.emplace_back(new MarvinPlus);
Copy link
Member

Choose a reason for hiding this comment

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

I like this pattern and was somehow not aware of the fact that emplace_back returns something useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's nice. It was added in C++17

@greglandrum
Copy link
Member

@ricrogz : you ready to have this merged?

@ricrogz
Copy link
Contributor Author

ricrogz commented Sep 1, 2023

@ricrogz : you ready to have this merged?

Yeah, as long as it builds correctly

@ricrogz
Copy link
Contributor Author

ricrogz commented Sep 1, 2023

Finally!

Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

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

LGTM

@greglandrum greglandrum merged commit 8176f5c into rdkit:master Sep 2, 2023
10 checks passed
@ricrogz ricrogz deleted the werror_build branch September 2, 2023 03:59
@ricrogz ricrogz mentioned this pull request Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Code cleanup and refactoring infrastructure build infrastructure and the like
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants