xdress/xdress — pull request #137 by tewk (2014-01-04 05:13:27+00:00)
Title: libclang segfaults in clang_Cursor_hasDefaultConstructor when a template decl doesn't have a definition

I'm struggling to create a minimal testcase, but essentially clang_Cursor_hasDefaultConstructor is getting called on a template declaration that appears to not have a definition.

```
python: /home/tewk/llvm/tools/clang/tools/libclang/../../include/clang/AST/DeclCXX.h:566: const struct DefinitionData &clang::CXXRecordDecl::data() const: Assertion `DefinitionData && "queried property of class with no definition"' failed.
Aborted (core dumped)

Program received signal SIGABRT, Aborted.
0x00007ffff782bf77 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 0x00007ffff782bf77 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007ffff782f5e8 in __GI_abort () at abort.c:90
#2 0x00007ffff7824d43 in __assert_fail_base (fmt=0x7ffff797bf58 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
assertion=assertion@entry=0x7ffff1a31d5f "DefinitionData && \"queried property of class with no definition\"",
file=file@entry=0x7ffff1a31da0 "/home/tewk/llvm/tools/clang/tools/libclang/../../include/clang/AST/DeclCXX.h",
line=line@entry=566, function=function@entry=0x7ffff1a31ded "const struct DefinitionData &clang::CXXRecordDecl::data() const")
at assert.c:92
#3 0x00007ffff7824df2 in __GI___assert_fail (
assertion=0x7ffff1a31d5f "DefinitionData && \"queried property of class with no definition\"",
file=0x7ffff1a31da0 "/home/tewk/llvm/tools/clang/tools/libclang/../../include/clang/AST/DeclCXX.h", line=566,
function=0x7ffff1a31ded "const struct DefinitionData &clang::CXXRecordDecl::data() const") at assert.c:101
#4 0x00007ffff049fd66 in clang::CXXRecordDecl::data (this=0x7fffe167a6b0)
at /home/tewk/llvm/tools/clang/tools/libclang/../../include/clang/AST/DeclCXX.h:566
#5 0x00007ffff04d83f9 in clang::CXXRecordDecl::hasDefaultConstructor (this=0x7fffe167a6b0)
at /home/tewk/llvm/tools/clang/tools/libclang/../../include/clang/AST/DeclCXX.h:788
#6 0x00007ffff04d66b8 in clang_Cursor_hasDefaultConstructor (C=...) at CXCursor.cpp:1121
#7 0x00007ffff3bc0adc in ffi_call_unix64 () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#8 0x00007ffff3bc040c in ffi_call () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#9 0x00007ffff3dd76ce in _ctypes_callproc () from /usr/lib/python2.7/lib-dynload/_ctypes.x86_64-linux-gnu.so
#10 0x00007ffff3dd906e in ?? () from /usr/lib/python2.7/lib-dynload/_ctypes.x86_64-linux-gnu.so
#11 0x000000000052e3cb in PyEval_EvalFrameEx ()
#12 0x000000000052e672 in PyEval_EvalFrameEx ()
#13 0x0000000000505b24 in PyEval_EvalCodeEx ()
#14 0x000000000052f3f2 in PyEval_EvalFrameEx ()
#15 0x0000000000505b24 in PyEval_EvalCodeEx ()
#16 0x000000000052e237 in PyEval_EvalFrameEx ()
#17 0x0000000000505b24 in PyEval_EvalCodeEx ()
#18 0x000000000052e237 in PyEval_EvalFrameEx ()
#19 0x0000000000505b24 in PyEval_EvalCodeEx ()
#20 0x000000000052f3f2 in PyEval_EvalFrameEx ()
#21 0x0000000000505b24 in PyEval_EvalCodeEx ()
#22 0x000000000052f3f2 in PyEval_EvalFrameEx ()
#23 0x0000000000505b24 in PyEval_EvalCodeEx ()
#24 0x000000000052f3f2 in PyEval_EvalFrameEx ()
#25 0x000000000052e672 in PyEval_EvalFrameEx ()
#26 0x0000000000505b24 in PyEval_EvalCodeEx ()
#27 0x000000000052f3f2 in PyEval_EvalFrameEx ()
#28 0x0000000000567cdc in PyEval_EvalCode ()
#29 0x0000000000451adb in ?? ()
#30 0x0000000000451e5b in PyRun_FileExFlags ()
#31 0x0000000000452058 in ?? ()
#32 0x000000000052de05 in PyEval_EvalFrameEx ()
#33 0x0000000000505b24 in PyEval_EvalCodeEx ()
#34 0x000000000052f3f2 in PyEval_EvalFrameEx ()
#35 0x000000000052e672 in PyEval_EvalFrameEx ()
#36 0x0000000000567cdc in PyEval_EvalCode ()
#37 0x0000000000451adb in ?? ()
#38 0x0000000000451e5b in PyRun_FileExFlags ()
#39 0x0000000000452394 in PyRun_SimpleFileExFlags ()
#40 0x0000000000453ead in Py_Main ()
#41 0x00007ffff7816de5 in __libc_start_main (main=0x453f6b

, argc=3, ubp_av=0x7fffffffe388, init=,
fini=, rtld_fini=, stack_end=0x7fffffffe378) at libc-start.c:260
#42 0x00000000005786be in _start ()--

#6 0x00007ffff04d66b8 in clang_Cursor_hasDefaultConstructor (C=...) at CXCursor.cpp:1121
1121 return R->hasDefaultConstructor();
(gdb) p *R
$11 = {
= {
= {
= {
= {
= {
_vptr$Decl = 0x7ffff2401d50 ,
NextInContextAndBits = {
Value = 0
},
DeclCtx = {
Val = {
Value = 140736974656728
}
},
Loc = {
ID = 10498
},
DeclKind = 29,
InvalidDecl = 0,
HasAttrs = 0,
Implicit = 0,
Used = 0,
Referenced = 0,
static StatisticsEnabled = false,
Access = 3,
FromASTFile = 0,
Hidden = 0,
IdentifierNamespace = 0,
CacheValidAndLinkage = 0
},
members of clang::NamedDecl:
Name = {
Ptr = 140736974706680
}
},
members of clang::TypeDecl:
TypeForDecl = 0x7fffe167a7c0,
LocStart = {
ID = 10492
}
},
= {
DeclKind = 29,
ExternalLexicalStorage = false,
ExternalVisibleStorage = false,
NeedToReconcileExternalVisibleStorage = false,
LookupPtr = {
Value = 0
},
FirstDecl = 0x0,
LastDecl = 0x0
},
> = {
RedeclLink = {
NextAndIsPrevious = {
Value = 140736975054514
}
}
},
members of clang::TagDecl:
TagDeclKind = 3,
IsCompleteDefinition = false,
IsBeingDefined = false,
IsEmbeddedInDeclarator = false,
IsFreeStanding = false,
NumPositiveBits = 0,
NumNegativeBits = 0,
IsScoped = false,
IsScopedUsingClassTag = false,
---Type to continue, or q to quit---
IsFixed = false,
MayHaveOutOfDateDef = false,
IsCompleteDefinitionRequired = false,
RBraceLoc = {
ID = 0
},
NamedDeclOrQualifier = {
Val = {
Value = 0
}
}
},
members of clang::RecordDecl:
HasFlexibleArrayMember = false,
AnonymousStructOrUnion = false,
HasObjectMember = false,
HasVolatileMember = false,
LoadedFieldsFromExternalStorage = false
},
members of clang::CXXRecordDecl:
DefinitionData = 0x0,
TemplateOrInstantiation = {
Val = {
Value = 0
}
}
}
```