This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix for Bug 23161
ClosedPublic

Authored by eszasip on Apr 9 2015, 6:32 AM.

Details

Reviewers
alexfh
Summary

The misc-static-assert check will not warn on the followings:

  • assert("Some message" == NULL);
  • assert(NULL == "Some message");

Added corresponding test cases.

Bug 23161

Diff Detail

Event Timeline

eszasip updated this revision to Diff 23484.Apr 9 2015, 6:32 AM
eszasip retitled this revision from to [clang-tidy] Fix for Bug 23161.
eszasip updated this object.
eszasip edited the test plan for this revision. (Show Details)
eszasip added a reviewer: alexfh.
eszasip added subscribers: Unknown Object (MLST), xazax.hun.
alexfh added inline comments.Apr 9 2015, 6:54 AM
clang-tidy/misc/StaticAssertCheck.cpp
31

Maybe wrap anyOf in an expr() and use .bind() on it?

ignoringParenImpCasts(
  expr(anyOf(...)).bind("isAlwaysFalse"));
test/clang-tidy/misc-static-assert.cpp
18

Will it work with a more common definition of NULL?

#define NULL ((void*)0)
eszasip updated this revision to Diff 23489.Apr 9 2015, 7:39 AM

The new fix handles the case when NULL is defined as ((T)0), where T is an arbitrary type.
Please tell me, if you think that T should be restricted to void*.

alexfh added inline comments.Apr 9 2015, 8:26 AM
clang-tidy/misc/StaticAssertCheck.cpp
34

I'd say that the cast should be restricted to T*. Also, hasDescendant may be to loose. Isn't has (or has(ignoringParenImpCasts(...)) if needed) enough here?

eszasip updated this revision to Diff 23498.Apr 9 2015, 9:54 AM

The result type of the cast (in the definition of NULL) is restricted to T*.
Also replaced hasDescendant() with has().

alexfh accepted this revision.Apr 9 2015, 10:11 AM
alexfh edited edge metadata.

Looks good! Thanks for the fix!

Should I submit it for you?

This revision is now accepted and ready to land.Apr 9 2015, 10:11 AM
alexfh requested changes to this revision.Apr 9 2015, 10:14 AM
alexfh edited edge metadata.
alexfh added inline comments.
clang-tidy/misc/StaticAssertCheck.cpp
84

Wait, doesn't CastExpr->getType().isPointerType() work?

This revision now requires changes to proceed.Apr 9 2015, 10:14 AM
eszasip updated this revision to Diff 23521.Apr 9 2015, 12:29 PM
eszasip edited edge metadata.

Using built-in method to decide whether the result type is a pointer type.

eszasip added inline comments.Apr 9 2015, 12:43 PM
clang-tidy/misc/StaticAssertCheck.cpp
84

I also searched for a method like this but QualType didn't have such and I haven't looked at Type.

alexfh accepted this revision.Apr 10 2015, 6:15 AM
alexfh edited edge metadata.

Now looks good. Should I commit the patch for you?

This revision is now accepted and ready to land.Apr 10 2015, 6:15 AM
eszasip closed this revision.Apr 10 2015, 7:12 AM

Committed in r234596

Now looks good. Should I commit the patch for you?

Thanks.
I've just got commit access so I can commit my patches from now on.

Awesome! And thanks again for fixing the issue!