Skip to content

Commit

Permalink
[cling] DeclExtractor: use BuildReturnStmt() instead
Browse files Browse the repository at this point in the history
Do not use `ActOnReturnStmt()`, given that the scope returned by
`m_Sema->getCurScope()` might be == m_Sema->TUScope which obviously is
not a function scope.

This fixes the following crash:
```
1:  root-project#3 0x0000556b6a50389e clang::Sema::ActOnReturnStmt(clang::SourceLocation, clang::Expr*, clang::Scope*) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0x225389e)
1:  root-project#4 0x0000556b69215c56 cling::DeclExtractor::EnforceInitOrder(llvm::SmallVector<clang::Stmt*>&) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0xf65c56)
1:  root-project#5 0x0000556b69216788 cling::DeclExtractor::ExtractDecl(clang::FunctionDecl*) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0xf66788)
1:  root-project#6 0x0000556b69216a75 cling::DeclExtractor::Transform(clang::Decl*) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0xf66a75)
```
  • Loading branch information
jalopezg-git authored and maksgraczyk committed Jun 28, 2023
1 parent 476251f commit 2af3270
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions interpreter/cling/lib/Interpreter/DeclExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ namespace cling {
IntegerLiteral* ZeroLit
= IntegerLiteral::Create(*m_Context, ZeroInt, m_Context->IntTy,
SourceLocation());
Stmts.push_back(m_Sema->ActOnReturnStmt(ZeroLit->getExprLoc(),
ZeroLit,
m_Sema->getCurScope()).get());
Stmts.push_back(
m_Sema->BuildReturnStmt(ZeroLit->getExprLoc(), ZeroLit).get());
}

// Wrap Stmts into a function body.
Expand Down

0 comments on commit 2af3270

Please sign in to comment.