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

The change D55575 <https://reviews.llvm.org/D55575> modified 
`ClangASTContext::CreateParameterDeclaration` to call 
`decl_ctx->addDecl(decl);` this caused a regression since the existing code in 
`DWARFASTParserClang::ParseChildParameters` is called with the containing 
`DeclContext`:

  m_ast.CreateParameterDeclaration(containing_decl_ctx, name,
                                   type->GetForwardCompilerType(),
                                   storage);

So when end up with cases where we are parsing a parameter for a member 
function and the parameter is added to the `CXXRecordDecl` as opposed to the 
`CXXMethodDecl`. This example is given in the regression test  
`TestBreakpointInMemberFuncWNonPrimitiveParams.py` which without this fix in a 
modules build leads to assert on setting a breakpoint in a member function with 
non primitive parameters. This scenario would be common when debugging LLDB or 
clang.

This leaves a the existing issue which D55571 <https://reviews.llvm.org/D55571> 
tried to fix but apparently did not fix the issue or at least not totally, 
since there are no tests added with the PR it is hard to tell.


https://reviews.llvm.org/D65414

Files:
  
packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/Makefile
  
packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/TestBreakpointInMemberFuncWNonPrimitiveParams.py
  
packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/a.cpp
  
packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/a.h
  
packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/main.cpp
  
packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/module.modulemap
  source/Symbol/ClangASTContext.cpp

Index: source/Symbol/ClangASTContext.cpp
===================================================================
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -2234,7 +2234,6 @@
                           name && name[0] ? &ast->Idents.get(name) : nullptr,
                           ClangUtil::GetQualType(param_type), nullptr,
                           (clang::StorageClass)storage, nullptr);
-  decl_ctx->addDecl(decl);
   return decl;
 }
 
Index: packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/module.modulemap
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/module.modulemap
@@ -0,0 +1,3 @@
+module A {
+  header "a.h"
+}
Index: packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/main.cpp
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/main.cpp
@@ -0,0 +1,15 @@
+#include "a.h"
+#include <cstdio>
+
+bool foo() {
+  A a1;
+  B b1;
+
+  return b1.member_func_a(a1); // break here
+}
+
+int main() {
+  int x = 0;
+
+  return foo();
+}
Index: packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/a.h
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/a.h
@@ -0,0 +1,7 @@
+struct A {
+  bool b(int x);
+};
+
+struct B {
+  bool member_func_a(A a);
+};
Index: packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/a.cpp
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/a.cpp
@@ -0,0 +1,10 @@
+#include "a.h"
+
+bool A::b(int x) {
+  if (x)
+    return true;
+
+  return false;
+}
+
+bool B::member_func_a(A a) { return a.b(10); };
Index: packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/TestBreakpointInMemberFuncWNonPrimitiveParams.py
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/TestBreakpointInMemberFuncWNonPrimitiveParams.py
@@ -0,0 +1,18 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestBreakpointInMemberFuncWNonPrimitiveParams(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @skipUnlessDarwin
+    @add_test_categories(["gmodules"])
+    def test_breakpint_in_member_func_w_non_primitie_params(self):
+        self.build()
+
+        (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here',
+                lldb.SBFileSpec("main.cpp", False))
+
+        self.runCmd("b a.cpp:11");
Index: packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/Makefile
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/cpp/breakpoint_in_member_func_w_non_primitive_params/Makefile
@@ -0,0 +1,19 @@
+LEVEL = ../../../make
+
+CXX_SOURCES = main.cpp a.cpp
+
+CFLAGS_LIMIT = -c $(CXXFLAGS)
+CFLAGS_NO_LIMIT = -c $(CXXFLAGS)
+
+all: a.out
+
+limit: main.o a.o
+	$(CXX) -fcxx-modules -fmodules -gmodules main.o a.o -o a.out
+
+main.o: main.cpp
+	$(CXX) $(CFLAGS_LIMIT) -fcxx-modules -fmodules -gmodules -c $(SRCDIR)/main.cpp -o main.o -fmodules-cache-path=$(CLANG_MODULE_CACHE_DIR)
+
+a.o: a.cpp
+	$(CXX) $(CFLAGS_NO_DEBUG) -fcxx-modules -fmodules -gmodules -c $(SRCDIR)/a.cpp -o a.o -fmodules-cache-path=$(CLANG_MODULE_CACHE_DIR)
+
+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