This is an archive of the discontinued LLVM Phabricator instance.

SmallVector fix for use-after-dtor bug.
AbandonedPublic

Authored by nmusgrave on Sep 18 2015, 10:04 AM.

Details

Reviewers
eugenis
Summary

Fix for use-after-dtor bug in SmallVector. Circular dependency in class hierarchy:

SmallVector contains a SmallVectorStorage member.
This member is never explicitly referenced, but removing it results in major
test failures.
SmallVectorStorage contains a SmallVectorTemplateCommon member, which SmallVector
is also a subclass of.

This fix resolves some of the issues, but there are still failures arising
in connection with SmallVector.

Diff Detail

Event Timeline

nmusgrave updated this revision to Diff 35098.Sep 18 2015, 10:04 AM
nmusgrave retitled this revision from to SmallVector fix. Some tests still failing. Not sure this is right approach for fixing circular dependency that gives use-after-dtor bug..
nmusgrave updated this object.
nmusgrave added a reviewer: eugenis.
nmusgrave added a subscriber: llvm-commits.
nmusgrave retitled this revision from SmallVector fix. Some tests still failing. Not sure this is right approach for fixing circular dependency that gives use-after-dtor bug. to SmallVector fix for use-after-dtor bug..Sep 18 2015, 10:07 AM
nmusgrave updated this object.

We try to keep as much code in the Impl rather than the SmallVector itself to reduce template code bloat.

Could you explain in more detail what the circular dependency/use-after-dtor issue is? Which entity's dtor is ~SmallVectorImpl using inappropriately?

eugenis edited edge metadata.Sep 18 2015, 3:13 PM

The problem is this:
SmallVectorTemplateCommon only has space for the first element of the vector; the rest of the space is provided by SmallVector and used by effectively overflowing the field SmallVectorTemplateCommon. Sanitizers are OK with it because the memory is, in fact, allocated.

Use-after-destroy detector complains about ~SmallVectorTemplateCommon accessing memory that belongs to SmallVector (the destructor for that has already ran at the point) when calling destructors for individual vector elements in destroy_range.

dblaikie added inline comments.Sep 18 2015, 5:05 PM
include/llvm/ADT/SmallVector.h
926

This is different from the original code, why?

I assume this would introduce a bug where in big-mode it doesn't call the dtors on the elements of the vector?

nmusgrave abandoned this revision.Sep 18 2015, 9:56 PM