[Lldb-commits] [PATCH] D96366: Remove uneeded CopyType from BlockPointerSyntheticFrontEnd

Shafik Yaghmour via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 9 13:35:51 PST 2021


shafik created this revision.
shafik added reviewers: teemperor, aprantl.
shafik requested review of this revision.

`BlockPointerSyntheticFrontEnd` does a `CopyType` which results in it copying the type back into its own context. This will result in a call to `ASTImporterDelegate::setOrigin` with `&decl->getASTContext() == origin.ctx` this can result in an infinite recursion later on in `ASTImporter` since it will attempt to find the decl in its origin which will be itself.


https://reviews.llvm.org/D96366

Files:
  lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
  lldb/test/API/lang/c/blocks/TestBlocks.py
  lldb/test/API/lang/c/blocks/main.c


Index: lldb/test/API/lang/c/blocks/main.c
===================================================================
--- lldb/test/API/lang/c/blocks/main.c
+++ lldb/test/API/lang/c/blocks/main.c
@@ -1,5 +1,17 @@
 #include <stdio.h>
 
+struct CG {int x; int y;};
+
+int g(int (^callback)(struct CG)) {
+   struct CG cg = {.x=1,.y=2};
+
+   int z = callback(cg); // Set breakpoint 2 here.
+
+   return z;
+}
+
+int h(struct CG cg){return 42;}
+
 int main()
 {
     int c = 1;
@@ -17,5 +29,12 @@
     printf("%d\n", add(3, 4));
     printf("%d\n", neg(-5)); // Set breakpoint 1 here.
 
+    int (^add_struct)(struct CG) = ^int(struct CG cg)
+    {
+        return cg.x + cg.y;
+    };
+
+    g(add_struct);
+
     return 0;
 }
Index: lldb/test/API/lang/c/blocks/TestBlocks.py
===================================================================
--- lldb/test/API/lang/c/blocks/TestBlocks.py
+++ lldb/test/API/lang/c/blocks/TestBlocks.py
@@ -20,6 +20,7 @@
         # Find the line numbers to break at.
         self.lines.append(line_number('main.c', '// Set breakpoint 0 here.'))
         self.lines.append(line_number('main.c', '// Set breakpoint 1 here.'))
+        self.lines.append(line_number('main.c', '// Set breakpoint 2 here.'))
 
     def launch_common(self):
         self.build()
@@ -51,6 +52,10 @@
         self.expect("expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY,
                     substrs=["= 12"])
 
+        self.wait_for_breakpoint()
+
+        self.expect_expr("h(cg)", result_type="int", result_value="42")
+
     @skipUnlessDarwin
     def test_define(self):
         self.launch_common()
Index: lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -74,14 +74,12 @@
     const CompilerType reserved_type =
         clang_ast_context->GetBasicType(lldb::eBasicTypeInt);
     const char *const FuncPtr_name("__FuncPtr");
-    const CompilerType FuncPtr_type =
-        clang_ast_importer->CopyType(*clang_ast_context, function_pointer_type);
 
     m_block_struct_type = clang_ast_context->CreateStructForIdentifier(
         ConstString(), {{isa_name, isa_type},
                         {flags_name, flags_type},
                         {reserved_name, reserved_type},
-                        {FuncPtr_name, FuncPtr_type}});
+                        {FuncPtr_name, function_pointer_type}});
   }
 
   ~BlockPointerSyntheticFrontEnd() override = default;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96366.322486.patch
Type: text/x-patch
Size: 2577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210209/2affbd7e/attachment-0001.bin>


More information about the lldb-commits mailing list