[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

Leandro Lupori via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 16 13:54:38 PDT 2024


luporl wrote:

In my debug build, clang is receiving a SIGSEGV in frame 7 below (that is actually frame 0, as the frames below it are from a gdb call that received a signal). In it, `this` holds an invalid address.
In frame 8, `NE` is 0x3fffffff, which probably caused the invalid access.
In frame 12, `NumElements.V` is 0xffffffff, which may be the cause of the huge `NE` value later.

I stopped there, as I lack experience with clang's sources.
Please let me know if you need more information or help with reproducing the issue with qemu.

```
#7  0xe55f55cc in clang::interp::Integral<32u, true>::Integral (this=0x57f000) at /home/leandro.lupori/git/ci/llvm/clang/lib/AST/Interp/Integral.h:69
#8  0xe55f3e4e in ctorArrayTy<clang::interp::Integral<32, true> > (Ptr=0x575a20, D=0x577240) at /home/leandro.lupori/git/ci/llvm/clang/lib/AST/Interp/Descriptor.cpp:48
#9  0xe5639e06 in clang::interp::Block::invokeCtor (this=0x5759e8) at /home/leandro.lupori/git/ci/llvm/clang/lib/AST/Interp/InterpBlock.h:120
#10 0xe56e5f52 in clang::interp::DynamicAllocator::allocate (this=0xfffec530, D=0x577240, EvalID=88) at /home/leandro.lupori/git/ci/llvm/clang/lib/AST/Interp/DynamicAllocator.cpp:69
#11 0xe56e5df6 in clang::interp::DynamicAllocator::allocate (this=0xfffec530, Source=0x575220, T=clang::interp::PT_Sint32, NumElements=4294967295, EvalID=88)
    at /home/leandro.lupori/git/ci/llvm/clang/lib/AST/Interp/DynamicAllocator.cpp:50
#12 0xe5644402 in clang::interp::AllocN<(clang::interp::PrimType)5, clang::interp::Integral<32u, false> > (S=..., OpPC=..., T=clang::interp::PT_Sint32, Source=0x575220, IsNoThrow=true)
    at /home/leandro.lupori/git/ci/llvm/clang/lib/AST/Interp/Interp.h:2841
#13 0xe56ee890 in clang::interp::Interpret (S=..., Result=...) at /home/leandro.lupori/git/ci/build/tools/clang/lib/AST/Opcodes.inc:901
#14 0xe563f126 in clang::interp::Call (S=..., OpPC=..., Func=0x5760e0, VarArgSize=0) at /home/leandro.lupori/git/ci/llvm/clang/lib/AST/Interp/Interp.h:2554
#15 0xe561e956 in clang::interp::EvalEmitter::emitCall (this=0xfffec428, A0=0x5760e0, A1=0, L=...) at /home/leandro.lupori/git/ci/build/tools/clang/lib/AST/Opcodes.inc:3495
#16 0xe55cb414 in clang::interp::Compiler<clang::interp::EvalEmitter>::VisitCallExpr (this=0xfffec428, E=0x576270)
    at /home/leandro.lupori/git/ci/llvm/clang/lib/AST/Interp/Compiler.cpp:4031
#17 0xe55e2814 in clang::StmtVisitorBase<llvm::make_const_ptr, clang::interp::Compiler<clang::interp::EvalEmitter>, bool>::Visit (this=0xfffec428, S=0x576270)
    at /home/leandro.lupori/git/ci/build/tools/clang/include/clang/AST/StmtNodes.inc:602
```

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


More information about the cfe-commits mailing list