[llvm-bugs] [Bug 51818] New: lldb crashes with relatively simple gcc debug info

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 10 13:17:30 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51818

            Bug ID: 51818
           Summary: lldb crashes with relatively simple gcc debug info
           Product: lldb
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: lldb-dev at lists.llvm.org
          Reporter: jgorbe at google.com
                CC: jdevlieghere at apple.com, llvm-bugs at lists.llvm.org

Building the following program with gcc 10.2.1:
```
#include <optional>
#include <string>

int main()
{
  std::optional<std::string> os{ "stringy" };
  return 0;
}
```
and trying to `print os` from lldb, results in infinite recursion inside
`clang::ASTContext::getASTRecordLayout` leading to a crash.

I have investigated this for a while and I got to the following reduced test
case:
```
template <bool> struct S {};
template <> struct S<false> : S<true> {};
S<false> s;
```
What happens is that gcc omits `DW_TAG_template_parameter` in some cases (for
unnamed template arguments, it seems). lldb passes clang an AST that says that
S<false> is a struct S that inherits from S<>, and clang recurses infinitely
trying to compute the class layout. This is the AST as dumped by lldb-test
symbols -dump-clang-ast:

Module: cxx17.o
S<true>
ClassTemplateSpecializationDecl 0xf2571d0 <<invalid sloc>> <invalid sloc>
struct S definition
`-DefinitionData pass_in_registers empty aggregate standard_layout
trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor
can_const_default_init
  |-DefaultConstructor exists trivial constexpr needs_implicit
defaulted_is_constexpr
  |-CopyConstructor simple trivial has_const_param needs_implicit
implicit_has_const_param
  |-MoveConstructor exists simple trivial needs_implicit
  |-CopyAssignment simple trivial has_const_param needs_implicit
implicit_has_const_param
  |-MoveAssignment exists simple trivial needs_implicit
  `-Destructor simple irrelevant trivial needs_implicit
S<false>
ClassTemplateSpecializationDecl 0xf257340 <<invalid sloc>> <invalid sloc>
struct S definition
|-DefinitionData pass_in_registers empty standard_layout trivially_copyable
trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
| |-DefaultConstructor exists trivial constexpr needs_implicit
defaulted_is_constexpr
| |-CopyConstructor simple trivial has_const_param needs_implicit
implicit_has_const_param
| |-MoveConstructor exists simple trivial needs_implicit
| |-CopyAssignment simple trivial has_const_param needs_implicit
implicit_has_const_param
| |-MoveAssignment exists simple trivial needs_implicit
| `-Destructor simple irrelevant trivial needs_implicit
`-public 'S<>'


`getASTRecordLayout` tries to create an `EmptySubobjectMap`, and its
constructor calls `ComputeEmptySubobjectSizes`. This function enumerates the
base classes of the current class, and calls `getASTRecordLayout` again. Here's
a relevant fragment of a stack trace:

[... 6993 more frames of these 3 functions recursing ...]
#6994 0x00007ffff5d7a05a in (anonymous
namespace)::EmptySubobjectMap::EmptySubobjectMap (this=0x7fffffff3df8,
Context=..., Class=0x6f2500)                          
    at /home/jgorbe/code/llvm/clang/lib/AST/RecordLayoutBuilder.cpp:172         
#6995 0x00007ffff5d79687 in clang::ASTContext::getASTRecordLayout
(this=0x6a5e80, D=0x6f2500)                                                     
    at /home/jgorbe/code/llvm/clang/lib/AST/RecordLayoutBuilder.cpp:3290
#6996 0x00007ffff5d7f5e1 in (anonymous
namespace)::EmptySubobjectMap::ComputeEmptySubobjectSizes (this=0x7fffffff4bf8) 
    at /home/jgorbe/code/llvm/clang/lib/AST/RecordLayoutBuilder.cpp:193
#6997 0x00007ffff5d7a05a in (anonymous
namespace)::EmptySubobjectMap::EmptySubobjectMap (this=0x7fffffff4bf8,
Context=..., Class=0x6f2500)        
    at /home/jgorbe/code/llvm/clang/lib/AST/RecordLayoutBuilder.cpp:172
#6998 0x00007ffff5d79687 in clang::ASTContext::getASTRecordLayout
(this=0x6a5e80, D=0x6f2500)
    at /home/jgorbe/code/llvm/clang/lib/AST/RecordLayoutBuilder.cpp:3290
#6999 0x00007ffff5d7f5e1 in (anonymous
namespace)::EmptySubobjectMap::ComputeEmptySubobjectSizes (this=0x7fffffff59f8)
    at /home/jgorbe/code/llvm/clang/lib/AST/RecordLayoutBuilder.cpp:193
#7000 0x00007ffff5d7a05a in (anonymous
namespace)::EmptySubobjectMap::EmptySubobjectMap (this=0x7fffffff59f8,
Context=..., Class=0x6f2500)
    at /home/jgorbe/code/llvm/clang/lib/AST/RecordLayoutBuilder.cpp:172
#7001 0x00007ffff5d79687 in clang::ASTContext::getASTRecordLayout
(this=0x6a5e80, D=0x6f2500)
    at /home/jgorbe/code/llvm/clang/lib/AST/RecordLayoutBuilder.cpp:3290
#7002 0x00007ffff2bfc53f in (anonymous
namespace)::CGRecordLowering::CGRecordLowering (this=0x7fffffff60a0, Types=...,
D=0x6f2500, Packed=false)
    at /home/jgorbe/code/llvm/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:234
#7003 0x00007ffff2bfb8d9 in clang::CodeGen::CodeGenTypes::ComputeRecordLayout
(this=0x6c09f8, D=0x6f2500, Ty=0x6c3170)
    at /home/jgorbe/code/llvm/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:879
#7004 0x00007ffff267324f in clang::CodeGen::CodeGenTypes::ConvertRecordDeclType
(this=0x6c09f8, RD=0x6f2500)
    at /home/jgorbe/code/llvm/clang/lib/CodeGen/CodeGenTypes.cpp:851
[...]

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210910/d58a1cee/attachment.html>


More information about the llvm-bugs mailing list