This is an archive of the discontinued LLVM Phabricator instance.

Improved checking for repeated macro argument with side effects when macro contains ?:
ClosedPublic

Authored by danielmarjamaki on Jun 23 2015, 7:25 AM.

Details

Reviewers
alexfh
Summary

This patch fixes possible false negatives when macro contains ?:.

I tested this improvemed checker on 1398 open source projects, but did not see any new warnings.. At least that means that it did not cause any new false positives even though it does fix the false negatives that are shown in the testing.

Question: Is it a good idea to use std::stack or would some other container be better in clang-tidy?

Diff Detail

Event Timeline

danielmarjamaki retitled this revision from to Improved checking for repeated macro argument with side effects when macro contains ?:.
danielmarjamaki updated this object.
danielmarjamaki edited the test plan for this revision. (Show Details)
danielmarjamaki added a reviewer: alexfh.
danielmarjamaki added a subscriber: Unknown Object (MLST).
alexfh edited edge metadata.Jun 23 2015, 8:23 AM

Question: Is it a good idea to use std::stack or would some other container be better in clang-tidy?

You can try to use std::stack<unsigned, SmallVector<unsigned, 8>> to avoid heap allocation in most cases.

clang-tidy/misc/MacroRepeatedSideEffectsCheck.cpp
126–127

I guess, the main use case is __builtin_constant_p which doesn't evaluate its argument? Maybe specifically check for it? Or at least this needs some more explanation.

danielmarjamaki edited edge metadata.

I have refactored my patch.

  • I added more comments.
  • now the handling of __builtin_constant_p is more explicit.
  • I changed uppercase=>lowercase in two functionnames in accordance with the llvm style guide.

I have rerun the patch on various projects to make sure that the more explicit handling of builtins don't cause false positives.

alexfh accepted this revision.Jul 1 2015, 7:48 AM
alexfh edited edge metadata.

LG with a couple of comments.

clang-tidy/misc/MacroRepeatedSideEffectsCheck.cpp
93

nits:

  • s/result from/result of/
  • "If we have seen a __builtin_constant_p(x) and then there is a ..." - "If we see __builtin_constant_p(x) followed by a ..."
  • add a comma before "then we need to reason about ..."
  • s/bailout/bail out/
127

nits:

  • dont -> don't
  • argument -> arguments
This revision is now accepted and ready to land.Jul 1 2015, 7:48 AM

This was committed in r241245