teemperor requested changes to this revision.
teemperor added a comment.
This revision now requires changes to proceed.

I think this looks good, thanks for fixing this! I believe there should be a 
few more tests for all the corner cases we can run into here (those tests can 
all be just Python API tests, no need for having them all in assembly format). 
Also I think lambdas where triggering the original issue, so that would also be 
nice to have in a test.

I started writing some example tests but this is crashing for me with:

  Unexpected undeduced type!
  UNREACHABLE executed at 
/home/teemperor/work/ci/llvm-project/clang/lib/CodeGen/CodeGenTypes.cpp:624!
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace.
  Stack dump:
  0.    Program arguments: ./bin/lldb 
././lldb-test-build.noindex/lang/cpp/auto_return/TestCppAutoReturn.test_dwarf/a.out
   #0 0x000055f540b5e611 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(./bin/lldb+0x34611)
   #1 0x000055f540b5c6b0 llvm::sys::RunSignalHandlers() (./bin/lldb+0x326b0)
   #2 0x000055f540b5efb6 SignalHandler(int) (./bin/lldb+0x34fb6)
   #3 0x00007fe3c3484870 __restore_rt (/usr/lib/libpthread.so.0+0x13870)
   #4 0x00007fe3bd2e3d22 raise (/usr/lib/libc.so.6+0x3cd22)
   #5 0x00007fe3bd2cd862 abort (/usr/lib/libc.so.6+0x26862)
   #6 0x00007fe3becf0df1 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x146adf1)
   #7 0x00007fe3bf7cbdda 
clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1f45dda)
   #8 0x00007fe3bf7caf7e 
clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType, bool) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1f44f7e)
   #9 0x00007fe3bf951dd8 
clang::CodeGen::CodeGenModule::getOrCreateStaticVarDecl(clang::VarDecl const&, 
llvm::GlobalValue::LinkageTypes) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x20cbdd8)
  #10 0x00007fe3bf950b10 
clang::CodeGen::CodeGenFunction::EmitStaticVarDecl(clang::VarDecl const&, 
llvm::GlobalValue::LinkageTypes) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x20cab10)
  #11 0x00007fe3bf9508f3 
clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x20ca8f3)
  #12 0x00007fe3bf950458 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl 
const&) (/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x20ca458)
  #13 0x00007fe3bf6f887c 
clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e7287c)
  #14 0x00007fe3bf6ee2d8 
clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, 
llvm::ArrayRef<clang::Attr const*>) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e682d8)
  #15 0x00007fe3bf6eda89 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt 
const*, llvm::ArrayRef<clang::Attr const*>) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e67a89)
  #16 0x00007fe3bf6f96b0 
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
 const&, bool, clang::CodeGen::AggValueSlot) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e736b0)
  #17 0x00007fe3bf7585b4 
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ed25b4)
  #18 0x00007fe3bf7591de 
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, 
llvm::Function*, clang::CodeGen::CGFunctionInfo const&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ed31de)
  #19 0x00007fe3bf77a51f 
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, 
llvm::GlobalValue*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ef451f)
  #20 0x00007fe3bf77222d 
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, 
llvm::GlobalValue*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1eec22d)
  #21 0x00007fe3bf7773bb 
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ef13bb)
  #22 0x00007fe3bf77e039 
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1ef8039)
  #23 0x00007fe3bf6ab280 (anonymous 
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1e25280)
  #24 0x00007fe3bf549632 
lldb_private::ASTResultSynthesizer::HandleTopLevelDecl(clang::DeclGroupRef) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1cc3632)
  #25 0x00007fe3c018a558 clang::ParseAST(clang::Sema&, bool, bool) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x2904558)
  #26 0x00007fe3bf55d493 
lldb_private::ClangExpressionParser::ParseInternal(lldb_private::DiagnosticManager&,
 clang::CodeCompleteConsumer*, unsigned int, unsigned int) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1cd7493)
  #27 0x00007fe3bf540c11 
lldb_private::ClangUserExpression::TryParse(lldb_private::DiagnosticManager&, 
lldb_private::ExecutionContextScope*, lldb_private::ExecutionContext&, 
lldb_private::ExecutionPolicy, bool, bool) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1cbac11)
  #28 0x00007fe3bf541346 
lldb_private::ClangUserExpression::Parse(lldb_private::DiagnosticManager&, 
lldb_private::ExecutionContext&, lldb_private::ExecutionPolicy, bool, bool) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1cbb346)
  #29 0x00007fe3be8013d6 
lldb_private::UserExpression::Evaluate(lldb_private::ExecutionContext&, 
lldb_private::EvaluateExpressionOptions const&, llvm::StringRef, 
llvm::StringRef, std::shared_ptr<lldb_private::ValueObject>&, 
lldb_private::Status&, std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >*, lldb_private::ValueObject*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0xf7b3d6)
  #30 0x00007fe3be927184 
lldb_private::Target::EvaluateExpression(llvm::StringRef, 
lldb_private::ExecutionContextScope*, 
std::shared_ptr<lldb_private::ValueObject>&, 
lldb_private::EvaluateExpressionOptions const&, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
>*, lldb_private::ValueObject*) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x10a1184)
  #31 0x00007fe3bf473723 
