Skip to content

LLDB crashes when printing a clang::TemplateDecl object #66335

Open
@kasuga-fj

Description

@kasuga-fj

LLDB crashed when I tried printing an object while debugging clang++.

Here is the stack trace.

$ /path/to/lldb /path/to/clang++
(lldb) target create "/path/to/clang++"
Current executable set to '/path/to/clang++' (x87_64).
(lldb) b Sema::DeclareImplicitDeductionGuides
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) run -cc1 main.cpp
Process 3231335 launched: '/path/to/clang++' (x86_64)
1 location added to breakpoint 1
Process 3231335 stopped
* thread #1, name = 'clang++', stop reason = breakpoint 1.1
    frame #0: 0x00007ffff05c5ce3 libclang-cpp.so.18git`clang::Sema::DeclareImplicitDeductionGuides(this=0x000055555569fd10, Template=0x00005555556b34d0, Loc=(ID = 76)) at SemaTemplate.cpp:2617:75
   2614 void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
   2615                                           SourceLocation Loc) {
   2616   if (CXXRecordDecl *DefRecord =
-> 2617           cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) {
   2618     if (TemplateDecl *DescribedTemplate = DefRecord->getDescribedClassTemplate())
   2619       Template = DescribedTemplate;
   2620   }
(lldb) p *Template
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /path/to/lldb /path/to/clang++
1.      HandleCommand(command = "p *Template")
2.      <eof> parser at end of file
3.      <lldb wrapper prefix>:43:16: Generating code for declaration 'clang::Sema::$__lldb_expr'
  #0 0x00007f76d0569c40 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/path/to/libLLVM-18git.so+0x7f5c40)
  #1 0x00007f76d056720e SignalHandler(int) Signals.cpp:0:0
  #2 0x00007f76cf954520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
  #3 0x00007f76cc9da68b clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb368b)
  #4 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #5 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #6 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #7 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #8 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
  #9 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 #10 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 #11 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 #12 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
 ...... (omitted since the stack frame is the same)
#245 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#246 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#247 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#248 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#249 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#250 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#251 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#252 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#253 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#254 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
#255 0x00007f76cc9da915 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/path/to/libclang-cpp.so.18git+0xfb3915)
LLDB diagnostics will be written to /tmp/diagnostics-f465ea
Please include the directory content when filing a bug report
Segmentation fault (core dumped)

LLDB diagnostics is as follows.

$ ls /tmp/diagnostics-f465ea/
diagnostics.log
$ cat /tmp/diagnostics-f465ea/diagnostics.log
$

The main.cpp I passed to clang++ is as follows.

struct X {
  X(const T&);
};

void f() {
  auto x = X(42);
}

The versions of lldb/clang++ are

$ /path/to/lldb --version
lldb version 18.0.0git (${upstream url} revision f8f934e22c4a9dc7abaaddf422c8725bacf2048a)
  clang revision f8f934e22c4a9dc7abaaddf422c8725bacf2048a
  llvm revision f8f934e22c4a9dc7abaaddf422c8725bacf2048a

$ /path/to/clang++ --version
clang version 18.0.0 (${upstream url} f8f934e22c4a9dc7abaaddf422c8725bacf2048a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to 

GDB prints the object correctly.

...
(gdb) p *Template
$1 = {<clang::NamedDecl> = {<clang::Decl> = {_vptr.Decl = 0x7ffff7f47df0 <vtable for clang::ClassTemplateDecl+16>, NextInContextAndBits = {Value = {Data = "h:kUUU\000"}},
      DeclCtx = {<llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPair<void*, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPairInfo<void*, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*> > >, 0, clang::DeclContext*, clang::Decl::MultipleDC*>> = {<llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPair<void*, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPairInfo<void*, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*> > >, 1, clang::Decl::MultipleDC*>> = {<llvm::pointer_union_detail::PointerUnionMembers<llvm::PointerUnion<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPair<void*, 1, int, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*>, llvm::PointerIntPairInfo<void*, 1, llvm::pointer_union_detail::PointerUnionUIntTraits<clang::DeclContext*, clang::Decl::MultipleDC*> > >, 2>> = {Val = {Value = {Data = "p\243fUUU\000"}}}, <No data fields>}, <No data fields>}, <No data fields>}, Loc = {ID = 31}, DeclKind = 30, InvalidDecl = 0, HasAttrs = 0, Implicit = 0, Used = 0,
      Referenced = 0, TopLevelDeclInObjCContainer = 0, static StatisticsEnabled = false, Access = 3, FromASTFile = 0, IdentifierNamespace = 38, CacheValidAndLinkage = 0}, Name = {Ptr = 93824993767936}},
  TemplatedDecl = 0x5555556b3440, TemplateParams = 0x5555556b3428}

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashPrefer [crash-on-valid] or [crash-on-invalid]lldb

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions