Author: gclayton Date: Thu May 26 17:33:25 2016 New Revision: 270932 URL: http://llvm.org/viewvc/llvm-project?rev=270932&view=rev Log: With -gmodules, we have been having a harder time always finding a type when we need one.
We have seen cases where we have been unable to find an argument type for a function, or we find one from another language, and then we try to create a function type by calling: lldb_private::ClangASTContext::CreateFunctionType(clang::ASTContext*, lldb_private::CompilerType const&, lldb_private::CompilerType const*, unsigned int, bool, unsigned int) This fix will ensure that all arguments to lldb_private::ClangASTContext::CreateFunctionType() are in order by checking: - AST is valid - if arguments are specified we have a valid argument array - return type is valid - return type is a clang type - all argument types are valid - all argument types are clang types If any of these fail, we return an invalid CompilerType. If we don't return an invalid type, clang will crash anyway, and LLDB must not crash even in the presence of bad or missing debug info. <rdar://problem/25172715> Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=270932&r1=270931&r2=270932&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu May 26 17:33:25 2016 @@ -2013,10 +2013,33 @@ ClangASTContext::CreateFunctionType (AST bool is_variadic, unsigned type_quals) { - assert (ast != nullptr); + if (ast == nullptr) + return CompilerType(); // invalid AST + + if (!result_type || !ClangUtil::IsClangType(result_type)) + return CompilerType(); // invalid return type + std::vector<QualType> qual_type_args; + if (num_args > 0 && args == nullptr) + return CompilerType(); // invalid argument array passed in + + // Verify that all arguments are valid and the right type for (unsigned i=0; i<num_args; ++i) - qual_type_args.push_back(ClangUtil::GetQualType(args[i])); + { + if (args[i]) + { + // Make sure we have a clang type in args[i] and not a type from another + // language whose name might match + const bool is_clang_type = ClangUtil::IsClangType(args[i]); + lldbassert(is_clang_type); + if (is_clang_type) + qual_type_args.push_back(ClangUtil::GetQualType(args[i])); + else + return CompilerType(); // invalid argument type (must be a clang type) + } + else + return CompilerType(); // invalid argument type (empty) + } // TODO: Detect calling convention in DWARF? FunctionProtoType::ExtProtoInfo proto_info; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits