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

Umann Kristóf via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 10 03:48:38 PDT 2018


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())
+    return;
+
----------------
NoQ wrote:
> This heuristic ("the argument of `std::sort` is //a class whose first field is of pointer type//") is quite wonky, do you have a plan on how to make it more precise?
```
template< class RandomIt >
void sort( RandomIt first, RandomIt last );
```
Since `RandomIt` must satisfy [[ https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator | RandomAccesIterator ]], maybe you could obtain the value type with `std::iterator_traits<It>::value_type`, and check whether it's a pointer type.


Repository:
  rC Clang

https://reviews.llvm.org/D50488





More information about the cfe-commits mailing list