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

Leandro Lupori via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 16 06:57:17 PDT 2024


luporl wrote:

I have been able to reproduce the issue on ARM hardware and collected the info below.
This was with a release build. I'll check if I can get more details with a debug build.

```
Program received signal SIGSEGV, Segmentation fault.
memset () at ../sysdeps/arm/memset.S:51
51	../sysdeps/arm/memset.S: No such file or directory.
(gdb) bt
#0  memset () at ../sysdeps/arm/memset.S:51
#1  0x05ad8eec in clang::interp::DynamicAllocator::allocate(clang::interp::Descriptor const*, unsigned int) [clone .part.0] ()
#2  0x05b2027a in clang::interp::Interpret(clang::interp::InterpState&, clang::APValue&) ()
#3  0x05ac96fe in clang::interp::Call(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::Function const*, unsigned int) ()
#4  0x05cd1dcc in clang::interp::Compiler<clang::interp::EvalEmitter>::VisitCallExpr(clang::CallExpr const*) ()
#5  0x05cd0670 in clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) ()
#6  0x05cdbbda in clang::interp::Compiler<clang::interp::EvalEmitter>::VisitCastExpr(clang::CastExpr const*) ()
#7  0x05cd0670 in clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) ()
#8  0x05cd541a in clang::interp::Compiler<clang::interp::EvalEmitter>::visitExpr(clang::Expr const*) ()
#9  0x05a26b64 in clang::interp::EvalEmitter::interpretExpr(clang::Expr const*, bool) ()
#10 0x05a20c58 in clang::interp::Context::evaluateAsRValue(clang::interp::State&, clang::Expr const*, clang::APValue&) ()
#11 0x059ca096 in EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ()
#12 0x059cac2c in clang::Expr::isCXX11ConstantExpr(clang::ASTContext const&, clang::APValue*, clang::SourceLocation*) const ()
#13 0x059caeb2 in EvaluateCPlusPlus11IntegralConstantExpr(clang::ASTContext const&, clang::Expr const*, llvm::APSInt*, clang::SourceLocation*) ()
#14 0x059cceb8 in clang::Expr::getIntegerConstantExpr(clang::ASTContext const&, clang::SourceLocation*) const ()
#15 0x04d93f24 in AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) [clone .constprop.0] ()
#16 0x04d94d3c in clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) ()
#17 0x050d7ec4 in clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) ()
#18 0x04f20652 in clang::Sema::BuildStaticAssertDeclaration(clang::SourceLocation, clang::Expr*, clang::Expr*, clang::SourceLocation, bool) ()
#19 0x04f20b78 in clang::Sema::ActOnStaticAssertDeclaration(clang::SourceLocation, clang::Expr*, clang::Expr*, clang::SourceLocation) ()
#20 0x04c37dba in clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&) ()
#21 0x04c2d022 in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) ()
#22 0x04c00bb0 in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) ()
#23 0x04c3ddae in clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) ()
#24 0x04c403d0 in clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) ()
#25 0x04c2d0d0 in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) ()
#26 0x04c00bb0 in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) ()
#27 0x04c01594 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) ()
#28 0x04bf63e0 in clang::ParseAST(clang::Sema&, bool, bool) ()
#29 0x0396e5ea in clang::FrontendAction::Execute() ()
#30 0x03916b90 in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) ()
#31 0x03a0b2b6 in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) ()
#32 0x00e14120 in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) ()
#33 0x00e0f402 in ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) ()
#34 0x00e117e6 in clang_main(int, char**, llvm::ToolContext const&) ()
#35 0x00d68a5e in main ()
```

```
   0xf7cac25c <+60>:	subscs	r2, r2, #8
   0xf7cac260 <+64>:	stmiacs	r3!, {r1, r12}
   0xf7cac264 <+68>:	subscs	r2, r2, #8
=> 0xf7cac268 <+72>:	stmiacs	r3!, {r1, r12}
   0xf7cac26c <+76>:	bcs	0xf7cac24c <memset+44>
   0xf7cac270 <+80>:	and	r2, r2, #7
   0xf7cac274 <+84>:	subs	r2, r2, #1
End of assembler dump.
(gdb) p/x $r3
$1 = 0x9fda000
(gdb) p/x $r1
$2 = 0x0
(gdb) p/x $r12
$3 = 0x0
```

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


More information about the cfe-commits mailing list