[llvm] 75c86c9 - Support: Make VarStreamArrayIterator iterate over const values

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 12 20:37:56 PST 2021


Author: Duncan P. N. Exon Smith
Date: 2021-11-12T20:37:36-08:00
New Revision: 75c86c9935925f841c1c4e0396b701210358489a

URL: https://github.com/llvm/llvm-project/commit/75c86c9935925f841c1c4e0396b701210358489a
DIFF: https://github.com/llvm/llvm-project/commit/75c86c9935925f841c1c4e0396b701210358489a.diff

LOG: Support: Make VarStreamArrayIterator iterate over const values

VarStreamArrayIterator returns a reference to a just-computed internal
value. Change it to iterate over `const ValueType` to avoid allowing
clients to mutate the internal state, and to drop the
non-`const`-qualified operator*().

The removed operator*() was from 175d70ee5c2f03f6 to get
iterator_facade_base::operator->() working, and this fixes the root
cause instead: setting `T` to `const ValueType` causes
iterator_facade_base to infer `PointerT` as `const ValueType*`.

Ironically, this is the last blocker for removing the const-incorrect
overload of `iterator_facade_base::operator->()`, whose presence
triggered adding the workaround in the first place :).

Differential Revision: https://reviews.llvm.org/D113797

Added: 
    

Modified: 
    llvm/include/llvm/Support/BinaryStreamArray.h
    llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/BinaryStreamArray.h b/llvm/include/llvm/Support/BinaryStreamArray.h
index 148ab85169f28..85d29be26ca96 100644
--- a/llvm/include/llvm/Support/BinaryStreamArray.h
+++ b/llvm/include/llvm/Support/BinaryStreamArray.h
@@ -153,7 +153,7 @@ class VarStreamArray {
 template <typename ValueType, typename Extractor>
 class VarStreamArrayIterator
     : public iterator_facade_base<VarStreamArrayIterator<ValueType, Extractor>,
-                                  std::forward_iterator_tag, ValueType> {
+                                  std::forward_iterator_tag, const ValueType> {
   typedef VarStreamArrayIterator<ValueType, Extractor> IterType;
   typedef VarStreamArray<ValueType, Extractor> ArrayType;
 
@@ -197,11 +197,6 @@ class VarStreamArrayIterator
     return ThisValue;
   }
 
-  ValueType &operator*() {
-    assert(Array && !HasError);
-    return ThisValue;
-  }
-
   IterType &operator+=(unsigned N) {
     for (unsigned I = 0; I < N; ++I) {
       // We are done with the current record, discard it so that we are

diff  --git a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
index 3d2490509c03e..b631bdf8f2b1c 100644
--- a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
@@ -373,7 +373,7 @@ static void explainDbiModiSubstreamOffset(LinePrinter &P, DbiStream &Dbi,
     ++Index;
   }
 
-  DbiModuleDescriptor &Descriptor = *Prev;
+  const DbiModuleDescriptor &Descriptor = *Prev;
   P.formatLine("which contains the descriptor for module {0} ({1}).", Index,
                Descriptor.getModuleName());
 }


        


More information about the llvm-commits mailing list