This is an archive of the discontinued LLVM Phabricator instance.

[clang] Ensure that statements, expressions and types are trivially destructible
ClosedPublic

Authored by riccibruno on Aug 23 2019, 5:42 AM.

Details

Summary

Since statements, expressions and types are allocated with the BumpPtrAllocator from ASTContext their destructor is not executed. Two classes are currently exempted from the check : InitListExpr due to its ASTVector and ConstantArrayType due to its APInt.

No functional changes.

Diff Detail

Repository
rL LLVM

Event Timeline

riccibruno created this revision.Aug 23 2019, 5:42 AM

SGTM, but i wonder if this should be done one level up, in BumpPtrAllocator itself?

SGTM, but i wonder if this should be done one level up, in BumpPtrAllocator itself?

I don't understand. BumpPtrAllocator is only used to allocate raw memory and doesn't know anything about how it is going to be used.

SGTM, but i wonder if this should be done one level up, in BumpPtrAllocator itself?

I don't understand. BumpPtrAllocator is only used to allocate raw memory and doesn't know anything about how it is going to be used.

I was looking at SpecificBumpPtrAllocator, which knows it's type.
But if i look down the indirection, i think AllocatorBase::Allocate<T>()/AllocatorBase::Deallocate<T>() is the place.

I was looking at SpecificBumpPtrAllocator, which knows it's type.
But if i look down the indirection, i think AllocatorBase::Allocate<T>()/AllocatorBase::Deallocate<T>() is the place.

I did look at that, but I think it won't work for two reasons:

  1. AST nodes are very often allocated with some trailing objects and so the typed version of Allocate is not used.
  2. It would be difficult to add exceptions as done in this patch. The two exceptions I added are (I think!) latent bugs, but they seem to be relatively harmless (for ConstantArrayType you would need to have an array with a size which do not fit inline in the APInt, and then it would only cause a leak).

In time it would be nice to just remove the two exceptions, but then point 1 still apply.

lebedev.ri accepted this revision.Aug 25 2019, 4:43 AM
lebedev.ri added a subscriber: rsmith.

SGTM but please wait a bit in case @aaron.ballman / @rsmith wants to comment.
Thanks.

This revision is now accepted and ready to land.Aug 25 2019, 4:43 AM
riccibruno retitled this revision from Ensure that statements, expressions and types are trivially destructible with a static_assert to [clang] Ensure that statements, expressions and types are trivially destructible.
gribozavr accepted this revision.Aug 25 2019, 1:34 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 27 2019, 4:52 AM