[Lldb-commits] [lldb] r143528 - /lldb/trunk/source/Symbol/ClangASTContext.cpp

Greg Clayton gclayton at apple.com
Tue Nov 1 19:06:21 PDT 2011


Author: gclayton
Date: Tue Nov  1 21:06:20 2011
New Revision: 143528

URL: http://llvm.org/viewvc/llvm-project?rev=143528&view=rev
Log:
<rdar://problem/10020849>

Fixed an issue where the DWARF might mention that a class has a constructor
(default, copy or move), destructor, or an assignment operator (copy or move)
and it might not have an actual implementation in your code. Then you try and
use this struct or class in an expression and the JIT would ask for the 
address of these methods that were in the declaration, yet there are none.
We now "do the right thing" for trivial ctors, dtors and assignment operators
by telling the methods that they are are defaulted and trivial, and clang will
then just do all of the work with builtins!


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=143528&r1=143527&r2=143528&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Nov  1 21:06:20 2011
@@ -1733,17 +1733,36 @@
     
     cxx_record_decl->addDecl (cxx_method_decl);
     
+    // Sometimes the debug info will mention a constructor (default/copy/move), 
+    // destructor, or assignment operator (copy/move) but there won't be any
+    // version of this in the code. So we check if the function was artificially
+    // generated and if it is trivial and this lets the compiler/backend know
+    // that it can inline the IR for these when it needs to and we can avoid a
+    // "missing function" error when running expressions.
+    
     if (is_artificial)
     {
-        if (cxx_ctor_decl && cxx_ctor_decl->isCopyConstructor() && cxx_record_decl->hasTrivialCopyConstructor())
+        if (cxx_ctor_decl && 
+            ((cxx_ctor_decl->isDefaultConstructor() && cxx_record_decl->hasTrivialDefaultConstructor ()) ||
+             (cxx_ctor_decl->isCopyConstructor()    && cxx_record_decl->hasTrivialCopyConstructor    ()) ||
+             (cxx_ctor_decl->isMoveConstructor()    && cxx_record_decl->hasTrivialMoveConstructor    ()) ))
         {
             cxx_ctor_decl->setDefaulted();
             cxx_ctor_decl->setTrivial(true);
         }
-        else if (cxx_dtor_decl && cxx_record_decl->hasTrivialDestructor())
+        else if (cxx_dtor_decl)
+        {
+            if (cxx_record_decl->hasTrivialDestructor())
+            {
+                cxx_dtor_decl->setDefaulted();
+                cxx_dtor_decl->setTrivial(true);
+            }
+        }
+        else if ((cxx_method_decl->isCopyAssignmentOperator() && cxx_record_decl->hasTrivialCopyAssignment()) ||
+                 (cxx_method_decl->isMoveAssignmentOperator() && cxx_record_decl->hasTrivialMoveAssignment()))
         {
-            cxx_dtor_decl->setDefaulted();
-            cxx_dtor_decl->setTrivial(true);
+            cxx_method_decl->setDefaulted();
+            cxx_method_decl->setTrivial(true);
         }
     }
     





More information about the lldb-commits mailing list