ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.96k stars 2.55k forks source link

ZigClangDecl_getName_bytes_begin segfaults in llvm::StringMapEntryBase::getKeyLength #4143

Closed daurnimator closed 4 years ago

daurnimator commented 4 years ago

Failure when using linux kernel headers:

─── Output/messages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
/usr/lib/../share/gcc-9.2.0/python/libstdcxx/v6/xmethods.py:731: SyntaxWarning: list indices must be integers or slices, not str; perhaps you missed a comma?
  refcounts = ['_M_refcount']['_M_pi']

Program received signal SIGSEGV, Segmentation fault.
0x00005555558d5934 in llvm::StringMapEntryBase::getKeyLength (this=0x2) at /usr/include/llvm/ADT/StringMap.h:44
44    size_t getKeyLength() const { return StrLen; }
─── Assembly ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
0x00005555558d5929 llvm::StringMapEntryBase::getKeyLength+1  mov    %rsp,%rbp
0x00005555558d592c llvm::StringMapEntryBase::getKeyLength+4  mov    %rdi,-0x8(%rbp)
0x00005555558d5930 llvm::StringMapEntryBase::getKeyLength+8  mov    -0x8(%rbp),%rax
0x00005555558d5934 llvm::StringMapEntryBase::getKeyLength+12 mov    (%rax),%rax
0x00005555558d5937 llvm::StringMapEntryBase::getKeyLength+15 pop    %rbp
0x00005555558d5938 llvm::StringMapEntryBase::getKeyLength+16 retq   
─── Expressions ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─── History ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─── Memory ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─── Registers ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   rax 0x0000000000000002      rbx 0x0000555556b0a588      rcx 0x0000000000000000      rdx 0x00007fffffffa550      rsi 0x00007fffffffa550  
   rdi 0x0000000000000002      rbp 0x00007fffffff9d80      rsp 0x00007fffffff9d80       r8 0x0000000000000000       r9 0x0000000000000000  
   r10 0x0000000000000064      r11 0xd092b5194b8aa000      r12 0x000000004b8aa001      r13 0x000055555570c3f0      r14 0x0000555556b0ddc8  
   r15 0x0000000000000000      rip 0x00005555558d5934   eflags [ PF IF RF ]             cs 0x00000033               ss 0x0000002b          
    ds 0x00000000               es 0x00000000               fs 0x00000000               gs 0x00000000          
─── Source ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
39   size_t StrLen;
40 
41 public:
42   explicit StringMapEntryBase(size_t Len) : StrLen(Len) {}
43 
44   size_t getKeyLength() const { return StrLen; }
45 };
46 
47 /// StringMapImpl - This is the base class of StringMap that is shared among
48 /// all of its instantiations.
49 class StringMapImpl {
─── Stack ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[0] from 0x00005555558d5934 in llvm::StringMapEntryBase::getKeyLength+12 at /usr/include/llvm/ADT/StringMap.h:44
arg this = 0x2
[1] from 0x00005555558e365e in clang::IdentifierInfo::getLength+28 at /usr/include/clang/Basic/IdentifierTable.h:152
arg this = 0x555556260af0
[+]
─── Threads ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[1] id 559201 name zig from 0x00005555558d5934 in llvm::StringMapEntryBase::getKeyLength+12 at /usr/include/llvm/ADT/StringMap.h:44
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
>>> bt
#0  0x00005555558d5934 in llvm::StringMapEntryBase::getKeyLength (this=0x2) at /usr/include/llvm/ADT/StringMap.h:44
#1  0x00005555558e365e in clang::IdentifierInfo::getLength (this=0x555556260af0) at /usr/include/clang/Basic/IdentifierTable.h:152
#2  0x00005555558e3688 in clang::IdentifierInfo::getName (this=0x555556260af0) at /usr/include/clang/Basic/IdentifierTable.h:156
#3  0x00005555558e3b32 in clang::NamedDecl::getName (this=0x5555567f9428) at /usr/include/clang/AST/Decl.h:277
#4  0x00005555558deb43 in ZigClangDecl_getName_bytes_begin (zig_decl=0x5555567f9428) at /home/daurnimator/src/zig/src/zig_clang.cpp:1655
#5  0x000055555570c718 in translate_c.declVisitorNamesOnly (c=0x7fffffffa550, decl=0x5555567f9428) at translate_c.zig:385
#6  0x000055555570c50e in translate_c.declVisitorNamesOnlyC (context=0x7fffffffa550, decl=0x5555567f9428) at translate_c.zig:368
#7  0x00007ffff794a312 in clang::ASTUnit::visitLocalTopLevelDecls(void*, bool (*)(void*, clang::Decl const*)) () from /usr/lib/libclangFrontend.so.9
LemonBoy commented 4 years ago

Failure when using linux kernel headers

There's virtually no information in this bug report, no minimal test case, not even a hint to what header file causes the problem!

daurnimator commented 4 years ago

Sorry about that. Was the last thing I hit before heading to bed. Was going to narrpw down a reproduction in the morning.

daurnimator commented 4 years ago

@LemonBoy thankyou! Sorry for not providing more info at the time.