[PATCH] D125695: [clang][DebugInfo] Allow function-local type-like entities to be scoped within a lexical block (5/5)

2022-06-06 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 434541.
krisb marked an inline comment as done.
krisb added a comment.

Applied review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125695/new/

https://reviews.llvm.org/D125695

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-local-types.cpp

Index: clang/test/CodeGenCXX/debug-info-local-types.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-local-types.cpp
@@ -0,0 +1,101 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=CHECK,LIMITED
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=unused-types -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=UNUSED_TYPES
+
+void test() {
+  {
+struct S { int a; };
+class C { int b; };
+S s;
+{
+  C c;
+}
+  }
+
+  {
+typedef char Char;
+using Int = int;
+Char c;
+{
+  Int i;
+}
+  }
+
+  {
+enum E { a, b, c };
+enum class T { aa, bb, cc };
+E e = E::a;
+{
+  T t = T::aa;
+}
+  }
+
+  {
+union U { int i; char c; };
+U u = { 256 };
+  }
+}
+
+// LIMITED: distinct !DICompileUnit
+// LIMITED-NOT: retainedTypes:
+
+// CHECK: !DILocalVariable(name: "s", scope: [[LBSCOPE_1:![0-9]+]]
+// CHECK-SAME:type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE_1]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB1_DECLS:![0-9]+]]
+// CHECK: [[LB1_DECLS]] = !{[[STRUCT]], [[CLASS:![0-9]+]]}
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", scope: [[LBSCOPE_1]]
+// CHECK: [[CLASS]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", scope: [[LBSCOPE_1]]
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_11:![0-9]+]]
+// CHECK-SAME:type: [[CLASS]]
+// CHECK: [[LBSCOPE_11]] = distinct !DILexicalBlock(scope: [[LBSCOPE_1]]
+//
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_2:![0-9]+]]
+// CHECK-SAME:type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[LBSCOPE_2]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB2_DECLS:![0-9]+]]
+// CHECK: [[LB2_DECLS]] = !{[[TYPEDEF]], [[USING:![0-9]+]]}
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Char", scope: [[LBSCOPE_2]]
+// CHECK: [[USING]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Int", scope: [[LBSCOPE_2]]
+// CHECK: !DILocalVariable(name: "i", scope: [[LBSCOPE_21:![0-9]+]]
+// CHECK-SAME:type: [[USING]]
+// CHECK: [[LBSCOPE_21]] = distinct !DILexicalBlock(scope: [[LBSCOPE_2]]
+//
+// CHECK: !DILocalVariable(name: "e", scope: [[LBSCOPE_3:![0-9]+]]
+// CHECK-SAME:type: [[ENUM:![0-9]+]]
+// CHECK: [[LBSCOPE_3]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB3_DECLS:![0-9]+]]
+// CHECK: [[LB3_DECLS]] = !{[[ENUM]], [[ENUM_CLASS:![0-9]+]]}
+// CHECK: [[ENUM]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E", scope: [[LBSCOPE_3]]
+// CHECK: [[ENUM_CLASS]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "T", scope: [[LBSCOPE_3]]
+// CHECK: !DILocalVariable(name: "t", scope: [[LBSCOPE_31:![0-9]+]]
+// CHECK-SAME:type: [[ENUM_CLASS]]
+// CHECK: [[LBSCOPE_31]] = distinct !DILexicalBlock(scope: [[LBSCOPE_3]]
+//
+// CHECK: !DILocalVariable(name: "u", scope: [[LBSCOPE_4:![0-9]+]]
+// CHECK-SAME:type: [[UNION:![0-9]+]]
+// CHECK: [[LBSCOPE_4]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB4_DECLS:![0-9]+]]
+// CHECK: [[LB4_DECLS]] = !{[[UNION]]}
+// CHECK: [[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "U", scope: [[LBSCOPE_4]]
+
+void test_unused() {
+  {
+struct X {};
+typedef int Y; // typedef doesn't go to retainedTypes.
+enum Z { z };
+  }
+}
+
+// UNUSED_TYPES: distinct !DICompileUnit
+// UNUSED_TYPES-SAME: retainedTypes: [[RETAINED_TYPES:![0-9]+]]
+//
+// struct, class, char, int, enum, enum class, union, unused struct, unused enum, ::F
+// UNUSED_TYPES: [[RETAINED_TYPES]] = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, [[UNUSED_STRUCT:![0-9]+]], [[UNUSED_ENUM:![0-9]+]], !{{.*}}}
+// UNUSED_TYPES: [[UNUSED_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[UNUSED_LB:![0-9]+]]
+// UNUSED_TYPES: [[UNUSED_LB]] = distinct !DILexicalBlock({{.*}}, localDecls: [[UNUSED_LB_DECLS:![0-9]+]]
+// UNUSED_TYPES: [[UNUSED_LB_DECLS]] = !{[[UNUSED_STRUCT]], [[UNUSED_ENUM]]}
+// UNUSED_TYPES: [[UNUSED_ENUM]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Z", scope: [[UNUSED_LB]]
+
+void test_lambda() {
+  auto t = []() { struct F {}; return F(); };
+  auto v = t();
+}
+
+// TODO: ::F doesn't have its scope 

[PATCH] D125695: [clang][DebugInfo] Allow function-local type-like entities to be scoped within a lexical block (5/5)

