[PATCH] D26718: [llvm] Iterate SmallPtrSet in reverse order to uncover non-determinism in codegen

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 28 11:47:25 PST 2016


> On Nov 28, 2016, at 11:40 AM, Chandler Carruth <chandlerc at gmail.com> wrote:
> 
> Hash functions of *pointers* cannot be consistent in the face of ASLR.

I was answering the fact that “it cannot be tested”. So I meant, for the purpose of writing a unittest that checks if you can pass a flag that reverse the iteration order, I don’t expect that you need *valid* pointers.

What I had in mind is something along these lines (I haven’t looked at the patch either):

SmallPtrSet<void *, 4> Set;
void *Ptrs[] = { (void *)0x1, (void *)0x2, (void *)0x3,(void *)0x4 };
void *ExpectedExperimentalOrder[] = { (void *)0x4, (void *)0x2, (void *)0x3,(void *)0x1 };

for (auto *Ptr : Ptrs) 
  Set.insert(Ptr);

for (auto &Tuple : zip(Set, ExpectedExperimentalOrder)) 
  ASSERT_EQ(std::get<0>(Tuple), std::get<1>(Tuple));

Set.setReverseIterationOrder();

for (auto &Tuple : zip(Set, reverse_order(ExpectedExperimentalOrder))) 
  ASSERT_EQ(std::get<0>(Tuple), std::get<1>(Tuple));


— 
Mehdi


> 
> But really, hash functions shouldn't be assumed to be consistent. They'll be deterministic only within a single execution of the program. If we want the freedom to change hash functions in the future we need people to not rely on their particulars.
> 
> And even worse, hash *tables* are less consistent if you ever want to change the rebucketing thresholds.
> 
> On Mon, Nov 28, 2016 at 10:57 AM Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote:
> Why is it “undefined"? I thought it is dependent on the order of insertion and the hash function, which should be deterministic and consistent.
> 
> 
> > On Nov 22, 2016, at 12:10 PM, Mandeep Singh Grang <mgrang at codeaurora.org <mailto:mgrang at codeaurora.org>> wrote:
> >
> > mgrang added a comment.
> >
> > Note: There are no associated tests with this patch as it is very difficult (not possible?) to detect "reverse" iteration since the relative order of elements in the SmallPtrSet is always undefined.
> > I would be happy to write tests for this if someone can suggest a good way of testing it. Otherwise the biggest test for this is to enable it in the buildbot and let the unit tests fail due to non-deterministic codegen.
> >
> >
> > Repository:
> >  rL LLVM
> >
> > https://reviews.llvm.org/D26718 <https://reviews.llvm.org/D26718>
> >
> >
> >
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161128/a5cd44f5/attachment.html>


More information about the llvm-commits mailing list