shafik created this revision.
shafik added reviewers: jingham, aprantl, teemperor, rsmith.

This will fix a bug where during expression parsing we are not setting a 
`CXXRecordDecl` to not be passed in registers and the resulting code generation 
is wrong.

The DWARF attribute `DW_CC_pass_by_reference` tells us that we should not be 
passing in registers i.e. `RAA_Indirect`.

This change depends this clang change which fixes the fact that the ASTImporter 
does not copy `RecordDeclBits` for `CXXRecordDecl`:

  https://reviews.llvm.org/D61140


https://reviews.llvm.org/D61146

Files:
  
packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile
  
packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py
  
packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -959,6 +959,15 @@
           }
         }
 
+        if (calling_convention == llvm::dwarf::DW_CC_pass_by_reference) {
+          clang::CXXRecordDecl *record_decl =
+              m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
+          if (record_decl) {
+            record_decl->setArgPassingRestrictions(
+                clang::RecordDecl::APK_CannotPassInRegs);
+          }
+        }
+
       } break;
 
       case DW_TAG_enumeration_type: {
Index: packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp
@@ -0,0 +1,40 @@
+struct Bounds {
+  Bounds() = default;
+  Bounds(const Bounds &b);
+
+  int x, y;
+};
+
+Bounds::Bounds(const Bounds &b) : x(b.x), y(b.y) {}
+
+class Shape {
+    static Shape *sp;
+public:
+  static Shape *empty_shape() { return sp;}
+
+  bool check() const { return this == sp;}
+
+  void get_bounds(Bounds &bounds) const{
+    if (check())
+    {
+      bounds.x = 1;
+      bounds.y = 2;
+      return;
+    }
+  }
+
+  Bounds bounds() const {
+      Bounds b;
+      get_bounds(b);
+      return b;
+  }
+};
+
+Shape shape;
+Shape *Shape::sp=&shape;
+
+int main() {
+    Shape s;
+
+    return Shape::empty_shape()->bounds().x; // break here
+}
Index: packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py
@@ -0,0 +1,29 @@
+"""
+This is a test to ensure that both lldb is reconstructing the right
+calling convention for a CXXRecordDecl as represented by:
+
+   DW_CC_pass_by_reference
+   DW_CC_pass_by_value
+
+and to also make sure that the ASTImporter is copying over this
+setting when importing the CXXRecordDecl via setArgPassingRestrictions.
+"""
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestArgumentPassingRestrictions(TestBase):
+
+  mydir = TestBase.compute_mydir(__file__)
+
+  def test_argument_passing_restrictions(self):
+    self.build()
+
+    lldbutil.run_to_source_breakpoint(self, '// break here',
+            lldb.SBFileSpec("main.cpp", False))
+
+    self.expect("expr Shape::empty_shape()->bounds()",
+            substrs=['(Bounds) $0 = (x = 1, y = 2)'])
Index: packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to