-ast-print-xml hasUninstantiatedDefaultArg assert

On OS X (10.6.x) when running (with trunk revision: 117928):

clang++ -cc1 -ast-print-xml unparsedDefaultArg.cc

produces the following partial stack dump with:

Assertion failed: (!hasUninstantiatedDefaultArg() && "Default argument is not yet instantiated!"), function getDefaultArg, file llvm/tools/clang/lib/AST/Decl.cpp, line 1092.
0 clang++ 0x000000010120978b PrintStackTrace(void*) + 38
1 clang++ 0x0000000101209d46 SignalHandler(int) + 254
2 libSystem.B.dylib 0x00007fff812e635a _sigtramp + 26
3 libSystem.B.dylib 0x0000000104c4dc65 _sigtramp + 2207676709
4 clang++ 0x000000010002099f raise + 27
5 clang++ 0x00000001000209af abort + 14
6 clang++ 0x0000000100020a3c __gnu_cxx::new_allocator<std::pair<void (*)(void*), void*> >::new_allocator() + 0
7 clang++ 0x00000001006bbda8 clang::ParmVarDecl::getDefaultArg() + 138
8 clang++ 0x0000000100079831 clang::DocumentXML::DeclPrinter::addSubNodes(clang::ParmVarDecl*) + 25
9 clang++ 0x000000010007994f clang::DocumentXML::DeclPrinter::VisitParmVarDecl(clang::ParmVarDecl*) + 249
10 clang++ 0x0000000100079eab clang::DeclVisitor<clang::DocumentXML::DeclPrinter, void>::Visit(clang::Decl*) + 1055
11 clang++ 0x000000010007a803 clang::DocumentXML::DeclPrinter::addSubNodes(clang::FunctionDecl*) + 61
12 clang++ 0x000000010007aee2 clang::DocumentXML::DeclPrinter::VisitCXXMethodDecl(clang::CXXMethodDecl*) + 858
...

such that unparsedDefaultArg.cc ==

---------------------- START --------------------------------
#include <string>

int main (int argc, char* argv)
{
    return(0);
}
----------------------- END -------------------------------

Same result occurs with a release build, and when building on Linux (32bit on ec2, clang+llvm
built with gcc4.2.1 and -m686).

I do not yet have the proficiency in Clang internals to debug this, but pointers
in this direction would help mitigate my time. Specifically given that I need to
search for a parameter with a default arg, is there a symbol one could give
me which I could use in gdb to dump the current source (SourceLocation/SourceRange?)
at frame 7 above?

Thanks in advance

Garrison

SourceLocation::dump(SourceManager&) will dump a source location in a human-readable format.

  - Doug

Well, it looks like I need more hand holding. While at frame 6 in gdb, executing:

print (argDecl->Loc).dump((argDecl->getASTContext()).getSourceManager())

gives: /usr/include/c++/4.2.1/bits/basic_string.h:254:36

Looking at the source code for SourceLocation::print(...), it looks like the above
should be interpreted as the filename:line#:col#. However the source line:
<space+>_CharT* neither has a 36th column nor is a method decl
containing a param with a default arg. So I think I'm in never never land. Is this
because the use of getPresumedLoc(...) in the implementation of SourceLocation::
print(...) is not returning the correct location? Or is it because _CharT type is a
template arg, and somehow that involves method instantiations behind the
scene? Or is it ...? :slight_smile:

I think the real request is that I need more pointers if you have time. I do not believe
the doc covers this kind of debugging for clang, but I've not been thorough, and
regardless I believe we have an -ast-print-xml bug. If you agree, I'll file it, though
I was really hoping for better understanding of how parts of clang work.

Thanks in advance again

Garrison

Well, it looks like I need more hand holding. While at frame 6 in gdb, executing:

print (argDecl->Loc).dump((argDecl->getASTContext()).getSourceManager())

gives: /usr/include/c++/4.2.1/bits/basic_string.h:254:36

Looking at the source code for SourceLocation::print(...), it looks like the above
should be interpreted as the filename:line#:col#. However the source line:
<space+>_CharT* neither has a 36th column nor is a method decl
containing a param with a default arg. So I think I'm in never never land. Is this
because the use of getPresumedLoc(...) in the implementation of SourceLocation::
print(...) is not returning the correct location? Or is it because _CharT type is a
template arg, and somehow that involves method instantiations behind the
scene? Or is it ...? :slight_smile:

Template instantiation may have lost some source-location information. More debugging would be needed to figure that out.

I think the real request is that I need more pointers if you have time. I do not believe
the doc covers this kind of debugging for clang, but I've not been thorough, and
regardless I believe we have an -ast-print-xml bug. If you agree, I'll file it, though
I was really hoping for better understanding of how parts of clang work.

The XML printer probably isn't checking whether it should treat the default argument as an uninstantiated default argument; see the ParmVarDecl class for more information.

  - Doug