Fix expression evaluation for resolving anonymous aggregrate types with a typedefed name

This fixes a recently reported a bug(https://llvm.org/bugs/show_bug.cgi?id=26790) relating to the clang expression evaluator no longer being able to resolve calls to
functions with arguments to typedefed anonymous structs, unions, or enums after a cleanup to the expression parsing code in r260768

This fixes the issue by attaching the tagged name to the original clang::TagDecl object when generating the typedef in lldb::ClangAstContext::CreateTypeDef.

This also fixes the issue for anonymous typedefs for non-struct types (unions and enums) where we have a tag name.


Author: Luke Drummond <luke.drummond@codeplay.com>
Differential Revision: http://reviews.llvm.org/D18099

llvm-svn: 263544
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index d59b39c..b9d71b4 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -4640,6 +4640,20 @@
                                                                &clang_ast->Idents.get(typedef_name),
                                                                clang_ast->getTrivialTypeSourceInfo(qual_type));
 
+        clang::TagDecl *tdecl = nullptr;
+        if (!qual_type.isNull())
+        {
+            if (const clang::RecordType *rt = qual_type->getAs<clang::RecordType>())
+                tdecl = rt->getDecl();
+            if (const clang::EnumType *et = qual_type->getAs<clang::EnumType>())
+                tdecl = et->getDecl();
+        }
+
+        // Check whether this declaration is an anonymous struct, union, or enum, hidden behind a typedef. If so, we
+        // try to check whether we have a typedef tag to attach to the original record declaration
+        if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl())
+            tdecl->setTypedefNameForAnonDecl(decl);
+
         decl->setAccess(clang::AS_public); // TODO respect proper access specifier
 
         // Get a uniqued clang::QualType for the typedef decl type