[PATCH] D154581: [clang][Interp] Track existing InitMaps in InterpState

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 6 01:53:07 PDT 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, cor3ntin, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

InitMaps are created for primitive arrays when the first element of the arrays is initialized, and they are free'd when the last element is initialized, leaving the array in a fully initialized state.

The initmap is also free'd in the `Descriptor`'s destructor function, which is called at the end of a scope.

This works fine when the execution of the program is not interrupted. However, when it is, we never destroy the scopes, leaving the initmaps behind.

To fix this, track the initmaps in `InterpState` and free them manually in `~InterpState()`, so we don't leak the memory and fail on LSan enabled builders.

(Side note: There is a similar problem with the current handling of floating point numbers, i.e. the `APFloat` might heap allocate some memory and we will leak this when the execution is interrupted).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154581

Files:
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Descriptor.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBlock.h
  clang/lib/AST/Interp/InterpState.cpp
  clang/lib/AST/Interp/InterpState.h
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/test/AST/Interp/arrays.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154581.537624.patch
Type: text/x-patch
Size: 12334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230706/46fced63/attachment-0001.bin>


More information about the cfe-commits mailing list