[Lldb-commits] [lldb] r238476 - If we see an external function in the symbols, make

Sean Callanan scallanan at apple.com
Thu May 28 13:07:44 PDT 2015


Author: spyffe
Date: Thu May 28 15:07:44 2015
New Revision: 238476

URL: http://llvm.org/viewvc/llvm-project?rev=238476&view=rev
Log:
If we see an external function in the symbols, make
it an extern "C" function instead of a C++ function
so that Clang doesn't emit a mangled function reference.

Also removed the hack in ClangExpressionDeclMap that
works around this.

Modified:
    lldb/trunk/include/lldb/Expression/ClangASTSource.h
    lldb/trunk/source/Expression/ClangASTSource.cpp
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangASTSource.h?rev=238476&r1=238475&r2=238476&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangASTSource.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangASTSource.h Thu May 28 15:07:44 2015
@@ -476,8 +476,12 @@ struct NameSearchContext {
     ///
     /// @param[in] type
     ///     The opaque QualType for the FunDecl being registered.
+    ///
+    /// @param[in] extern_c
+    ///     If true, build an extern "C" linkage specification for this.
     //------------------------------------------------------------------
-    clang::NamedDecl *AddFunDecl(const ClangASTType &type);
+    clang::NamedDecl *AddFunDecl(const ClangASTType &type,
+                                 bool extern_c = false);
     
     //------------------------------------------------------------------
     /// Create a FunDecl with the name being searched for and generic

Modified: lldb/trunk/source/Expression/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=238476&r1=238475&r2=238476&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Expression/ClangASTSource.cpp Thu May 28 15:07:44 2015
@@ -1926,7 +1926,7 @@ NameSearchContext::AddVarDecl(const Clan
 }
 
 clang::NamedDecl *
-NameSearchContext::AddFunDecl (const ClangASTType &type)
+NameSearchContext::AddFunDecl (const ClangASTType &type, bool extern_c)
 {
     assert (type && "Type for variable must be valid!");
 
@@ -1945,15 +1945,26 @@ NameSearchContext::AddFunDecl (const Cla
     const bool isInlineSpecified = false;
     const bool hasWrittenPrototype = true;
     const bool isConstexprSpecified = false;
+    
+    clang::DeclContext *context = const_cast<DeclContext*>(m_decl_context);
+    
+    if (extern_c) {
+        context = LinkageSpecDecl::Create(*ast,
+                                          context,
+                                          SourceLocation(),
+                                          SourceLocation(),
+                                          clang::LinkageSpecDecl::LanguageIDs::lang_c,
+                                          false);
+    }
 
     clang::FunctionDecl *func_decl = FunctionDecl::Create (*ast,
-                                                           const_cast<DeclContext*>(m_decl_context),
+                                                           context,
                                                            SourceLocation(),
                                                            SourceLocation(),
                                                            m_decl_name.getAsIdentifierInfo(),
                                                            qual_type,
                                                            NULL,
-                                                           SC_Static,
+                                                           SC_Extern,
                                                            isInlineSpecified,
                                                            hasWrittenPrototype,
                                                            isConstexprSpecified);
@@ -1976,7 +1987,7 @@ NameSearchContext::AddFunDecl (const Cla
             QualType arg_qual_type (func_proto_type->getParamType(ArgIndex));
 
             parm_var_decls.push_back(ParmVarDecl::Create (*ast,
-                                                          const_cast<DeclContext*>(m_decl_context),
+                                                          const_cast<DeclContext*>(context),
                                                           SourceLocation(),
                                                           SourceLocation(),
                                                           NULL,
@@ -2012,7 +2023,7 @@ NameSearchContext::AddGenericFunDecl()
                                                                                 ArrayRef<QualType>(),                                        // argument types
                                                                                 proto_info));
 
-    return AddFunDecl(ClangASTType (m_ast_source.m_ast_context, generic_function_type));
+    return AddFunDecl(ClangASTType (m_ast_source.m_ast_context, generic_function_type), true);
 }
 
 clang::NamedDecl *

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=238476&r1=238475&r2=238476&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Thu May 28 15:07:44 2015
@@ -596,29 +596,6 @@ ClangExpressionDeclMap::GetFunctionAddre
             sc_list_size = sc_list.GetSize();
         }
     }
-    
-    if (sc_list_size == 0)
-    {
-        // Sometimes we get a mangled name for a global function that actually should be "extern C."
-        // This is a hack to compensate.
-        
-        const bool is_mangled = true;
-        Mangled mangled(name, is_mangled);
-                
-        CPPLanguageRuntime::MethodName method_name(mangled.GetDemangledName());
-
-        // the C++ context must be empty before we can think of searching for symbol by a simple basename
-        if (method_name.GetContext().empty())
-        {
-            llvm::StringRef basename = method_name.GetBasename();
-            
-            if (!basename.empty())
-            {
-                FindCodeSymbolInContext(ConstString(basename), m_parser_vars->m_sym_ctx, sc_list);
-                sc_list_size = sc_list.GetSize();
-            }
-        }
-    }
 
     lldb::addr_t intern_callable_load_addr = LLDB_INVALID_ADDRESS;
 





More information about the lldb-commits mailing list