From 09fe1fd2b3d6e7e86b193b5ecab5b85d711716d6 Mon Sep 17 00:00:00 2001 From: Javier Lopez-Gomez Date: Tue, 30 May 2023 11:29:59 +0200 Subject: [PATCH] DeclExtractor: use `BuildReturnStmt()` instead 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: #3 0x0000556b6a50389e clang::Sema::ActOnReturnStmt(clang::SourceLocation, clang::Expr*, clang::Scope*) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0x225389e) 1: #4 0x0000556b69215c56 cling::DeclExtractor::EnforceInitOrder(llvm::SmallVector&) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0xf65c56) 1: #5 0x0000556b69216788 cling::DeclExtractor::ExtractDecl(clang::FunctionDecl*) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0xf66788) 1: #6 0x0000556b69216a75 cling::DeclExtractor::Transform(clang::Decl*) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0xf66a75) ``` --- lib/Interpreter/DeclExtractor.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Interpreter/DeclExtractor.cpp b/lib/Interpreter/DeclExtractor.cpp index 55e90419..8fbbaa6b 100644 --- a/lib/Interpreter/DeclExtractor.cpp +++ b/lib/Interpreter/DeclExtractor.cpp @@ -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.