lldb_private::CommandObjectExpression::EvaluateExpression(llvm::StringRef, 
lldb_private::Stream&, lldb_private::Stream&, 
lldb_private::CommandReturnObject&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1bed723)
  #32 0x00007fe3bf4746ae 
lldb_private::CommandObjectExpression::DoExecute(llvm::StringRef, 
lldb_private::CommandReturnObject&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0x1bee6ae)
  #33 0x00007fe3be848635 lldb_private::CommandObjectRaw::Execute(char const*, 
lldb_private::CommandReturnObject&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0xfc2635)
  #34 0x00007fe3be83d0a8 lldb_private::CommandInterpreter::HandleCommand(char 
const*, lldb_private::LazyBool, lldb_private::CommandReturnObject&) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0xfb70a8)
  #35 0x00007fe3be840f58 
lldb_private::CommandInterpreter::IOHandlerInputComplete(lldb_private::IOHandler&,
 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
>&) (/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0xfbaf58)
  #36 0x00007fe3be781f18 lldb_private::IOHandlerEditline::Run() 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0xefbf18)
  #37 0x00007fe3be762cc4 lldb_private::Debugger::RunIOHandlers() 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0xedccc4)
  #38 0x00007fe3be842c19 
lldb_private::CommandInterpreter::RunCommandInterpreter(lldb_private::CommandInterpreterRunOptions&)
 (/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0xfbcc19)
  #39 0x00007fe3be2a16bd lldb::SBDebugger::RunCommandInterpreter(bool, bool) 
(/home/teemperor/work/ci/build/bin/../lib/liblldb.so.13git+0xa1b6bd)
  #40 0x000055f540b39d0c Driver::MainLoop() (./bin/lldb+0xfd0c)

This is the diff for the test:

  diff --git a/lldb/test/API/lang/cpp/auto_return/Makefile 
b/lldb/test/API/lang/cpp/auto_return/Makefile
  new file mode 100644
  index 000000000000..a43ca68df298
  --- /dev/null
  +++ b/lldb/test/API/lang/cpp/auto_return/Makefile
  @@ -0,0 +1,4 @@
  +CXX_SOURCES := main.cpp other.cpp
  +CXXFLAGS_EXTRAS := -std=c++17
  +
  +include Makefile.rules
  diff --git a/lldb/test/API/lang/cpp/auto_return/TestCppAutoReturn.py 
b/lldb/test/API/lang/cpp/auto_return/TestCppAutoReturn.py
  new file mode 100644
  index 000000000000..49ff5a9460dd
  --- /dev/null
  +++ b/lldb/test/API/lang/cpp/auto_return/TestCppAutoReturn.py
  @@ -0,0 +1,18 @@
  +import lldb
  +from lldbsuite.test.decorators import *
  +from lldbsuite.test.lldbtest import *
  +from lldbsuite.test import lldbutil
  +
  +class TestCase(TestBase):
  +
  +    mydir = TestBase.compute_mydir(__file__)
  +
  +    def test(self):
  +        self.build()
  +        lldbutil.run_to_source_breakpoint(self, "// break here", 
lldb.SBFileSpec("main.cpp"))
  +
  +        # Member access
  +        self.expect_expr("C.ret()", result_type="int", result_value="1")
  +
  +        lldbutil.run_to_source_breakpoint(self, "// break also here", 
lldb.SBFileSpec("other.cpp"))
  +        self.expect_expr("b.ret()", result_type="int", result_value="1")
  diff --git a/lldb/test/API/lang/cpp/auto_return/main.cpp 
b/lldb/test/API/lang/cpp/auto_return/main.cpp
  new file mode 100644
  index 000000000000..3629c7b0c8f4
  --- /dev/null
  +++ b/lldb/test/API/lang/cpp/auto_return/main.cpp
  @@ -0,0 +1,18 @@
  +void other();
  +
  +namespace {
  +struct Bla {
  +  auto ret();
  +};
  +
  +auto Bla::ret() {
  +  auto x = [](int bla){ return bla; };
  +  return x(1);
  +}
  +}
  +
  +int main() {
  +  Bla C;
  +  other();
  +  return C.ret(); // break here
  +}
  diff --git a/lldb/test/API/lang/cpp/auto_return/other.cpp 
b/lldb/test/API/lang/cpp/auto_return/other.cpp
  new file mode 100644
  index 000000000000..315049e16ff0
  --- /dev/null
  +++ b/lldb/test/API/lang/cpp/auto_return/other.cpp
  @@ -0,0 +1,15 @@
  +namespace {
  +struct Bla {
  +  auto ret();
  +};
  +
  +auto Bla::ret() {
  +  auto x = [](int bla){ return bla; };
  +  return x(2);
  +}
  +}
  +
  +void other() {
  +  Bla b;
  +  b.ret(); // // break also here
  +}



================
Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h:406
 
+  virtual lldb::TypeSP
+  FindTypeForAutoReturnForDIE(const DWARFDIE &die,
----------------
If this is virtual then I guess `SymbolFileDWARFDwo` should overload it?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105564/new/

https://reviews.llvm.org/D105564

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to