[clang] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early (PR #73096)

Qizhi Hu via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 23 00:36:46 PST 2023


jcsxky wrote:

> > Debug the #72783 can prove it. Address interval (local from 0x3a9a00 to 0x3aaa00) allocated by allocator contains a IdentifierInfo variable (local address:0x3aa190) whose address is freed early.
> 
> In this case, it looks better to extract the use-after-free variable only instead of extracting the whole ASTUnit.

- From my local debugging, it's a `IdentifierInfo` type variable which is freed by allocator. The variable is subnode of AST. Thanks to `ASTUnit` is out of scope, some related memory is freed (which is allocated by `SpecificBumpPtrAllocator`) as destructor called and we can't extract only `IdentifierInfo` type variable.


> 
> > As system header like stdio.h or math.h can't be put into test, it's hard to add testcase. Could anyone give me some guidance? Thanks in advance!
> 
> Generally, we need to reduce them in this case. e.g., we need to preprocess them, and remove unncessary parts until we can't. It is time consuming but it is worthy.

- Small piece of code can't reproduce the crash. The crash is caused by growing of size of `OnDiskChainedHashTableGenerator` when add `IdentifierInfo` type variable. As mentioned in the [issue](https://github.com/llvm/llvm-project/issues/72783), when remove header file, it runs OK. Small-scale code wouldn't cause resize of `OnDiskChainedHashTableGenerator`


https://github.com/llvm/llvm-project/pull/73096


More information about the cfe-commits mailing list