2022-05-27 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:231-234
+  assert(LexicalBlockMap.find() == LexicalBlockMap.end() &&
+ "D is already mapped to a lexical block scope");
+  if (!LexicalBlockStack.empty())
+LexicalBlockMap.insert({, LexicalBlockStack.back()});

Rather than doing an extra lookup in the assert, could probably check the 
return value of `insert` instead and assert based on that?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125695/new/

https://reviews.llvm.org/D125695

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125695: [clang][DebugInfo] Allow function-local type-like entities to be scoped within a lexical block (5/5)

2022-05-26 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

Sgtm.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125695/new/

https://reviews.llvm.org/D125695

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125695: [clang][DebugInfo] Allow function-local type-like entities to be scoped within a lexical block (5/5)

2022-05-16 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added reviewers: dblaikie, aprantl, probinson.
Herald added a project: All.
krisb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a part from D113743  split to make it 
easier to test and review.

It also enables lexical blocks as a scope for types and type-like entities
only if -debugger-tunning=gdb. lldb can't (yet) handle lexical block scoped
types (see D115277  for details), other 
debuggers were not verified (yet).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125695

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-local-types.cpp

Index: clang/test/CodeGenCXX/debug-info-local-types.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-local-types.cpp
@@ -0,0 +1,101 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=CHECK,LIMITED
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=unused-types -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=UNUSED_TYPES
+
+void test() {
+  {
+struct S { int a; };
+class C { int b; };
+S s;
+{
+  C c;
+}
+  }
+
+  {
+typedef char Char;
+using Int = int;
+Char c;
+{
+  Int i;
+}
+  }
+
+  {
+enum E { a, b, c };
+enum class T { aa, bb, cc };
+E e = E::a;
+{
+  T t = T::aa;
+}
+  }
+
+  {
+union U { int i; char c; };
+U u = { 256 };
+  }
+}
+
+// LIMITED: distinct !DICompileUnit
+// LIMITED-NOT: retainedTypes:
+
+// CHECK: !DILocalVariable(name: "s", scope: [[LBSCOPE_1:![0-9]+]]
+// CHECK-SAME:type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE_1]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB1_DECLS:![0-9]+]]
+// CHECK: [[LB1_DECLS]] = !{[[STRUCT]], [[CLASS:![0-9]+]]}
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", scope: [[LBSCOPE_1]]
+// CHECK: [[CLASS]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", scope: [[LBSCOPE_1]]
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_11:![0-9]+]]
+// CHECK-SAME:type: [[CLASS]]
+// CHECK: [[LBSCOPE_11]] = distinct !DILexicalBlock(scope: [[LBSCOPE_1]]
+//
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_2:![0-9]+]]
+// CHECK-SAME:type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[LBSCOPE_2]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB2_DECLS:![0-9]+]]
+// CHECK: [[LB2_DECLS]] = !{[[TYPEDEF]], [[USING:![0-9]+]]}
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Char", scope: [[LBSCOPE_2]]
+// CHECK: [[USING]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Int", scope: [[LBSCOPE_2]]
+// CHECK: !DILocalVariable(name: "i", scope: [[LBSCOPE_21:![0-9]+]]
+// CHECK-SAME:type: [[USING]]
+// CHECK: [[LBSCOPE_21]] = distinct !DILexicalBlock(scope: [[LBSCOPE_2]]
+//
+// CHECK: !DILocalVariable(name: "e", scope: [[LBSCOPE_3:![0-9]+]]
+// CHECK-SAME:type: [[ENUM:![0-9]+]]
+// CHECK: [[LBSCOPE_3]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB3_DECLS:![0-9]+]]
+// CHECK: [[LB3_DECLS]] = !{[[ENUM]], [[ENUM_CLASS:![0-9]+]]}
+// CHECK: [[ENUM]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E", scope: [[LBSCOPE_3]]
+// CHECK: [[ENUM_CLASS]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "T", scope: [[LBSCOPE_3]]
+// CHECK: !DILocalVariable(name: "t", scope: [[LBSCOPE_31:![0-9]+]]
+// CHECK-SAME:type: [[ENUM_CLASS]]
+// CHECK: [[LBSCOPE_31]] = distinct !DILexicalBlock(scope: [[LBSCOPE_3]]
+//
+// CHECK: !DILocalVariable(name: "u", scope: [[LBSCOPE_4:![0-9]+]]
+// CHECK-SAME:type: [[UNION:![0-9]+]]
+// CHECK: [[LBSCOPE_4]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB4_DECLS:![0-9]+]]
+// CHECK: [[LB4_DECLS]] = !{[[UNION]]}
+// CHECK: [[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "U", scope: [[LBSCOPE_4]]
+
+void test_unused() {
+  {
+struct X {};
+typedef int Y; // typedef doesn't go to retainedTypes.
+enum Z { z };
+  }
+}
+
+// UNUSED_TYPES: distinct !DICompileUnit
+// UNUSED_TYPES-SAME: retainedTypes: [[RETAINED_TYPES:![0-9]+]]
+//
+// struct, class, char, int, enum, enum class, union, unused struct, unused enum, ::F
+// UNUSED_TYPES: [[RETAINED_TYPES]] = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, [[UNUSED_STRUCT:![0-9]+]], [[UNUSED_ENUM:![0-9]+]], !{{.*}}}
+// UNUSED_TYPES: [[UNUSED_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[UNUSED_LB:![0-9]+]]
+// UNUSED_TYPES: [[UNUSED_LB]] = distinct