[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes. Closed by commit rC337470: [Sema] Add a new warning, -Wmemset-transposed-args (authored by epilk, committed by ). Changed prior to commit: https://reviews.llvm.org/D49112?vs=156178&id=156298#toc Repository: rC Clang h

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision. aaron.ballman added a comment. LGTM aside from a minor nit. Comment at: clang/lib/Sema/SemaChecking.cpp:8751 + + if (auto *BO = dyn_cast(SizeofExpr)) { +if (BO->getOpcode() != BO_Mul && BO->getOpcode() != BO_Add) `cons

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-18 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments. Comment at: clang/lib/Sema/SemaChecking.cpp:7984 + if (isa(ThirdArg) && + cast(ThirdArg)->getValue() == 0) { +WarningKind = 0; Quuxplusone wrote: > > Suppress the diagnostic in cases like `memset(ptr, 0xff, PADDING

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-18 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 156178. erik.pilkington marked 5 inline comments as done. erik.pilkington added a comment. This revision is now accepted and ready to land. In this new patch: - Add support for __builtin_bzero (-Wsuspicious-bzero), improve diagnostics for platforms t

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments. Comment at: clang/lib/Sema/SemaChecking.cpp:7975-7976 +static void CheckMemsetSizeof(Sema &S, unsigned BId, const CallExpr *Call) { + if (BId != Builtin::BImemset) +return; + erik.pilkington wrote: > aaron.ballman wrote:

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-17 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments. Comment at: clang/lib/Sema/SemaChecking.cpp:7984 + if (isa(ThirdArg) && + cast(ThirdArg)->getValue() == 0) { +WarningKind = 0; > Suppress the diagnostic in cases like `memset(ptr, 0xff, PADDING)`, when > `PADDING` is

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-17 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington planned changes to this revision. erik.pilkington added a comment. In https://reviews.llvm.org/D49112#1158793, @thakis wrote: > lgtm assuming you ran this on some large code base to make sure it doesn't > have false positives. Sorry for the delay here, I was running this on som

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-13 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments. Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:662 +def note_suspicious_sizeof_memset_silence : Note< + "%select{parenthesize the third argument|cast the second argument to 'int'}0 to silence">; + aaron.ballman w

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments. Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:662 +def note_suspicious_sizeof_memset_silence : Note< + "%select{parenthesize the third argument|cast the second argument to 'int'}0 to silence">; + erik.pilkingt

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-11 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision. thakis added a comment. This revision is now accepted and ready to land. lgtm assuming you ran this on some large code base to make sure it doesn't have false positives. Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:659 +def warn_s

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-10 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments. Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:662 +def note_suspicious_sizeof_memset_silence : Note< + "%select{parenthesize the third argument|cast the second argument to 'int'}0 to silence">; + Quuxplusone

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-10 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 154833. erik.pilkington added a comment. Address @Quuxplusone comments. https://reviews.llvm.org/D49112 Files: clang/include/clang/Basic/DiagnosticGroups.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaChecking.cpp cla

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-09 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments. Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:662 +def note_suspicious_sizeof_memset_silence : Note< + "%select{parenthesize the third argument|cast the second argument to 'int'}0 to silence">; + If it were my c

[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

2018-07-09 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision. erik.pilkington added reviewers: rsmith, aaron.ballman, arphaman. Herald added a subscriber: dexonsmith. This warning tries to catch programs that incorrectly call memset with the second and third arguments transposed, ie `memset(ary, sizeof(ary), 0)` instea