[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-09-04 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 163876. mgrang added a comment. Addressed comments. https://reviews.llvm.org/D50488 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/CMakeLists.txt lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-09-04 Thread Whisperity via Phabricator via cfe-commits
whisperity added a project: clang. whisperity added a comment. @Szelethus `clang-query` seems to sometimes not include matcher functions that are perfectly available in the code... I recently had some issue with using `isUserDefined()`, it was available in my code, but `clang-query` always

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-09-04 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment. Minor comments in-line, looking good on first glance. I'm not sure if we discussed, has this checker been tried on some in-the-wild examples? To see if there are some real findings or crashes? There is a good selection of projects here in this tool:

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-21 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment. In https://reviews.llvm.org/D50488#1204655, @mgrang wrote: > In https://reviews.llvm.org/D50488#1203876, @Szelethus wrote: > > > > > > This is my first time with ASTMatchers and I am not sure how to get the > value_type from hasType (I don't see a matcher for

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-17 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added inline comments. Comment at: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp:72-76 + auto IteratesPointerKeysM = hasType(cxxRecordDecl(has( +fieldDecl(hasType(hasCanonicalType( +

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-17 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment. In https://reviews.llvm.org/D50488#1203876, @Szelethus wrote: > I think testcases for non-class iterator objects would be valuable. Thanks @Szelethus. Yes, as you correctly pointed out this would not match non-class iterator objects. This is my first time with

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-17 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added inline comments. Comment at: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp:72-76 + auto IteratesPointerKeysM = hasType(cxxRecordDecl(has( +fieldDecl(hasType(hasCanonicalType( +

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-17 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment. I think testcases for non-class iterator objects would be valuable. Comment at: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp:72-76 + auto IteratesPointerKeysM = hasType(cxxRecordDecl(has( +

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-16 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 161165. mgrang edited the summary of this revision. mgrang added a comment. Added checks for more algorithms: stable_sort, is_sorted, partial_sort, partition, stable_partition, nth_element. https://reviews.llvm.org/D50488 Files:

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-16 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment. This was my first time using AST matchers so it took me a while to figure out how exactly to get this right. clang-query helped a lot. Backspace seems to be a problem with clang-query though. https://reviews.llvm.org/D50488

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-16 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 161152. mgrang added a comment. Changed patch to use AST Matchers. https://reviews.llvm.org/D50488 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/CMakeLists.txt

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment. I guess one of the things the analyzer could find with path-sensitive analysis is direct comparison of non-aliasing pointers. Not only this is non-deterministic, but there's a related problem that comparison for equality would always yield false and is therefore useless.

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-10 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment. Thanks for all your review comments. I will try to address them soon. Meanwhile, I have started an email thread on the general problem of writing checkers/sanitizers to detect non-deterministic behaviors. See

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment. > I'm only a beginner, but here are some things that caught my eye. I really > like the idea! :) Thanks, i appreciate help with reviews greatly. Comment at: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp:93 + const RecordDecl *RD = +

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-10 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov requested changes to this revision. george.karpenkov added a comment. This revision now requires changes to proceed. All the comments above + if anything, should use ASTMatchers. Repository: rC Clang https://reviews.llvm.org/D50488

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-10 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment. The basics of the heuristics look okay as comparing pointers from non-continuous block of memory is undefined, it would be worthy to check if no compiler warning (perhaps by specifying `-W -Wall -Wextra -Weverything` and various others of these enable-all flags!) is

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-10 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment. I'm only a beginner, but here are some things that caught my eye. I really like the idea! :) Comment at: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp:28 + +// PointerSortingVisitor class. +class PointerSortingVisitor : public StmtVisitor {

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-10 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments. Comment at: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp:88 + + if (!II->getName().equals("sort")) +return; Brrr... `equals`. StringRef has a `==` and `!=` operator which accepts string literals on the other side,

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-10 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added inline comments. Comment at: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp:91-100 + const QualType IterTy = CE->getArg(0)->getType(); + const RecordDecl *RD = +IterTy->getUnqualifiedDesugaredType()->getAsCXXRecordDecl(); + + if (RD->field_empty())

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment. Hmm, this might make a good `optin.*` checker. Also i see that this is a pure AST-based checker; did you consider putting this into `clang-tidy`? Like, you shouldn't if you're not using `clang-tidy` yourself (it's a bit messy) but this is an option. Also we're actively

[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-08 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang created this revision. mgrang added reviewers: NoQ, george.karpenkov, whisperity. Herald added subscribers: mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun, mgorny. Repository: rC Clang https://reviews.llvm.org/D50488 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td