[llvm] r252372 - ADT: Require explicit ilist iterator/pointer conversions

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 6 16:02:32 PST 2015


Author: dexonsmith
Date: Fri Nov  6 18:02:32 2015
New Revision: 252372

URL: http://llvm.org/viewvc/llvm-project?rev=252372&view=rev
Log:
ADT: Require explicit ilist iterator/pointer conversions

Disallow implicit conversions between ilist iterators and element
points.  Explicit conversions still work of course.

This is the first step toward removing the undefined behaviour in
`ilist` and `iplist`:
http://lists.llvm.org/pipermail/llvm-dev/2015-October/091115.html

The motivation for removing the implicit iterators is that I came across
real bugs (that were *really* getting lucky).  More details and some
brief discussion later in that thread:
http://lists.llvm.org/pipermail/llvm-dev/2015-October/091617.html

Note: if you have out-of-tree code, it should be fairly easy to revert
this patch downstream while you update your out-of-tree call sites.
Note that these conversions are occasionally latent bugs (that may
happen to "work" now, but only because of getting lucky with UB;
follow-ups will change your luck).  When they are valid, I suggest using
`->getIterator()` to go from pointer to iterator, and `&*` to go from
iterator to pointer.

Modified:
    llvm/trunk/include/llvm/ADT/ilist.h

Modified: llvm/trunk/include/llvm/ADT/ilist.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ilist.h?rev=252372&r1=252371&r2=252372&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ilist.h (original)
+++ llvm/trunk/include/llvm/ADT/ilist.h Fri Nov  6 18:02:32 2015
@@ -220,8 +220,8 @@ private:
   template<class T> void operator-(T) const;
 public:
 
-  ilist_iterator(pointer NP) : NodePtr(NP) {}
-  ilist_iterator(reference NR) : NodePtr(&NR) {}
+  explicit ilist_iterator(pointer NP) : NodePtr(NP) {}
+  explicit ilist_iterator(reference NR) : NodePtr(&NR) {}
   ilist_iterator() : NodePtr(nullptr) {}
 
   // This is templated so that we can allow constructing a const iterator from
@@ -241,7 +241,7 @@ public:
   void reset(pointer NP) { NodePtr = NP; }
 
   // Accessors...
-  operator pointer() const {
+  explicit operator pointer() const {
     return NodePtr;
   }
 




More information about the llvm-commits mailing list