Issue 139012
Summary Bytecode Interpreter: Fix IntegralAP/Floating memory leaks
Labels clang:frontend, clang:bytecode
Assignees
Reporter tbaederr
    When creating new `IntegralAP` (or also `Floating`) values, they allocate heap memory, which _might_ not get cleaned up when we interrupt interpretation and the integral stays on the stack. We never call the destructor.

This code:
```c++
int ctz48 = __builtin_ctzg((unsigned __int128)0);
```
produces a memory leak:
```
Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x0000003e2c41 in operator new[](unsigned long) (/home/tbaeder/code/llvm-project/build/bin/clang-21+0x3e2c41) (BuildId: 616e3f3e5634af4d767394e4e2f35f78358eaebd)
    #1 0x7f05a3cdb67e in getMemory(unsigned int) /home/tbaeder/code/llvm-project/llvm/lib/Support/APInt.cpp:43:10
    #2 0x7f05a3cdb78f in llvm::APInt::initSlowCase(llvm::APInt const&) /home/tbaeder/code/llvm-project/llvm/lib/Support/APInt.cpp:87:12
    #3 0x7f05dd9c27ea in llvm::APInt::APInt(llvm::APInt const&) /home/tbaeder/code/llvm-project/llvm/include/llvm/ADT/APInt.h:180:7
    #4 0x7f05e007a03c in clang::interp::IntegralAP<false>::IntegralAP(llvm::APInt) /home/tbaeder/code/llvm-project/clang/lib/AST/ByteCode/IntegralAP.h:62:25
 #5 0x7f05e04e4eb7 in clang::interp::IntegralAP<false> clang::interp::IntegralAP<false>::from<32u, true>(clang::interp::Integral<32u, true>, unsigned int) /home/tbaeder/code/llvm-project/clang/lib/AST/ByteCode/IntegralAP.h:115:12
 #6 0x7f05e032b3fc in bool clang::interp::CastAP<(clang::interp::PrimType)4, clang::interp::Integral<32u, true>>(clang::interp::InterpState&, clang::interp::CodePtr, unsigned int) /home/tbaeder/code/llvm-project/clang/lib/AST/ByteCode/Interp.h:2266:7
 #7 0x7f05e02679de in clang::interp::EvalEmitter::emitCastAPSint32(unsigned int, clang::interp::SourceInfo const&) /home/tbaeder/code/llvm-project/build/tools/clang/lib/AST/Opcodes.inc:6657:10
```

I think we should allocate the memory ourselves, like `APNumericStorage` does.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to