[clang] 6beddd6 - Revert "[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)"

2023-11-07 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-11-08T00:29:24+01:00
New Revision: 6beddd668adf8e6bddbbc58ec02e4728dd889e9e

URL: 
https://github.com/llvm/llvm-project/commit/6beddd668adf8e6bddbbc58ec02e4728dd889e9e
DIFF: 
https://github.com/llvm/llvm-project/commit/6beddd668adf8e6bddbbc58ec02e4728dd889e9e.diff

LOG: Revert "[DebugMetadata][DwarfDebug] Support function-local types in 
lexical block scopes (4/7)"

This caused assert:
llvm/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp:110:
void llvm::DwarfFile::addScopeVariable(LexicalScope *, DbgVariable *):
Assertion `Ret.second' failed.

See comments https://reviews.llvm.org/D144006#4656350.

This reverts commit 3b449bd46a11a55a40cbc0016a99b202fa05248e.

Added: 
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGen/debug-info-codeview-unnamed.c
clang/test/CodeGen/debug-info-unused-types.c
clang/test/CodeGen/debug-info-unused-types.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/include/llvm/IR/DebugInfo.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/set.ll
llvm/unittests/Transforms/Utils/CloningTest.cpp

Removed: 
llvm/test/Bitcode/clone-local-types.ll
llvm/test/DebugInfo/Generic/inlined-local-type.ll
llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
llvm/test/DebugInfo/Generic/lexical-block-types.ll
llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import2.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index 16ffb3682236f18..bd2a7543e56b2ba 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
+  // LINUX-SAME: )
+  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE]]
-  // LINUX-SAME: )
   //
-  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
+  // MSVC-SAME:  )
+  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
-  // MSVC-SAME:  )
 
   return 0;
 }

diff  --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 31d608d92a06b41..3e9f7b07658e36e 100644
--- a/clang/test/CodeGen/debug-info-unused-types.c
+++ b/clang/test/CodeGen/debug-info-unused-types.c
@@ -18,15 +18,13 @@ void quux(void) {
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], 
[[TYPE4:![0-9]+]], {{![0-9]+}}}
-// CHECK: [[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
-// CHECK: [[TYPE3]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
-// CHECK: [[TYPE4]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
-// CHECK: [[SP:![0-9]+]] = distinct !DISubprogram(name: "quux", {{.*}}, 
retainedNodes: [[SPRETNODES:![0-9]+]]
-// CHECK

[llvm] [clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)

2023-11-07 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

Reverted due to Chromium build crash 
https://bugs.chromium.org/p/chromium/issues/detail?id=1500022.

https://github.com/llvm/llvm-project/pull/68986
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)

2023-10-31 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/68986

>From d61f109dcb92db45fa8f6ce7503409edcbfbce63 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Tue, 18 Jul 2023 14:22:46 +0200
Subject: [PATCH 1/3] [DebugMetadata][DwarfDebug] Support function-local types
 in lexical block scopes (4/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Similar to imported declarations, the patch tracks function-local types in
DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with
the aforementioned metadata change and provided a support of function-local
types scoped within a lexical block.

The patch assumes that DICompileUnit's 'enums field' no longer tracks local
types and DwarfDebug would assert if any locally-scoped types get placed there.

Reviewed By: jmmartinez

Differential Revision: https://reviews.llvm.org/D144006
---
 .../CodeGen/debug-info-codeview-unnamed.c |  16 +-
 clang/test/CodeGen/debug-info-unused-types.c  |  16 +-
 .../test/CodeGen/debug-info-unused-types.cpp  |  14 +-
 clang/test/CodeGenCXX/debug-info-access.cpp   |   2 +-
 .../CodeGenCXX/debug-info-anon-union-vars.cpp |  12 +-
 .../debug-info-codeview-unnamed.cpp   | 110 +++--
 .../debug-info-gline-tables-only-codeview.cpp |   4 +-
 clang/test/CodeGenCXX/debug-lambda-this.cpp   |   4 +-
 llvm/include/llvm/IR/DIBuilder.h  |   6 +-
 llvm/include/llvm/IR/DebugInfo.h  |   1 +
 llvm/lib/Bitcode/Reader/MetadataLoader.cpp|  86 ++--
 .../CodeGen/AsmPrinter/DwarfCompileUnit.cpp   |  60 ++-
 .../lib/CodeGen/AsmPrinter/DwarfCompileUnit.h |  16 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  13 +-
 llvm/lib/IR/DIBuilder.cpp |  37 +-
 llvm/lib/IR/DebugInfo.cpp |  11 +-
 llvm/lib/IR/Verifier.cpp  |   6 +-
 llvm/lib/Transforms/Utils/CloneFunction.cpp   |   7 +-
 llvm/test/Bitcode/upgrade-cu-locals.ll|  68 +--
 llvm/test/Bitcode/upgrade-cu-locals.ll.bc | Bin 2688 -> 2780 bytes
 .../DebugInfo/Generic/inlined-local-type.ll   | 128 ++
 .../Generic/lexical-block-retained-types.ll   |  55 +++
 .../DebugInfo/Generic/lexical-block-types.ll  | 425 ++
 .../Generic/verifier-invalid-disubprogram.ll  |   2 +-
 .../X86/local-type-as-template-parameter.ll   | 161 +++
 llvm/test/DebugInfo/X86/set.ll|   4 +-
 .../split-dwarf-local-import.ll   |   1 -
 .../split-dwarf-local-import2.ll  |   1 -
 .../split-dwarf-local-import3.ll  |   0
 .../Transforms/Utils/CloningTest.cpp  |  93 
 30 files changed, 1165 insertions(+), 194 deletions(-)
 create mode 100644 llvm/test/DebugInfo/Generic/inlined-local-type.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-types.ll
 create mode 100644 llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import2.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import3.ll (100%)

diff --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2ba..16ffb3682236f18 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE]]
+  // LINUX-SAME: )
   //
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
-  // MSVC-SAME:  )
-  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
+  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
+  // MSVC-SAME:  )
 
   return 0;
 }
diff --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 3e9f7b07658e36e..31d608d92a06b41 100644
--- a/clang/test/CodeGen/debug-info-unu

[clang] [llvm] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)

2023-10-31 Thread Vladislav Dzhidzhoev via cfe-commits


@@ -731,6 +731,29 @@ class MetadataLoader::MetadataLoaderImpl {
 upgradeCULocals();
   }
 
+  void cloneLocalTypes() {
+for (int I = MetadataList.size() - 1; I >= 0; --I) {

dzhidzhoev wrote:

Sorry, it's just a residue from the function draft. Fixed that.

https://github.com/llvm/llvm-project/pull/68986
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)

2023-11-02 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/68986

>From 3b449bd46a11a55a40cbc0016a99b202fa05248e Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Tue, 18 Jul 2023 14:22:46 +0200
Subject: [PATCH] [DebugMetadata][DwarfDebug] Support function-local types in
 lexical block scopes (4/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Similar to imported declarations, the patch tracks function-local types in
DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with
the aforementioned metadata change and provided a support of function-local
types scoped within a lexical block.

The patch assumes that DICompileUnit's 'enums field' no longer tracks local
types and DwarfDebug would assert if any locally-scoped types get placed there.

Reviewed By: jmmartinez
Authored-by: Kristina Bessonova 
Differential Revision: https://reviews.llvm.org/D144006
---
 .../CodeGen/debug-info-codeview-unnamed.c |  16 +-
 clang/test/CodeGen/debug-info-unused-types.c  |  16 +-
 .../test/CodeGen/debug-info-unused-types.cpp  |  14 +-
 clang/test/CodeGenCXX/debug-info-access.cpp   |   2 +-
 .../CodeGenCXX/debug-info-anon-union-vars.cpp |  12 +-
 .../debug-info-codeview-unnamed.cpp   | 110 +++--
 .../debug-info-gline-tables-only-codeview.cpp |   4 +-
 clang/test/CodeGenCXX/debug-lambda-this.cpp   |   4 +-
 llvm/include/llvm/IR/DIBuilder.h  |   6 +-
 llvm/include/llvm/IR/DebugInfo.h  |   1 +
 llvm/lib/Bitcode/Reader/MetadataLoader.cpp| 111 +++--
 .../CodeGen/AsmPrinter/DwarfCompileUnit.cpp   |  60 ++-
 .../lib/CodeGen/AsmPrinter/DwarfCompileUnit.h |  16 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  13 +-
 llvm/lib/IR/DIBuilder.cpp |  37 +-
 llvm/lib/IR/DebugInfo.cpp |  11 +-
 llvm/lib/IR/Verifier.cpp  |   6 +-
 llvm/lib/Transforms/Utils/CloneFunction.cpp   |   7 +-
 llvm/test/Bitcode/clone-local-types.ll|  46 ++
 llvm/test/Bitcode/upgrade-cu-locals.ll|  68 +--
 llvm/test/Bitcode/upgrade-cu-locals.ll.bc | Bin 2688 -> 2780 bytes
 .../DebugInfo/Generic/inlined-local-type.ll   | 128 ++
 .../Generic/lexical-block-retained-types.ll   |  55 +++
 .../DebugInfo/Generic/lexical-block-types.ll  | 425 ++
 .../Generic/verifier-invalid-disubprogram.ll  |   2 +-
 .../X86/local-type-as-template-parameter.ll   | 161 +++
 llvm/test/DebugInfo/X86/set.ll|   4 +-
 .../split-dwarf-local-import.ll   |   1 -
 .../split-dwarf-local-import2.ll  |   1 -
 .../split-dwarf-local-import3.ll  |   0
 .../Transforms/Utils/CloningTest.cpp  |  93 
 31 files changed, 1236 insertions(+), 194 deletions(-)
 create mode 100644 llvm/test/Bitcode/clone-local-types.ll
 create mode 100644 llvm/test/DebugInfo/Generic/inlined-local-type.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-types.ll
 create mode 100644 llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import2.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import3.ll (100%)

diff --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2ba..16ffb3682236f18 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE]]
+  // LINUX-SAME: )
   //
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
-  // MSVC-SAME:  )
-  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
+  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
+  // MSVC-SAME:  )
 
   return 0;
 }
diff --git a/clang/test/CodeGen/debug-info-unus

[clang] 3b449bd - [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)

2023-11-02 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-11-02T17:44:52+01:00
New Revision: 3b449bd46a11a55a40cbc0016a99b202fa05248e

URL: 
https://github.com/llvm/llvm-project/commit/3b449bd46a11a55a40cbc0016a99b202fa05248e
DIFF: 
https://github.com/llvm/llvm-project/commit/3b449bd46a11a55a40cbc0016a99b202fa05248e.diff

LOG: [DebugMetadata][DwarfDebug] Support function-local types in lexical block 
scopes (4/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Similar to imported declarations, the patch tracks function-local types in
DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with
the aforementioned metadata change and provided a support of function-local
types scoped within a lexical block.

The patch assumes that DICompileUnit's 'enums field' no longer tracks local
types and DwarfDebug would assert if any locally-scoped types get placed there.

Reviewed By: jmmartinez
Authored-by: Kristina Bessonova 
Differential Revision: https://reviews.llvm.org/D144006

Added: 
llvm/test/Bitcode/clone-local-types.ll
llvm/test/DebugInfo/Generic/inlined-local-type.ll
llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
llvm/test/DebugInfo/Generic/lexical-block-types.ll
llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import2.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGen/debug-info-codeview-unnamed.c
clang/test/CodeGen/debug-info-unused-types.c
clang/test/CodeGen/debug-info-unused-types.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/include/llvm/IR/DebugInfo.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/set.ll
llvm/unittests/Transforms/Utils/CloningTest.cpp

Removed: 
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2ba..16ffb3682236f18 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE]]
+  // LINUX-SAME: )
   //
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
-  // MSVC-SAME:  )
-  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
+  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
+  // MSVC-SAME:  )
 
   return 0;
 }

diff  --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 3e9f7b07658e36e..31d608d92a06b41 100644
--- a/clang/test/CodeGen/debug-info-unused-types.c
+++ b/clang/test/CodeGen/debug-info-unused-types.c
@@ -18,13 +18,15 @@ void quux(void) {
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name

[llvm] [clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)

2023-11-02 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev closed 
https://github.com/llvm/llvm-project/pull/68986
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2023-12-26 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

@dwblaikie
Could you please take a look at this when you have a chance?

https://github.com/llvm/llvm-project/pull/75385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2024-01-11 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/75385

>From 2953d4adcb36c28d12a3e3f8febf0995ef22c0d9 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Tue, 18 Jul 2023 14:22:46 +0200
Subject: [PATCH] [DebugMetadata][DwarfDebug] Support function-local types in
 lexical block scopes (4/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Similar to imported declarations, the patch tracks function-local types in
DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with
the aforementioned metadata change and provided a support of function-local
types scoped within a lexical block.

The patch assumes that DICompileUnit's 'enums field' no longer tracks local
types and DwarfDebug would assert if any locally-scoped types get placed there.

Additionally, if DISubprogram is not cloned in CloneFunctionInto(),
cloning of its DILocalVariables is avoided.
Otherwise we get duplicated DILocalVariables not tracked in their
subprogram's retainedNodes, that crash LTO with Chromium.

Reviewed By: jmmartinez
Authored-by: Kristina Bessonova 
Differential Revision: https://reviews.llvm.org/D144006
---
 .../CodeGen/debug-info-codeview-unnamed.c |  16 +-
 clang/test/CodeGen/debug-info-unused-types.c  |  16 +-
 .../test/CodeGen/debug-info-unused-types.cpp  |  14 +-
 clang/test/CodeGenCXX/debug-info-access.cpp   |   2 +-
 .../CodeGenCXX/debug-info-anon-union-vars.cpp |  12 +-
 .../debug-info-codeview-unnamed.cpp   | 110 +++--
 .../debug-info-gline-tables-only-codeview.cpp |   4 +-
 clang/test/CodeGenCXX/debug-lambda-this.cpp   |   4 +-
 llvm/include/llvm/IR/DIBuilder.h  |   6 +-
 llvm/include/llvm/IR/DebugInfo.h  |  11 +-
 llvm/lib/Bitcode/Reader/MetadataLoader.cpp| 111 +++--
 .../CodeGen/AsmPrinter/DwarfCompileUnit.cpp   |  60 ++-
 .../lib/CodeGen/AsmPrinter/DwarfCompileUnit.h |  16 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  13 +-
 llvm/lib/IR/DIBuilder.cpp |  39 +-
 llvm/lib/IR/DebugInfo.cpp |  14 +-
 llvm/lib/IR/Verifier.cpp  |   6 +-
 llvm/lib/Transforms/Utils/CloneFunction.cpp   |  15 +-
 llvm/test/Bitcode/clone-local-types.ll|  46 ++
 llvm/test/Bitcode/upgrade-cu-locals.ll|  68 +--
 llvm/test/Bitcode/upgrade-cu-locals.ll.bc | Bin 2688 -> 2780 bytes
 .../DebugInfo/Generic/inlined-local-type.ll   | 128 ++
 .../Generic/lexical-block-retained-types.ll   |  55 +++
 .../DebugInfo/Generic/lexical-block-types.ll  | 425 ++
 .../Generic/verifier-invalid-disubprogram.ll  |   2 +-
 .../X86/local-type-as-template-parameter.ll   | 161 +++
 llvm/test/DebugInfo/X86/set.ll|   4 +-
 .../split-dwarf-local-import.ll   |   1 -
 .../split-dwarf-local-import2.ll  |   1 -
 .../split-dwarf-local-import3.ll  |   0
 .../Transforms/Utils/CloningTest.cpp  | 105 +
 31 files changed, 1266 insertions(+), 199 deletions(-)
 create mode 100644 llvm/test/Bitcode/clone-local-types.ll
 create mode 100644 llvm/test/DebugInfo/Generic/inlined-local-type.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-types.ll
 create mode 100644 llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import2.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import3.ll (100%)

diff --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2b..16ffb3682236f1 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE]]
+  // LINUX-SAME: )
   //
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
-  // MSVC-SAME:  )
-  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
+  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:

[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2024-01-11 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev closed 
https://github.com/llvm/llvm-project/pull/75385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2024-02-06 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

> I see what you're saying about the metadata being incorrect; I feel like I've 
> seen it before, but can't pin it down. For the record, all the builds where 
> we saw this assertion were thin/full LTO.
> 
> I've kicked off a reduction of a large reproducer that I have to hand; I'm 
> not immensely confident that it'll complete in a reasonable timescale (i.e.: 
> days) as it's a large project being reduced. If any of the other reporters 
> have anything smaller they can reduce, that'd assist significantly.

Thanks a lot!

https://github.com/llvm/llvm-project/pull/75385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2024-01-31 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

> Hi,
> 
> We're seeing a crash with this commit and reproducer 
> https://gist.github.com/jmorse/b0248c3c9f9195487ffd7c7431a8d15e
> 
> llc: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:2338: virtual void 
> llvm::DwarfDebug::endFunctionImpl(const llvm::MachineFunction *): Assertion 
> `LScopes.getAbstractScopesList().size() == NumAbstractSubprograms && 
> "getOrCreateAbstractScope() inserted an abstract subprogram scope"' failed.
> 
> I'd previously posted the reproducer on 
> https://reviews.llvm.org/D144006#4656728 , however I'd anonymised the IR too 
> much to the point where it was broken in unrelated ways. Revision 2 of the 
> gist, as linked, should produce the crash. I suspect the extra lexical scopes 
> reachable through the retained-nodes list also need to be explored when the 
> LexicalScopes object gets constructed, to avoid scopes being added late and 
> causing containers to invalidate iterators. (Which is what that assertion is 
> there to detect).

It seems that the debug info metadata was already malformed before getting into 
the AsmPrinter pass, probably during the LTO process. I ran into trouble trying 
to find the root cause of the problem, since the information provided by the 
reproducer is not sufficient to investigate it.
Could you please provide an IR dump of the earlier stage of compilation or any 
source code? 

https://github.com/llvm/llvm-project/pull/75385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2024-02-01 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

> ...ah, actually is it malformed because there's a DICompositeType in the 
> retainedNodes list for a DISubprogram? I remember that the verifier 
> considered that illegal before your patch landed, but not after.

Having this commit applied, DICompositeTypes with the scope of DISubprogram 
must appear in the corresponding subprogram's retainedNodes list, so that's not 
the issue.
However, in the reproducer, DICompositeType node no !54 ("type4") has a scope 
value !55 ("plimsoles") but appears in the retainedNodes list of subprogram !49 
("crumpets").
!54 must have either scope of !49 or belong to the subprogram !55's 
retainedNodes list.
This discrepancy was likely to happen in CloneFunctionInto if LTO was used. 
However, I'm not sure about that.

https://github.com/llvm/llvm-project/pull/75385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2024-01-26 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

> Hmmm, that's unexpected -- I reverted the revert (tree here, contains one 
> unrelated commit: 
> https://github.com/jmorse/llvm-project/tree/reapply-localvars-patch) and 
> rebuilt. The assertion-failure occurs just with `llc foobar.ll -o out.o 
> -filetype=obj`, where foobar.ll is the contents of the gist file linked. For 
> the avoidance of doubt, it's:
> 
> ```
> $ wget 
> https://gist.githubusercontent.com/jmorse/b0248c3c9f9195487ffd7c7431a8d15e/raw/e57ca0417b77fe04f9551a0a69ce58f0db697527/gistfile1.txt
> $ mv gistfile1.txt foobar.ll
> $ md5sum foobar.ll
> d6c888d4e163545da596071fb5143377  foobar.ll
> ```
> 
> I don't think there's anything special about the build -- it's a 
> CMAKE_BUILD_TYPE=Release build with LLVM_ENABLE_ASSERTIONS=On, built with 
> clang-14 as shipped by ubuntu.

Thanks a lot! I've stubbornly tried to pass it through llvm-as before feeding 
it to llc.

https://github.com/llvm/llvm-project/pull/75385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2024-01-23 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

> Hi,
> 
> We're seeing a crash with this commit and reproducer 
> https://gist.github.com/jmorse/b0248c3c9f9195487ffd7c7431a8d15e
> 
> llc: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:2338: virtual void 
> llvm::DwarfDebug::endFunctionImpl(const llvm::MachineFunction *): Assertion 
> `LScopes.getAbstractScopesList().size() == NumAbstractSubprograms && 
> "getOrCreateAbstractScope() inserted an abstract subprogram scope"' failed.
> 
> I'd previously posted the reproducer on 
> https://reviews.llvm.org/D144006#4656728 , however I'd anonymised the IR too 
> much to the point where it was broken in unrelated ways. Revision 2 of the 
> gist, as linked, should produce the crash. I suspect the extra lexical scopes 
> reachable through the retained-nodes list also need to be explored when the 
> LexicalScopes object gets constructed, to avoid scopes being added late and 
> causing containers to invalidate iterators. (Which is what that assertion is 
> there to detect).

Hello,

Sorry for bothering you. Could you please share the command you used as an 
interestingness test to reduce the crash? I've tried running llc/opt/ld.lld, 
but I haven't been able to reproduce it :( 

https://github.com/llvm/llvm-project/pull/75385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)

2023-10-19 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

> FWIW, I think we also saw, internally at Google, some significant and 
> surprising (growth in sections, like .debug_loclists and 
> .debug_gnu_pubnames/types) that were a bit surprising/not what I'd have 
> expected of the original committed/reverted patch.
> 
> Could you run a clang build with/without this patch, and compare the two 
> files using `bloaty` ( https://github.com/google/bloaty ) or similar - some 
> comparison of the % growth of each section to see how these patches are 
> affecting debug info size?
> 
> (patch itself sounds OK/looks good)

I haven't mentioned any significant change in the total debug info size. The 
full size of the debug info sections of clang executable file has increased by 
less than 1%. The size of the debug info sections of test-suite object files 
has also increased by 0,02% in total.

https://github.com/llvm/llvm-project/pull/68986
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)

2023-10-27 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

Ping

https://github.com/llvm/llvm-project/pull/68986
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f8aab28 - [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)

2023-09-26 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-09-26T23:07:29+04:00
New Revision: f8aab289b5549086062588fba627b0e4d3a5ab15

URL: 
https://github.com/llvm/llvm-project/commit/f8aab289b5549086062588fba627b0e4d3a5ab15
DIFF: 
https://github.com/llvm/llvm-project/commit/f8aab289b5549086062588fba627b0e4d3a5ab15.diff

LOG: [DebugMetadata][DwarfDebug] Support function-local types in lexical block 
scopes (4/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Similar to imported declarations, the patch tracks function-local types in
DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with
the aforementioned metadata change and provided a support of function-local
types scoped within a lexical block.

The patch assumes that DICompileUnit's 'enums field' no longer tracks local
types and DwarfDebug would assert if any locally-scoped types get placed there.

Reviewed By: jmmartinez

Differential Revision: https://reviews.llvm.org/D144006

Added: 
llvm/test/DebugInfo/Generic/inlined-local-type.ll
llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
llvm/test/DebugInfo/Generic/lexical-block-types.ll
llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import2.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGen/debug-info-codeview-unnamed.c
clang/test/CodeGen/debug-info-unused-types.c
clang/test/CodeGen/debug-info-unused-types.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/include/llvm/IR/DebugInfo.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/set.ll
llvm/unittests/Transforms/Utils/CloningTest.cpp

Removed: 
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2ba..16ffb3682236f18 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE]]
+  // LINUX-SAME: )
   //
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
-  // MSVC-SAME:  )
-  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
+  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
+  // MSVC-SAME:  )
 
   return 0;
 }

diff  --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 3e9f7b07658e36e..31d608d92a06b41 100644
--- a/clang/test/CodeGen/debug-info-unused-types.c
+++ b/clang/test/CodeGen/debug-info-unused-types.c
@@ -18,13 +18,15 @@ void quux(void) {
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "z"
-// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
-// CHECK: [[R

[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading. (PR #68986)

2023-10-13 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev created 
https://github.com/llvm/llvm-project/pull/68986

- [DebugMetadata][DwarfDebug] Support function-local types in lexical block 
scopes (4/7)
- Clone function-local types after metadata loading.

This is a follow-up for https://reviews.llvm.org/D144006, fixing a crash 
reported in Chromium (https://reviews.llvm.org/D144006#4651955).

The very first commit is added for convenience, as it has already been accepted.
The issue with it is that when DIType nodes are loaded, they get deduplicated 
as ODR-uniqued. When two modules get merged by LTO, DISubprogram nodes for the 
same function from different modules are not uniqued, since they are marked as 
distinct, whereas their retained type are, which can violate the ownership 
relationship betweeen DISubprogram and its function-local retained type.
It is fixed by copying a function-local type referenced by one DISubprogram 
through retainedNodes and referencing another in its scope field. The scope of 
copy gets changed correspondingly.

This is meant to be committed along with https://reviews.llvm.org/D144006.


>From d61f109dcb92db45fa8f6ce7503409edcbfbce63 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Tue, 18 Jul 2023 14:22:46 +0200
Subject: [PATCH 1/2] [DebugMetadata][DwarfDebug] Support function-local types
 in lexical block scopes (4/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Similar to imported declarations, the patch tracks function-local types in
DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with
the aforementioned metadata change and provided a support of function-local
types scoped within a lexical block.

The patch assumes that DICompileUnit's 'enums field' no longer tracks local
types and DwarfDebug would assert if any locally-scoped types get placed there.

Reviewed By: jmmartinez

Differential Revision: https://reviews.llvm.org/D144006
---
 .../CodeGen/debug-info-codeview-unnamed.c |  16 +-
 clang/test/CodeGen/debug-info-unused-types.c  |  16 +-
 .../test/CodeGen/debug-info-unused-types.cpp  |  14 +-
 clang/test/CodeGenCXX/debug-info-access.cpp   |   2 +-
 .../CodeGenCXX/debug-info-anon-union-vars.cpp |  12 +-
 .../debug-info-codeview-unnamed.cpp   | 110 +++--
 .../debug-info-gline-tables-only-codeview.cpp |   4 +-
 clang/test/CodeGenCXX/debug-lambda-this.cpp   |   4 +-
 llvm/include/llvm/IR/DIBuilder.h  |   6 +-
 llvm/include/llvm/IR/DebugInfo.h  |   1 +
 llvm/lib/Bitcode/Reader/MetadataLoader.cpp|  86 ++--
 .../CodeGen/AsmPrinter/DwarfCompileUnit.cpp   |  60 ++-
 .../lib/CodeGen/AsmPrinter/DwarfCompileUnit.h |  16 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp|  13 +-
 llvm/lib/IR/DIBuilder.cpp |  37 +-
 llvm/lib/IR/DebugInfo.cpp |  11 +-
 llvm/lib/IR/Verifier.cpp  |   6 +-
 llvm/lib/Transforms/Utils/CloneFunction.cpp   |   7 +-
 llvm/test/Bitcode/upgrade-cu-locals.ll|  68 +--
 llvm/test/Bitcode/upgrade-cu-locals.ll.bc | Bin 2688 -> 2780 bytes
 .../DebugInfo/Generic/inlined-local-type.ll   | 128 ++
 .../Generic/lexical-block-retained-types.ll   |  55 +++
 .../DebugInfo/Generic/lexical-block-types.ll  | 425 ++
 .../Generic/verifier-invalid-disubprogram.ll  |   2 +-
 .../X86/local-type-as-template-parameter.ll   | 161 +++
 llvm/test/DebugInfo/X86/set.ll|   4 +-
 .../split-dwarf-local-import.ll   |   1 -
 .../split-dwarf-local-import2.ll  |   1 -
 .../split-dwarf-local-import3.ll  |   0
 .../Transforms/Utils/CloningTest.cpp  |  93 
 30 files changed, 1165 insertions(+), 194 deletions(-)
 create mode 100644 llvm/test/DebugInfo/Generic/inlined-local-type.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
 create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-types.ll
 create mode 100644 llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import2.ll (98%)
 rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import3.ll (100%)

diff --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2ba..16ffb3682236f18 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DIComp

[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading. (PR #68986)

2023-10-13 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev edited 
https://github.com/llvm/llvm-project/pull/68986
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading. (PR #68986)

2023-10-13 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev edited 
https://github.com/llvm/llvm-project/pull/68986
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)

2023-10-13 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev edited 
https://github.com/llvm/llvm-project/pull/68986
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 38c92c1 - [AArch64] Add patterns for FMADD, FMSUB

2023-08-30 Thread Vladislav Dzhidzhoev via cfe-commits

Author: OverMighty
Date: 2023-08-30T12:39:04+02:00
New Revision: 38c92c1ee2f07e3260c94d51834a97e84f93c708

URL: 
https://github.com/llvm/llvm-project/commit/38c92c1ee2f07e3260c94d51834a97e84f93c708
DIFF: 
https://github.com/llvm/llvm-project/commit/38c92c1ee2f07e3260c94d51834a97e84f93c708.diff

LOG: [AArch64] Add patterns for FMADD, FMSUB

FMADD, FMSUB instructions perform better or the same compared to indexed
FMLA, FMLS.

For example, the Arm Cortex-A55 Software Optimization Guide lists "FP
multiply accumulate" FMADD, FMSUB instructions with a throughput of 2
IPC, whereas it lists "ASIMD FP multiply accumulate, by element" FMLA,
FMLS with a throughput of 1 IPC.

The Arm Cortex-A77 Software Optimization Guide, however, does not
separately list "by element" variants of the "ASIMD FP multiply
accumulate" instructions, which are listed with the same throughput of 2
IPC as "FP multiply accumulate" instructions.

Reviewed By: samtebbs, dzhidzhoev

Differential Revision: https://reviews.llvm.org/D158008

Added: 


Modified: 
clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
llvm/lib/Target/AArch64/AArch64InstrFormats.td
llvm/test/CodeGen/AArch64/complex-deinterleaving-f16-mul.ll
llvm/test/CodeGen/AArch64/fp16_intrinsic_lane.ll
llvm/test/CodeGen/AArch64/neon-scalar-by-elem-fma.ll

Removed: 




diff  --git 
a/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c 
b/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
index 6371339f0a40dd..1d0db697e4fddd 100644
--- a/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
+++ b/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
@@ -103,7 +103,7 @@ float64x1_t test_vfms_lane_f64(float64x1_t a, float64x1_t 
b, float64x1_t v) {
 // COMMONIR:[[EXTRACT:%.*]] = extractelement <2 x double> [[TMP5]], 
i32 0
 // UNCONSTRAINED:   [[TMP6:%.*]] = call double @llvm.fma.f64(double [[TMP4]], 
double [[EXTRACT]], double [[TMP3]])
 // CONSTRAINED: [[TMP6:%.*]] = call double 
@llvm.experimental.constrained.fma.f64(double [[TMP4]], double [[EXTRACT]], 
double [[TMP3]], metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM:   fmla d{{[0-9]+}}, d{{[0-9]+}}, v{{[0-9]+}}.d[{{[0-9]+}}]
+// CHECK-ASM:   fmadd d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}
 // COMMONIR:[[TMP7:%.*]] = bitcast double [[TMP6]] to <1 x double>
 // COMMONIR:ret <1 x double> [[TMP7]]
 float64x1_t test_vfma_laneq_f64(float64x1_t a, float64x1_t b, float64x2_t v) {
@@ -122,7 +122,7 @@ float64x1_t test_vfma_laneq_f64(float64x1_t a, float64x1_t 
b, float64x2_t v) {
 // COMMONIR:[[EXTRACT:%.*]] = extractelement <2 x double> [[TMP5]], 
i32 0
 // UNCONSTRAINED:   [[TMP6:%.*]] = call double @llvm.fma.f64(double [[TMP4]], 
double [[EXTRACT]], double [[TMP3]])
 // CONSTRAINED: [[TMP6:%.*]] = call double 
@llvm.experimental.constrained.fma.f64(double [[TMP4]], double [[EXTRACT]], 
double [[TMP3]], metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM:   fmla d{{[0-9]+}}, d{{[0-9]+}}, v{{[0-9]+}}.d[{{[0-9]+}}]
+// CHECK-ASM:   fmadd d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}
 // COMMONIR:[[TMP7:%.*]] = bitcast double [[TMP6]] to <1 x double>
 // COMMONIR:ret <1 x double> [[TMP7]]
 float64x1_t test_vfms_laneq_f64(float64x1_t a, float64x1_t b, float64x2_t v) {

diff  --git a/llvm/lib/Target/AArch64/AArch64InstrFormats.td 
b/llvm/lib/Target/AArch64/AArch64InstrFormats.td
index 885b70a50121f3..57d69ae05c47ff 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrFormats.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrFormats.td
@@ -5409,6 +5409,44 @@ multiclass ThreeOperandFPData {
 let Inst{23-22} = 0b01; // 64-bit size flag
   }
+
+  let Predicates = [HasFullFP16] in {
+  def : Pat<(f16 (node (f16 FPR16:$Rn),
+   (f16 (extractelt (v8f16 V128:$Rm), (i64 0))),
+   (f16 FPR16:$Ra))),
+(!cast(NAME # Hrrr)
+  FPR16:$Rn, (f16 (EXTRACT_SUBREG V128:$Rm, hsub)), FPR16:$Ra)>;
+
+  def : Pat<(f16 (node (f16 (extractelt (v8f16 V128:$Rn), (i64 0))),
+   (f16 FPR16:$Rm),
+   (f16 FPR16:$Ra))),
+(!cast(NAME # Hrrr)
+  (f16 (EXTRACT_SUBREG V128:$Rn, hsub)), FPR16:$Rm, FPR16:$Ra)>;
+  }
+
+  def : Pat<(f32 (node (f32 FPR32:$Rn),
+   (f32 (extractelt (v4f32 V128:$Rm), (i64 0))),
+   (f32 FPR32:$Ra))),
+(!cast(NAME # Srrr)
+  FPR32:$Rn, (EXTRACT_SUBREG V128:$Rm, ssub), FPR32:$Ra)>;
+
+  def : Pat<(f32 (node (f32 (extractelt (v4f32 V128:$Rn), (i64 0))),
+   (f32 FPR32:$Rm),
+   (f32 FPR32:$Ra))),
+(!cast(NAME # Srrr)
+  (EXTRACT_SUBREG V128:$Rn, ssub), FPR32:$Rm, FPR32:$Ra)>;
+
+  def : Pat<(f64 (nod

[clang] [GlobalISel][AArch64] Combine unmerge(G_EXT v, undef) to unmerge(v). (PR #65263)

2023-09-04 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/65263:

>From 6f762b1eb8ad944be81fb237da10110e282d45fe Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Mon, 4 Sep 2023 12:35:48 +0200
Subject: [PATCH] [GlobalISel][AArch64] Combine unmerge(G_EXT v, undef) to
 unmerge(v).

When having  d1, unused = unmerge(G_EXT <2*N x t> v1, undef, N),
it is possible to express it just as unused, d1 = unmerge v1.

It is useful for tackling regressions in arm64-vcvt_f.ll, introduced in
https://reviews.llvm.org/D144670.
---
 llvm/lib/Target/AArch64/AArch64Combine.td | 11 ++-
 .../GISel/AArch64PostLegalizerLowering.cpp| 47 
 .../AArch64/arm64-neon-add-pairwise.ll|  6 +-
 llvm/test/CodeGen/AArch64/arm64-vabs.ll   | 76 +++
 llvm/test/CodeGen/AArch64/arm64-vcvt_f.ll | 17 ++---
 5 files changed, 93 insertions(+), 64 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64Combine.td 
b/llvm/lib/Target/AArch64/AArch64Combine.td
index 58493b98316531..0ff039126ba119 100644
--- a/llvm/lib/Target/AArch64/AArch64Combine.td
+++ b/llvm/lib/Target/AArch64/AArch64Combine.td
@@ -204,6 +204,14 @@ def vector_sext_inreg_to_shift : GICombineRule<
   (apply [{ applyVectorSextInReg(*${d}, MRI, B, Observer); }])
 >;
 
+def unmerge_ext_to_unmerge_matchdata : GIDefMatchData<"Register">;
+def unmerge_ext_to_unmerge : GICombineRule<
+  (defs root:$d, icmp_redundant_trunc_matchdata:$matchinfo),
+  (match (wip_match_opcode G_UNMERGE_VALUES):$d,
+  [{ return matchUnmergeExtToUnmerge(*${d}, MRI, ${matchinfo}); }]),
+  (apply [{ applyUnmergeExtToUnmerge(*${d}, MRI, B, Observer, ${matchinfo}); 
}])
+>;
+
 // Post-legalization combines which should happen at all optimization levels.
 // (E.g. ones that facilitate matching for the selector) For example, matching
 // pseudos.
@@ -212,7 +220,8 @@ def AArch64PostLegalizerLowering
[shuffle_vector_lowering, vashr_vlshr_imm,
 icmp_lowering, build_vector_lowering,
 lower_vector_fcmp, form_truncstore,
-vector_sext_inreg_to_shift]> {
+vector_sext_inreg_to_shift,
+unmerge_ext_to_unmerge]> {
 }
 
 // Post-legalization combines which are primarily optimizations.
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp 
b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
index d8ee35ebf1e21a..41c271a7af70ad 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
@@ -1067,6 +1067,53 @@ void applyVectorSextInReg(MachineInstr &MI, 
MachineRegisterInfo &MRI,
   Helper.lower(MI, 0, /* Unused hint type */ LLT());
 }
 
+/// Combine , unused = unmerge(G_EXT <2*N x t> v, undef, N)
+///   => unused,  = unmerge v
+bool matchUnmergeExtToUnmerge(MachineInstr &MI, MachineRegisterInfo &MRI,
+  Register &MatchInfo) {
+  assert(MI.getOpcode() == TargetOpcode::G_UNMERGE_VALUES);
+  if (MI.getNumDefs() != 2)
+return false;
+  if (!MRI.use_nodbg_empty(MI.getOperand(1).getReg()))
+return false;
+
+  LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
+  if (!DstTy.isVector())
+return false;
+
+  MachineInstr *Ext = getDefIgnoringCopies(
+  MI.getOperand(MI.getNumExplicitDefs()).getReg(), MRI);
+  if (!Ext || Ext->getOpcode() != AArch64::G_EXT)
+return false;
+
+  Register ExtSrc1 = Ext->getOperand(1).getReg();
+  Register ExtSrc2 = Ext->getOperand(2).getReg();
+  auto LowestVal =
+  getIConstantVRegValWithLookThrough(Ext->getOperand(3).getReg(), MRI);
+  if (!LowestVal || LowestVal->Value.getZExtValue() != DstTy.getSizeInBytes())
+return false;
+
+  MachineInstr *Undef = getDefIgnoringCopies(ExtSrc2, MRI);
+  if (!Undef)
+return false;
+
+  MatchInfo = ExtSrc1;
+
+  return Undef->getOpcode() == TargetOpcode::G_IMPLICIT_DEF;
+}
+
+void applyUnmergeExtToUnmerge(MachineInstr &MI, MachineRegisterInfo &MRI,
+  MachineIRBuilder &B,
+  GISelChangeObserver &Observer, Register &SrcReg) 
{
+  Observer.changingInstr(MI);
+  // Swap dst registers.
+  Register Dst1 = MI.getOperand(0).getReg();
+  MI.getOperand(0).setReg(MI.getOperand(1).getReg());
+  MI.getOperand(1).setReg(Dst1);
+  MI.getOperand(2).setReg(SrcReg);
+  Observer.changedInstr(MI);
+}
+
 class AArch64PostLegalizerLoweringImpl : public GIMatchTableExecutor {
 protected:
   CombinerHelper &Helper;
diff --git a/llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll 
b/llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
index aa048eea302c97..17fb312c63754d 100644
--- a/llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
@@ -137,7 +137,7 @@ define i32 @addp_v4i32(<4 x i32> %a, <4 x i32> %b) {
 ; CHECK-GI-LABEL: addp_v4i32:
 ; CHECK-GI:   // %bb.0:
 ; C

[clang] [GlobalISel][AArch64] Combine unmerge(G_EXT v, undef) to unmerge(v). (PR #65263)

2023-09-05 Thread Vladislav Dzhidzhoev via cfe-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/65263:

>From a88ee53623a3ff4774bc7a5df13379e55a0f9945 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Mon, 4 Sep 2023 12:35:48 +0200
Subject: [PATCH 1/2] [GlobalISel][AArch64] Combine unmerge(G_EXT v, undef) to
 unmerge(v).

When having  d1, unused = unmerge(G_EXT <2*N x t> v1, undef, N),
it is possible to express it just as unused, d1 = unmerge v1.

It is useful for tackling regressions in arm64-vcvt_f.ll, introduced in
https://reviews.llvm.org/D144670.
---
 llvm/lib/Target/AArch64/AArch64Combine.td | 11 ++-
 .../GISel/AArch64PostLegalizerLowering.cpp| 47 
 .../AArch64/arm64-neon-add-pairwise.ll|  6 +-
 llvm/test/CodeGen/AArch64/arm64-vabs.ll   | 76 +++
 llvm/test/CodeGen/AArch64/arm64-vcvt_f.ll | 17 ++---
 5 files changed, 93 insertions(+), 64 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64Combine.td 
b/llvm/lib/Target/AArch64/AArch64Combine.td
index 6bcb014d22035e..699310d0627dba 100644
--- a/llvm/lib/Target/AArch64/AArch64Combine.td
+++ b/llvm/lib/Target/AArch64/AArch64Combine.td
@@ -206,6 +206,14 @@ def vector_sext_inreg_to_shift : GICombineRule<
   (apply [{ applyVectorSextInReg(*${d}, MRI, B, Observer); }])
 >;
 
+def unmerge_ext_to_unmerge_matchdata : GIDefMatchData<"Register">;
+def unmerge_ext_to_unmerge : GICombineRule<
+  (defs root:$d, unmerge_ext_to_unmerge_matchdata:$matchinfo),
+  (match (wip_match_opcode G_UNMERGE_VALUES):$d,
+  [{ return matchUnmergeExtToUnmerge(*${d}, MRI, ${matchinfo}); }]),
+  (apply [{ applyUnmergeExtToUnmerge(*${d}, MRI, B, Observer, ${matchinfo}); 
}])
+>;
+
 // Post-legalization combines which should happen at all optimization levels.
 // (E.g. ones that facilitate matching for the selector) For example, matching
 // pseudos.
@@ -214,7 +222,8 @@ def AArch64PostLegalizerLowering
[shuffle_vector_lowering, vashr_vlshr_imm,
 icmp_lowering, build_vector_lowering,
 lower_vector_fcmp, form_truncstore,
-vector_sext_inreg_to_shift]> {
+vector_sext_inreg_to_shift,
+unmerge_ext_to_unmerge]> {
 }
 
 // Post-legalization combines which are primarily optimizations.
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp 
b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
index 57117ea143d7e9..e9386d77b2559f 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
@@ -1066,6 +1066,53 @@ void applyVectorSextInReg(MachineInstr &MI, 
MachineRegisterInfo &MRI,
   Helper.lower(MI, 0, /* Unused hint type */ LLT());
 }
 
+/// Combine , unused = unmerge(G_EXT <2*N x t> v, undef, N)
+///   => unused,  = unmerge v
+bool matchUnmergeExtToUnmerge(MachineInstr &MI, MachineRegisterInfo &MRI,
+  Register &MatchInfo) {
+  assert(MI.getOpcode() == TargetOpcode::G_UNMERGE_VALUES);
+  if (MI.getNumDefs() != 2)
+return false;
+  if (!MRI.use_nodbg_empty(MI.getOperand(1).getReg()))
+return false;
+
+  LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
+  if (!DstTy.isVector())
+return false;
+
+  MachineInstr *Ext = getDefIgnoringCopies(
+  MI.getOperand(MI.getNumExplicitDefs()).getReg(), MRI);
+  if (!Ext || Ext->getOpcode() != AArch64::G_EXT)
+return false;
+
+  Register ExtSrc1 = Ext->getOperand(1).getReg();
+  Register ExtSrc2 = Ext->getOperand(2).getReg();
+  auto LowestVal =
+  getIConstantVRegValWithLookThrough(Ext->getOperand(3).getReg(), MRI);
+  if (!LowestVal || LowestVal->Value.getZExtValue() != DstTy.getSizeInBytes())
+return false;
+
+  MachineInstr *Undef = getDefIgnoringCopies(ExtSrc2, MRI);
+  if (!Undef)
+return false;
+
+  MatchInfo = ExtSrc1;
+
+  return Undef->getOpcode() == TargetOpcode::G_IMPLICIT_DEF;
+}
+
+void applyUnmergeExtToUnmerge(MachineInstr &MI, MachineRegisterInfo &MRI,
+  MachineIRBuilder &B,
+  GISelChangeObserver &Observer, Register &SrcReg) 
{
+  Observer.changingInstr(MI);
+  // Swap dst registers.
+  Register Dst1 = MI.getOperand(0).getReg();
+  MI.getOperand(0).setReg(MI.getOperand(1).getReg());
+  MI.getOperand(1).setReg(Dst1);
+  MI.getOperand(2).setReg(SrcReg);
+  Observer.changedInstr(MI);
+}
+
 class AArch64PostLegalizerLoweringImpl : public Combiner {
 protected:
   // TODO: Make CombinerHelper methods const.
diff --git a/llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll 
b/llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
index aa048eea302c97..17fb312c63754d 100644
--- a/llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
@@ -137,7 +137,7 @@ define i32 @addp_v4i32(<4 x i32> %a, <4 x i32> %b) {
 ; CHECK-GI-LABEL: addp_v4i32:
 ; CHECK-GI:   

[clang] 66511b4 - [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)

2023-06-19 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-19T16:42:43+02:00
New Revision: 66511b401042f28c74d2ded3aac76d19a53bd7c4

URL: 
https://github.com/llvm/llvm-project/commit/66511b401042f28c74d2ded3aac76d19a53bd7c4
DIFF: 
https://github.com/llvm/llvm-project/commit/66511b401042f28c74d2ded3aac76d19a53bd7c4.diff

LOG: [DebugMetadata][DwarfDebug] Support function-local types in lexical block 
scopes (4/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Similar to imported declarations, the patch tracks function-local types in
DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with
the aforementioned metadata change and provided a support of function-local
types scoped within a lexical block.

The patch assumes that DICompileUnit's 'enums field' no longer tracks local
types and DwarfDebug would assert if any locally-scoped types get placed there.

Authored-by: Kristina Bessonova 

Differential Revision: https://reviews.llvm.org/D144006

Depends on D144005

Added: 
llvm/test/DebugInfo/Generic/inlined-local-type.ll
llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
llvm/test/DebugInfo/Generic/lexical-block-types.ll
llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll

Modified: 
clang/test/CodeGen/debug-info-codeview-unnamed.c
clang/test/CodeGen/debug-info-unused-types.c
clang/test/CodeGen/debug-info-unused-types.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/set.ll

Removed: 




diff  --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2..16ffb3682236f 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE]]
+  // LINUX-SAME: )
   //
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
-  // MSVC-SAME:  )
-  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
+  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
+  // MSVC-SAME:  )
 
   return 0;
 }

diff  --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 3e9f7b07658e3..5bcc71f710a5c 100644
--- a/clang/test/CodeGen/debug-info-unused-types.c
+++ b/clang/test/CodeGen/debug-info-unused-types.c
@@ -18,13 +18,13 @@ void quux(void) {
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "z"
-// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
-// CHECK: [[RETTYPES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]], [[TYPE0]], 
[[TYPE6:![0-9]+]], {{![0-9]+}}, [[TYPE7:![0-9]+]], [[TYPE2]], [[TYPE8:![0-9]+]]}
-// CHECK: [[TYPE4]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
-// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
-// CHECK: [[TYPE6]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
-// CHECK: [[TYPE7]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "y"
+// CH

[clang] aeb99dc - Revert "[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)"

2023-06-19 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-19T19:16:13+02:00
New Revision: aeb99dc48a58f872465e818d0eda7d9c3f221e06

URL: 
https://github.com/llvm/llvm-project/commit/aeb99dc48a58f872465e818d0eda7d9c3f221e06
DIFF: 
https://github.com/llvm/llvm-project/commit/aeb99dc48a58f872465e818d0eda7d9c3f221e06.diff

LOG: Revert "[DebugMetadata][DwarfDebug] Support function-local types in 
lexical block scopes (4/7)"

This reverts commit 66511b401042f28c74d2ded3aac76d19a53bd7c4.
llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll is
broken.

Added: 


Modified: 
clang/test/CodeGen/debug-info-codeview-unnamed.c
clang/test/CodeGen/debug-info-unused-types.c
clang/test/CodeGen/debug-info-unused-types.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/set.ll

Removed: 
llvm/test/DebugInfo/Generic/inlined-local-type.ll
llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
llvm/test/DebugInfo/Generic/lexical-block-types.ll
llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll



diff  --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index 16ffb3682236f..bd2a7543e56b2 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
+  // LINUX-SAME: )
+  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE]]
-  // LINUX-SAME: )
   //
-  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
+  // MSVC-SAME:  )
+  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
-  // MSVC-SAME:  )
 
   return 0;
 }

diff  --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 5bcc71f710a5c..3e9f7b07658e3 100644
--- a/clang/test/CodeGen/debug-info-unused-types.c
+++ b/clang/test/CodeGen/debug-info-unused-types.c
@@ -18,13 +18,13 @@ void quux(void) {
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], 
[[TYPE4:![0-9]+]], {{![0-9]+}}, [[TYPE5:![0-9]+]], [[TYPE6:![0-9]+]], 
[[TYPE8:![0-9]+]]}
-// CHECK: [[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
-// CHECK: [[TYPE3]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
-// CHECK: [[TYPE4]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
-// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "y"
-// CHECK: [[TYPE6]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "z"
-// CHECK: [[TYPE7:![0-9]+]] = !DIEnumerator(name: "Z"
+// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "z"
+// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
+// CHECK: [[RETTYPES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]], [[TYPE0]], 
[[TYPE6:![0-9]+]], {{![0-9]+}}, [[TYPE7:![0-9]+]], [[TYPE2]], [[TYPE8:![0-9]+]]}
+// CHECK: [[TYPE4]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
+// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
+// CHECK: [[TYPE6]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
+// 

[clang] 2da4517 - Reland "[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)"

2023-06-19 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-19T19:50:46+02:00
New Revision: 2da45172c4bcd42f704c57c656926f56f32fc5ce

URL: 
https://github.com/llvm/llvm-project/commit/2da45172c4bcd42f704c57c656926f56f32fc5ce
DIFF: 
https://github.com/llvm/llvm-project/commit/2da45172c4bcd42f704c57c656926f56f32fc5ce.diff

LOG: Reland "[DebugMetadata][DwarfDebug] Support function-local types in 
lexical block scopes (4/7)"

Test "local-type-as-template-parameter.ll" now requires linux-system.

Authored-by: Kristina Bessonova 

Differential Revision: https://reviews.llvm.org/D144006

Depends on D144005

Added: 
llvm/test/DebugInfo/Generic/inlined-local-type.ll
llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
llvm/test/DebugInfo/Generic/lexical-block-types.ll
llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import2.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGen/debug-info-codeview-unnamed.c
clang/test/CodeGen/debug-info-unused-types.c
clang/test/CodeGen/debug-info-unused-types.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/set.ll

Removed: 
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2..16ffb3682236f 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE]]
+  // LINUX-SAME: )
   //
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
-  // MSVC-SAME:  )
-  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
+  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
+  // MSVC-SAME:  )
 
   return 0;
 }

diff  --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 3e9f7b07658e3..5bcc71f710a5c 100644
--- a/clang/test/CodeGen/debug-info-unused-types.c
+++ b/clang/test/CodeGen/debug-info-unused-types.c
@@ -18,13 +18,13 @@ void quux(void) {
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "z"
-// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
-// CHECK: [[RETTYPES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]], [[TYPE0]], 
[[TYPE6:![0-9]+]], {{![0-9]+}}, [[TYPE7:![0-9]+]], [[TYPE2]], [[TYPE8:![0-9]+]]}
-// CHECK: [[TYPE4]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
-// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
-// CHECK: [[TYPE6]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
-// CHECK: [[TYPE7]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "y"
+// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], 
[[TYPE4:![0-9]+]], {{![0-9]+}}, [[TYPE5:![0-9]+]], [[TYPE6:![0-9]+]], 
[[TYPE8:![0-9]+]]

[clang] fec7c64 - Revert "Reland "[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)""

2023-06-19 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-20T01:54:48+02:00
New Revision: fec7c6457ced7e87d4e0837402b0b8a644cf6242

URL: 
https://github.com/llvm/llvm-project/commit/fec7c6457ced7e87d4e0837402b0b8a644cf6242
DIFF: 
https://github.com/llvm/llvm-project/commit/fec7c6457ced7e87d4e0837402b0b8a644cf6242.diff

LOG: Revert "Reland "[DebugMetadata][DwarfDebug] Support function-local types 
in lexical block scopes (4/7)""

This reverts commit 2da45172c4bcd42f704c57c656926f56f32fc5ce.
Test local-type-as-template-parameter.ll fails on ppc64-aix.

Added: 
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGen/debug-info-codeview-unnamed.c
clang/test/CodeGen/debug-info-unused-types.c
clang/test/CodeGen/debug-info-unused-types.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/set.ll

Removed: 
llvm/test/DebugInfo/Generic/inlined-local-type.ll
llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
llvm/test/DebugInfo/Generic/lexical-block-types.ll
llvm/test/DebugInfo/Generic/local-type-as-template-parameter.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import2.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index 16ffb3682236f..bd2a7543e56b2 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
+  // LINUX-SAME: )
+  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE]]
-  // LINUX-SAME: )
   //
-  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
+  // MSVC-SAME:  )
+  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
-  // MSVC-SAME:  )
 
   return 0;
 }

diff  --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 5bcc71f710a5c..3e9f7b07658e3 100644
--- a/clang/test/CodeGen/debug-info-unused-types.c
+++ b/clang/test/CodeGen/debug-info-unused-types.c
@@ -18,13 +18,13 @@ void quux(void) {
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], 
[[TYPE4:![0-9]+]], {{![0-9]+}}, [[TYPE5:![0-9]+]], [[TYPE6:![0-9]+]], 
[[TYPE8:![0-9]+]]}
-// CHECK: [[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
-// CHECK: [[TYPE3]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
-// CHECK: [[TYPE4]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
-// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "y"
-// CHECK: [[TYPE6]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "z"
-// CHECK: [[TYPE7:![0-9]+]] = !DIEnumerator(name: "Z"
+// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "z"
+// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
+// CHECK: [[RETTYPES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]], [[TYP

[clang] cb9ac70 - Reland "[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)" (2)

2023-06-19 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-20T03:01:46+02:00
New Revision: cb9ac7051589ea0d05507f9370d0716bef86b4ae

URL: 
https://github.com/llvm/llvm-project/commit/cb9ac7051589ea0d05507f9370d0716bef86b4ae
DIFF: 
https://github.com/llvm/llvm-project/commit/cb9ac7051589ea0d05507f9370d0716bef86b4ae.diff

LOG: Reland "[DebugMetadata][DwarfDebug] Support function-local types in 
lexical block scopes (4/7)" (2)

Test "local-type-as-template-parameter.ll" is now enabled only for
x86_64.

Authored-by: Kristina Bessonova 

Differential Revision: https://reviews.llvm.org/D144006

Depends on D144005

Added: 
llvm/test/DebugInfo/Generic/inlined-local-type.ll
llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
llvm/test/DebugInfo/Generic/lexical-block-types.ll
llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import2.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGen/debug-info-codeview-unnamed.c
clang/test/CodeGen/debug-info-unused-types.c
clang/test/CodeGen/debug-info-unused-types.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/set.ll

Removed: 
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index bd2a7543e56b2..16ffb3682236f 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
-  // LINUX-SAME: )
-  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
+  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE]]
+  // LINUX-SAME: )
   //
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
-  // MSVC-SAME:  )
-  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
+  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
+  // MSVC-SAME:  )
 
   return 0;
 }

diff  --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 3e9f7b07658e3..5bcc71f710a5c 100644
--- a/clang/test/CodeGen/debug-info-unused-types.c
+++ b/clang/test/CodeGen/debug-info-unused-types.c
@@ -18,13 +18,13 @@ void quux(void) {
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "z"
-// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
-// CHECK: [[RETTYPES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]], [[TYPE0]], 
[[TYPE6:![0-9]+]], {{![0-9]+}}, [[TYPE7:![0-9]+]], [[TYPE2]], [[TYPE8:![0-9]+]]}
-// CHECK: [[TYPE4]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
-// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
-// CHECK: [[TYPE6]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
-// CHECK: [[TYPE7]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "y"
+// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], 
[[TYPE4:![0-9]+]], {{![0-9]+}}, [[TYPE5:![0-9]+]], [[TYPE6:![0-9]+]], 
[[TYPE8:![0-

[clang] 6bea833 - Revert "Reland "[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)" (2)"

2023-06-20 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-20T13:08:47+02:00
New Revision: 6bea8331f9e09ba94a225c65becd4224a1a473af

URL: 
https://github.com/llvm/llvm-project/commit/6bea8331f9e09ba94a225c65becd4224a1a473af
DIFF: 
https://github.com/llvm/llvm-project/commit/6bea8331f9e09ba94a225c65becd4224a1a473af.diff

LOG: Revert "Reland "[DebugMetadata][DwarfDebug] Support function-local types 
in lexical block scopes (4/7)" (2)"

This reverts commit cb9ac7051589ea0d05507f9370d0716bef86b4ae.
It causes an assert in clang:
virtual void llvm::DwarfDebug::endFunctionImpl(const llvm::MachineFunction*): 
Assertion `LScopes.getAbstractScopesList().size() == NumAbstractSubprograms && 
"getOrCreateAbstractScope() inserted an abstract subprogram scope"' failed.
https://bugs.chromium.org/p/chromium/issues/detail?id=1456288#c2

Added: 
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGen/debug-info-codeview-unnamed.c
clang/test/CodeGen/debug-info-unused-types.c
clang/test/CodeGen/debug-info-unused-types.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/set.ll

Removed: 
llvm/test/DebugInfo/Generic/inlined-local-type.ll
llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll
llvm/test/DebugInfo/Generic/lexical-block-types.ll
llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import2.ll
llvm/test/DebugInfo/X86/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c 
b/clang/test/CodeGen/debug-info-codeview-unnamed.c
index 16ffb3682236f..bd2a7543e56b2 100644
--- a/clang/test/CodeGen/debug-info-codeview-unnamed.c
+++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
   //
   struct { int bar; } one = {42};
   //
-  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
+  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
+  // LINUX-SAME: )
+  // LINUX:  [[TYPE_OF_ONE]] = distinct !DICompositeType(
   // LINUX-SAME: tag: DW_TAG_structure_type
   // LINUX-NOT:  name:
   // LINUX-NOT:  identifier:
   // LINUX-SAME: )
-  // LINUX:  !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // LINUX-SAME: type: [[TYPE_OF_ONE]]
-  // LINUX-SAME: )
   //
-  // MSVC:   [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
+  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
+  // MSVC-SAME:  type: [[TYPE_OF_ONE:![0-9]+]]
+  // MSVC-SAME:  )
+  // MSVC:   [[TYPE_OF_ONE]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_structure_type
   // MSVC-NOT:   name:
   // MSVC-NOT:   identifier:
   // MSVC-SAME:  )
-  // MSVC:   !{{[0-9]+}} = !DILocalVariable(name: "one"
-  // MSVC-SAME:  type: [[TYPE_OF_ONE]]
-  // MSVC-SAME:  )
 
   return 0;
 }

diff  --git a/clang/test/CodeGen/debug-info-unused-types.c 
b/clang/test/CodeGen/debug-info-unused-types.c
index 5bcc71f710a5c..3e9f7b07658e3 100644
--- a/clang/test/CodeGen/debug-info-unused-types.c
+++ b/clang/test/CodeGen/debug-info-unused-types.c
@@ -18,13 +18,13 @@ void quux(void) {
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], 
[[TYPE4:![0-9]+]], {{![0-9]+}}, [[TYPE5:![0-9]+]], [[TYPE6:![0-9]+]], 
[[TYPE8:![0-9]+]]}
-// CHECK: [[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
-// CHECK: [[TYPE3]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
-// CHECK: [[TYPE4]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
-// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "y"
-// CHECK: [[TYPE6]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "z"
-

[clang] af6c0b6 - [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2023-02-17 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-02-17T15:11:42+01:00
New Revision: af6c0b6d8c9dc52485d56e82f79a03de09aa188f

URL: 
https://github.com/llvm/llvm-project/commit/af6c0b6d8c9dc52485d56e82f79a03de09aa188f
DIFF: 
https://github.com/llvm/llvm-project/commit/af6c0b6d8c9dc52485d56e82f79a03de09aa188f.diff

LOG: [clang][CodeGen] Use base subobject type layout for 
potentially-overlapping fields

RecordLayoutBuilder assumes the size of a potentially-overlapping
class/struct field with non-zero size as the size of the base subobject
type corresponding to the field type.
Make CGRecordLayoutBuilder to acknowledge that in order to avoid incorrect
padding insertion.

Differential Revision: https://reviews.llvm.org/D139741

Added: 
clang/test/CodeGenCXX/no-unique-address-3.cpp

Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index b32d021b1c695..e213c5fe29c68 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3072,6 +3072,10 @@ class FieldDecl : public DeclaratorDecl, public 
Mergeable {
   /// [[no_unique_address]] attribute.
   bool isZeroSize(const ASTContext &Ctx) const;
 
+  /// Determine if this field is of potentially-overlapping class type, that
+  /// is, subobject with the [[no_unique_address]] attribute
+  bool isPotentiallyOverlapping() const;
+
   /// Get the kind of (C++11) default member initializer that this field has.
   InClassInitStyle getInClassInitStyle() const {
 InitStorageKind storageKind = InitStorage.getInt();

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index cd09e2fe2b05b..9c72d7a7d928c 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4347,6 +4347,10 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
   return true;
 }
 
+bool FieldDecl::isPotentiallyOverlapping() const {
+  return hasAttr() && getType()->getAsCXXRecordDecl();
+}
+
 unsigned FieldDecl::getFieldIndex() const {
   const FieldDecl *Canonical = getCanonicalDecl();
   if (Canonical != this)

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 2f546398338c4..641e9d62149e9 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1853,9 +1853,8 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const 
FieldDecl *D) {
 void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
  bool InsertExtraPadding) {
   auto *FieldClass = D->getType()->getAsCXXRecordDecl();
-  bool PotentiallyOverlapping = D->hasAttr() && 
FieldClass;
   bool IsOverlappingEmptyField =
-  PotentiallyOverlapping && FieldClass->isEmpty();
+  D->isPotentiallyOverlapping() && FieldClass->isEmpty();
 
   CharUnits FieldOffset =
   (IsUnion || IsOverlappingEmptyField) ? CharUnits::Zero() : getDataSize();
@@ -1916,7 +1915,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
 
 // A potentially-overlapping field occupies its dsize or nvsize, whichever
 // is larger.
-if (PotentiallyOverlapping) {
+if (D->isPotentiallyOverlapping()) {
   const ASTRecordLayout &Layout = Context.getASTRecordLayout(FieldClass);
   EffectiveFieldSize =
   std::max(Layout.getNonVirtualSize(), Layout.getDataSize());

diff  --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp 
b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 596f0bd332049..888b7ddcccd32 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -182,7 +182,7 @@ struct CGRecordLowering {
llvm::Type *StorageType);
   /// Lowers an ASTRecordLayout to a llvm type.
   void lower(bool NonVirtualBaseType);
-  void lowerUnion();
+  void lowerUnion(bool isNoUniqueAddress);
   void accumulateFields();
   void accumulateBitFields(RecordDecl::field_iterator Field,
RecordDecl::field_iterator FieldEnd);
@@ -280,7 +280,7 @@ void CGRecordLowering::lower(bool NVBaseType) {
   //CodeGenTypes::ComputeRecordLayout.
   CharUnits Size = NVBaseType ? Layout.getNonVirtualSize() : Layout.getSize();
   if (D->isUnion()) {
-lowerUnion();
+lowerUnion(NVBaseType);
 computeVolatileBitfields();
 return;
   }
@@ -308,8 +308,9 @@ void CGRecordLowering::lower(bool NVBaseType) {
   computeVolatileBitfields();
 }
 
-void CGRecordLowering::lowerUnion() {
-  CharUnits LayoutSize = Layout.getSize();
+void CGRecordLowering::lowerUnion(bool isNoUniqueAddress) {
+  CharUnits LayoutSize =
+  isNoUniqueAddress ? Layout.getDataSize() : Layout.getSize();
   llvm::Type *StorageType = nullptr;
   bool SeenNamedMember = false;
   // Iterate through the fields setting bitFiel

[clang] 4418434 - [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)

2023-06-07 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Kristina Bessonova
Date: 2023-06-07T16:43:12+02:00
New Revision: 4418434c6de7a861e241ba2448ea4a12080cf08f

URL: 
https://github.com/llvm/llvm-project/commit/4418434c6de7a861e241ba2448ea4a12080cf08f
DIFF: 
https://github.com/llvm/llvm-project/commit/4418434c6de7a861e241ba2448ea4a12080cf08f.diff

LOG: [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI 
(1/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Currently, `retainedNodes` tracks function-local variables and labels.
To support function-local import, types and static variables (which are globals
in LLVM IR), subsequent patches use the same field. So this patch makes
preliminary refactoring of the code tracking local entities to apply future
functional changes lucidly and cleanly.

No functional changes intended.

Differential Revision: https://reviews.llvm.org/D143984

Added: 


Modified: 
clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
clang/test/CodeGenCXX/debug-info-cxx1y.cpp
clang/test/CodeGenCXX/debug-info-template.cpp
clang/test/CodeGenObjC/debug-info-category.m
llvm/include/llvm/IR/DIBuilder.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/IR/DIBuilder.cpp

Removed: 




diff  --git a/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c 
b/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
index e3bfd71a56aad..5bbb05e6b8098 100644
--- a/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
+++ b/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
@@ -13,7 +13,7 @@ int foo2(struct t1 *arg) {
   return foo(arg);
 }
 
-// CHECK: ![[#]] = !DISubprogram(name: "foo", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, 
retainedNodes: ![[#]], annotations: ![[ANNOT:[0-9]+]])
+// CHECK: ![[#]] = !DISubprogram(name: "foo", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, 
annotations: ![[ANNOT:[0-9]+]])
 // CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
 // CHECK: ![[TAG1]] = !{!"btf_decl_tag", !"tag1"}
 // CHECK: ![[TAG2]] = !{!"btf_decl_tag", !"tag2"}

diff  --git a/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp 
b/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
index a35ca27e10d2a..6453e4379ae9a 100644
--- a/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
+++ b/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
@@ -52,15 +52,15 @@ X v;
 // CHECK:   ret void
 // CHECK: }
 
-// CHECK: ![[DBGVAR16]] = distinct !DISubprogram(name: 
"__cxx_global_var_init", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: 
!{{[0-9]+}}, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | 
DISPFlagDefinition, unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CHECK: ![[DBGVAR16]] = distinct !DISubprogram(name: 
"__cxx_global_var_init", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: 
!{{[0-9]+}}, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | 
DISPFlagDefinition, unit: !{{[0-9]+}})
 // CHECK: ![[DBGVAR19]] = !DILocation(line: 14, column: 3, scope: 
![[DBGVAR16]])
 // CHECK: ![[DBGVAR19b]] = !DILocation(line: 0, scope: ![[DBGVAR16]])
-// CHECK: ![[DBGVAR20]] = distinct !DISubprogram(name: "__dtor_v", scope: 
!{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 14, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CHECK: ![[DBGVAR20]] = distinct !DISubprogram(name: "__dtor_v", scope: 
!{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 14, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}})
 // CHECK: ![[DBGVAR21b]] = !DILocation(line: 0, scope: ![[DBGVAR20]])
 // CHECK: ![[DBGVAR21]] = !DILocation(line: 14, column: 3, scope: 
![[DBGVAR20]])
-// CHECK: ![[DBGVAR22]] = distinct !DISubprogram(linkageName: "__finalize_v", 
scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 
14, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CHECK: ![[DBGVAR22]] = distinct !DISubprogram(linkageName: "__finalize_v", 
scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 
14, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}})
 // CHECK: ![[DBGVAR24]] = !DILocation(line: 14, column: 3, scope: 
![[DBGVAR22]])
-// CHECK: ![[DBGVAR25]] = distinct !DISubprogram(linkageName: 
"_GLOBAL__sub_I__", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: !{{[0-9]+}}, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CH

[clang] 7815166 - Revert "[DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)"

2023-06-08 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-08T17:36:30+02:00
New Revision: 7815166b476b4184a1171ef56eed35726c1ab132

URL: 
https://github.com/llvm/llvm-project/commit/7815166b476b4184a1171ef56eed35726c1ab132
DIFF: 
https://github.com/llvm/llvm-project/commit/7815166b476b4184a1171ef56eed35726c1ab132.diff

LOG: Revert "[DebugMetadata] Simplify handling subprogram's retainedNodes 
field. NFCI (1/7)"

This reverts commit 4418434c6de7a861e241ba2448ea4a12080cf08f.

Reverted because it breaks tests of OCaml bindings.

Added: 


Modified: 
clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
clang/test/CodeGenCXX/debug-info-cxx1y.cpp
clang/test/CodeGenCXX/debug-info-template.cpp
clang/test/CodeGenObjC/debug-info-category.m
llvm/include/llvm/IR/DIBuilder.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/IR/DIBuilder.cpp

Removed: 




diff  --git a/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c 
b/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
index 5bbb05e6b8098..e3bfd71a56aad 100644
--- a/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
+++ b/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
@@ -13,7 +13,7 @@ int foo2(struct t1 *arg) {
   return foo(arg);
 }
 
-// CHECK: ![[#]] = !DISubprogram(name: "foo", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, 
annotations: ![[ANNOT:[0-9]+]])
+// CHECK: ![[#]] = !DISubprogram(name: "foo", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, 
retainedNodes: ![[#]], annotations: ![[ANNOT:[0-9]+]])
 // CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
 // CHECK: ![[TAG1]] = !{!"btf_decl_tag", !"tag1"}
 // CHECK: ![[TAG2]] = !{!"btf_decl_tag", !"tag2"}

diff  --git a/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp 
b/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
index 6453e4379ae9a..a35ca27e10d2a 100644
--- a/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
+++ b/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
@@ -52,15 +52,15 @@ X v;
 // CHECK:   ret void
 // CHECK: }
 
-// CHECK: ![[DBGVAR16]] = distinct !DISubprogram(name: 
"__cxx_global_var_init", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: 
!{{[0-9]+}}, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | 
DISPFlagDefinition, unit: !{{[0-9]+}})
+// CHECK: ![[DBGVAR16]] = distinct !DISubprogram(name: 
"__cxx_global_var_init", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: 
!{{[0-9]+}}, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | 
DISPFlagDefinition, unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
 // CHECK: ![[DBGVAR19]] = !DILocation(line: 14, column: 3, scope: 
![[DBGVAR16]])
 // CHECK: ![[DBGVAR19b]] = !DILocation(line: 0, scope: ![[DBGVAR16]])
-// CHECK: ![[DBGVAR20]] = distinct !DISubprogram(name: "__dtor_v", scope: 
!{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 14, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}})
+// CHECK: ![[DBGVAR20]] = distinct !DISubprogram(name: "__dtor_v", scope: 
!{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 14, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
 // CHECK: ![[DBGVAR21b]] = !DILocation(line: 0, scope: ![[DBGVAR20]])
 // CHECK: ![[DBGVAR21]] = !DILocation(line: 14, column: 3, scope: 
![[DBGVAR20]])
-// CHECK: ![[DBGVAR22]] = distinct !DISubprogram(linkageName: "__finalize_v", 
scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 
14, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}})
+// CHECK: ![[DBGVAR22]] = distinct !DISubprogram(linkageName: "__finalize_v", 
scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 
14, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
 // CHECK: ![[DBGVAR24]] = !DILocation(line: 14, column: 3, scope: 
![[DBGVAR22]])
-// CHECK: ![[DBGVAR25]] = distinct !DISubprogram(linkageName: 
"_GLOBAL__sub_I__", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: !{{[0-9]+}}, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}})
+// CHECK: ![[DBGVAR25]] = distinct !DISubprogram(linkageName: 
"_GLOBAL__sub_I__", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: !{{[0-9]+}}, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
 // CHECK: ![[DBGVAR26]] = !DILocation(line: 0, scope: ![[DBGVAR25]])
-// CHECK: ![[DBGVAR27]] = distinct !DISubprogram(linkageName: "_GLOBAL__D_a", 
scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: !{{[0-9]+}}, flags: 
DIFlagArtificia

[clang] ed506dd - [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)

2023-06-12 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-12T18:38:47+02:00
New Revision: ed506dd6cecd9653cf9202bfe195891a33482852

URL: 
https://github.com/llvm/llvm-project/commit/ed506dd6cecd9653cf9202bfe195891a33482852
DIFF: 
https://github.com/llvm/llvm-project/commit/ed506dd6cecd9653cf9202bfe195891a33482852.diff

LOG: [DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI 
(1/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Currently, `retainedNodes` tracks function-local variables and labels.
To support function-local import, types and static variables (which are globals
in LLVM IR), subsequent patches use the same field. So this patch makes
preliminary refactoring of the code tracking local entities to apply future
functional changes lucidly and cleanly.

No functional changes intended.

Differential Revision: https://reviews.llvm.org/D143984

Authored-by: Kristina Bessonova 

Added: 


Modified: 
clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
clang/test/CodeGenCXX/debug-info-cxx1y.cpp
clang/test/CodeGenCXX/debug-info-template.cpp
clang/test/CodeGenObjC/debug-info-category.m
llvm/include/llvm/IR/DIBuilder.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/IR/DIBuilder.cpp
llvm/test/Bindings/OCaml/debuginfo.ml

Removed: 




diff  --git a/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c 
b/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
index e3bfd71a56aad..5bbb05e6b8098 100644
--- a/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
+++ b/clang/test/CodeGen/attr-btf_tag-disubprogram-callsite.c
@@ -13,7 +13,7 @@ int foo2(struct t1 *arg) {
   return foo(arg);
 }
 
-// CHECK: ![[#]] = !DISubprogram(name: "foo", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, 
retainedNodes: ![[#]], annotations: ![[ANNOT:[0-9]+]])
+// CHECK: ![[#]] = !DISubprogram(name: "foo", scope: ![[#]], file: ![[#]], 
line: [[#]], type: ![[#]], flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, 
annotations: ![[ANNOT:[0-9]+]])
 // CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
 // CHECK: ![[TAG1]] = !{!"btf_decl_tag", !"tag1"}
 // CHECK: ![[TAG2]] = !{!"btf_decl_tag", !"tag2"}

diff  --git a/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp 
b/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
index a35ca27e10d2a..6453e4379ae9a 100644
--- a/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
+++ b/clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
@@ -52,15 +52,15 @@ X v;
 // CHECK:   ret void
 // CHECK: }
 
-// CHECK: ![[DBGVAR16]] = distinct !DISubprogram(name: 
"__cxx_global_var_init", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: 
!{{[0-9]+}}, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | 
DISPFlagDefinition, unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CHECK: ![[DBGVAR16]] = distinct !DISubprogram(name: 
"__cxx_global_var_init", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: 
!{{[0-9]+}}, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | 
DISPFlagDefinition, unit: !{{[0-9]+}})
 // CHECK: ![[DBGVAR19]] = !DILocation(line: 14, column: 3, scope: 
![[DBGVAR16]])
 // CHECK: ![[DBGVAR19b]] = !DILocation(line: 0, scope: ![[DBGVAR16]])
-// CHECK: ![[DBGVAR20]] = distinct !DISubprogram(name: "__dtor_v", scope: 
!{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 14, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CHECK: ![[DBGVAR20]] = distinct !DISubprogram(name: "__dtor_v", scope: 
!{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 14, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}})
 // CHECK: ![[DBGVAR21b]] = !DILocation(line: 0, scope: ![[DBGVAR20]])
 // CHECK: ![[DBGVAR21]] = !DILocation(line: 14, column: 3, scope: 
![[DBGVAR20]])
-// CHECK: ![[DBGVAR22]] = distinct !DISubprogram(linkageName: "__finalize_v", 
scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 
14, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CHECK: ![[DBGVAR22]] = distinct !DISubprogram(linkageName: "__finalize_v", 
scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 14, type: !{{[0-9]+}}, scopeLine: 
14, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, 
unit: !{{[0-9]+}})
 // CHECK: ![[DBGVAR24]] = !DILocation(line: 14, column: 3, scope: 
![[DBGVAR22]])
-// CHECK: ![[DBGVAR25]] = distinct !DISubprogram(linkageName: 
"_GLOBAL__sub_I__", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: !{{[0-9]+}}, 
flags: DIFlagArtificial, spFlags: DISPFlagLocalToUni

[clang] d04452d - [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-06-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-15T14:29:03+02:00
New Revision: d04452d54829cd7af5b43d670325ffa755ab0030

URL: 
https://github.com/llvm/llvm-project/commit/d04452d54829cd7af5b43d670325ffa755ab0030
DIFF: 
https://github.com/llvm/llvm-project/commit/d04452d54829cd7af5b43d670325ffa755ab0030.diff

LOG: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported 
entities (3/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Fixed PR51501 (tests from D112337).

1. Reuse of DISubprogram's 'retainedNodes' to track other function-local
   entities together with local variables and labels (this patch cares about
   function-local import while D144006 and D144008 use the same approach for
   local types and static variables). So, effectively this patch moves ownership
   of tracking local import from DICompileUnit's 'imports' field to 
DISubprogram's
   'retainedNodes' and adjusts DWARF emitter for the new layout. The old layout
   is considered unsupported (DwarfDebug would assert on such debug metadata).

   DICompileUnit's 'imports' field is supposed to track global imported
   declarations as it does before.

   This addresses various FIXMEs and simplifies the next part of the patch.

2. Postpone emission of function-local imported entities from
   `DwarfDebug::endFunctionImpl()` to `DwarfDebug::endModule()`.
   While in `DwarfDebug::endFunctionImpl()` we do not have all the
   information about a parent subprogram or a referring subprogram
   (whether a subprogram inlined or not), so we can't guarantee we emit
   an imported entity correctly and place it in a proper subprogram tree.
   So now, we just gather needed details about the import itself and its
   parent entity (either a Subprogram or a LexicalBlock) during
   processing in `DwarfDebug::endFunctionImpl()`, but all the real work is
   done in `DwarfDebug::endModule()` when we have all the required
   information to make proper emission.

Authored-by: Kristina Bessonova 

Differential Revision: https://reviews.llvm.org/D144004

Added: 
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGenCXX/debug-info-namespace.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/DIModule-fortran-external-module.ll
llvm/test/CodeGen/Generic/DbgValueAggregate.ll
llvm/test/DebugInfo/Generic/imported-name-inlined.ll
llvm/test/DebugInfo/Generic/namespace.ll
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
llvm/test/DebugInfo/X86/fission-inline.ll
llvm/test/DebugInfo/X86/fission-local-import.ll
llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
llvm/test/DebugInfo/X86/namelist2.ll
llvm/test/DebugInfo/omit-empty.ll
llvm/test/Linker/pr26037.ll
llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp 
b/clang/test/CodeGenCXX/debug-info-namespace.cpp
index be88feda1112f..e3cf6507e1611 100644
--- a/clang/test/CodeGenCXX/debug-info-namespace.cpp
+++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp
@@ -81,44 +81,43 @@ void C::c() {}
 // CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
-// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]
+// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]]}
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CTXT]], entity: [[NS]], file: [[FOOCPP]], line: 15)
-
 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[C

[clang] a7e7d34 - Revert "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)"

2023-06-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-15T14:35:54+02:00
New Revision: a7e7d34dc1ce35afdcd813348a7254ddfe13698a

URL: 
https://github.com/llvm/llvm-project/commit/a7e7d34dc1ce35afdcd813348a7254ddfe13698a
DIFF: 
https://github.com/llvm/llvm-project/commit/a7e7d34dc1ce35afdcd813348a7254ddfe13698a.diff

LOG: Revert "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local 
imported entities (3/7)"

This reverts commit d04452d54829cd7af5b43d670325ffa755ab0030 since
test llvm-project/llvm/test/Bitcode/DIImportedEntity_backward.ll is broken.

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-namespace.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/DIModule-fortran-external-module.ll
llvm/test/CodeGen/Generic/DbgValueAggregate.ll
llvm/test/DebugInfo/Generic/imported-name-inlined.ll
llvm/test/DebugInfo/Generic/namespace.ll
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
llvm/test/DebugInfo/X86/fission-inline.ll
llvm/test/DebugInfo/X86/fission-local-import.ll
llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
llvm/test/DebugInfo/X86/namelist2.ll
llvm/test/DebugInfo/omit-empty.ll
llvm/test/Linker/pr26037.ll
llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Removed: 
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp 
b/clang/test/CodeGenCXX/debug-info-namespace.cpp
index e3cf6507e1611..be88feda1112f 100644
--- a/clang/test/CodeGenCXX/debug-info-namespace.cpp
+++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp
@@ -81,43 +81,44 @@ void C::c() {}
 // CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
-// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]]}
+// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CTXT]], entity: [[NS]], file: [[FOOCPP]], line: 15)
+
 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CU]], entity: [[CTXT]],
 // CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: 
"E", scope: [[CU]], entity: [[CTXT]], file: [[FOOCPP]], line: 19)
-// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[CTXT]], entity: [[I]]
-// CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4
-// CHECK-SAME:   DISPFlagDefinition
-// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} 
DISPFlagDefinition
-// CHECK-SAME: retainedNodes: 
[[FUNC_NODES:![0-9]*]]
-// CHECK: [[FUNC_NODES]] = !{[[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], 
[[M8:![0-9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], 
[[M12:![0-9]+]], [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], 
[[M16:![0-9]+]], [[M17:![0-9]+]]}
-// CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
+// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
 // CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: 
[[FOOCPP]],
 // CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC:![0-9]+]], file: 
[[FOOCPP]],
-// CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[FUNC]], entity: [[CTXT]],
-// CHECK: [[M7]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[FUNC]], entity: [[FOO:![0-9]+]], file: [[FOOCPP]], line: 27)
+
+// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "f

[clang] ed578f0 - [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-06-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-15T16:15:39+02:00
New Revision: ed578f02cf44a52adde16647150e7421f3ef70f3

URL: 
https://github.com/llvm/llvm-project/commit/ed578f02cf44a52adde16647150e7421f3ef70f3
DIFF: 
https://github.com/llvm/llvm-project/commit/ed578f02cf44a52adde16647150e7421f3ef70f3.diff

LOG: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported 
entities (3/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Fixed PR51501 (tests from D112337).

1. Reuse of DISubprogram's 'retainedNodes' to track other function-local
   entities together with local variables and labels (this patch cares about
   function-local import while D144006 and D144008 use the same approach for
   local types and static variables). So, effectively this patch moves ownership
   of tracking local import from DICompileUnit's 'imports' field to 
DISubprogram's
   'retainedNodes' and adjusts DWARF emitter for the new layout. The old layout
   is considered unsupported (DwarfDebug would assert on such debug metadata).

   DICompileUnit's 'imports' field is supposed to track global imported
   declarations as it does before.

   This addresses various FIXMEs and simplifies the next part of the patch.

2. Postpone emission of function-local imported entities from
   `DwarfDebug::endFunctionImpl()` to `DwarfDebug::endModule()`.
   While in `DwarfDebug::endFunctionImpl()` we do not have all the
   information about a parent subprogram or a referring subprogram
   (whether a subprogram inlined or not), so we can't guarantee we emit
   an imported entity correctly and place it in a proper subprogram tree.
   So now, we just gather needed details about the import itself and its
   parent entity (either a Subprogram or a LexicalBlock) during
   processing in `DwarfDebug::endFunctionImpl()`, but all the real work is
   done in `DwarfDebug::endModule()` when we have all the required
   information to make proper emission.

Authored-by: Kristina Bessonova 

Differential Revision: https://reviews.llvm.org/D144004

Added: 
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGenCXX/debug-info-namespace.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/DIImportedEntity_backward.ll
llvm/test/Bitcode/DIModule-fortran-external-module.ll
llvm/test/CodeGen/Generic/DbgValueAggregate.ll
llvm/test/DebugInfo/Generic/imported-name-inlined.ll
llvm/test/DebugInfo/Generic/namespace.ll
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
llvm/test/DebugInfo/X86/fission-inline.ll
llvm/test/DebugInfo/X86/fission-local-import.ll
llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
llvm/test/DebugInfo/X86/namelist2.ll
llvm/test/DebugInfo/omit-empty.ll
llvm/test/Linker/pr26037.ll
llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp 
b/clang/test/CodeGenCXX/debug-info-namespace.cpp
index be88feda1112f..e3cf6507e1611 100644
--- a/clang/test/CodeGenCXX/debug-info-namespace.cpp
+++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp
@@ -81,44 +81,43 @@ void C::c() {}
 // CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
-// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]
+// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]]}
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CTXT]], entity: [[NS]], file: [[FOOCPP]], line: 15)
-
 // CHECK: [[M2]] = !DIImpo

[clang] 77f8f40 - Revert "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)"

2023-06-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-15T16:53:36+02:00
New Revision: 77f8f40cd492def39ee7a66fb7287eb4b0055428

URL: 
https://github.com/llvm/llvm-project/commit/77f8f40cd492def39ee7a66fb7287eb4b0055428
DIFF: 
https://github.com/llvm/llvm-project/commit/77f8f40cd492def39ee7a66fb7287eb4b0055428.diff

LOG: Revert "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local 
imported entities (3/7)"

This reverts commit ed578f02cf44a52adde16647150e7421f3ef70f3.

Tests llvm/test/DebugInfo/Generic/split-dwarf-local-import*.ll fail
when x86_64 target is not registered.

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-namespace.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/DIImportedEntity_backward.ll
llvm/test/Bitcode/DIModule-fortran-external-module.ll
llvm/test/CodeGen/Generic/DbgValueAggregate.ll
llvm/test/DebugInfo/Generic/imported-name-inlined.ll
llvm/test/DebugInfo/Generic/namespace.ll
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
llvm/test/DebugInfo/X86/fission-inline.ll
llvm/test/DebugInfo/X86/fission-local-import.ll
llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
llvm/test/DebugInfo/X86/namelist2.ll
llvm/test/DebugInfo/omit-empty.ll
llvm/test/Linker/pr26037.ll
llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Removed: 
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp 
b/clang/test/CodeGenCXX/debug-info-namespace.cpp
index e3cf6507e1611..be88feda1112f 100644
--- a/clang/test/CodeGenCXX/debug-info-namespace.cpp
+++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp
@@ -81,43 +81,44 @@ void C::c() {}
 // CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
-// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]]}
+// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CTXT]], entity: [[NS]], file: [[FOOCPP]], line: 15)
+
 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CU]], entity: [[CTXT]],
 // CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: 
"E", scope: [[CU]], entity: [[CTXT]], file: [[FOOCPP]], line: 19)
-// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[CTXT]], entity: [[I]]
-// CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4
-// CHECK-SAME:   DISPFlagDefinition
-// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} 
DISPFlagDefinition
-// CHECK-SAME: retainedNodes: 
[[FUNC_NODES:![0-9]*]]
-// CHECK: [[FUNC_NODES]] = !{[[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], 
[[M8:![0-9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], 
[[M12:![0-9]+]], [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], 
[[M16:![0-9]+]], [[M17:![0-9]+]]}
-// CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
+// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
 // CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: 
[[FOOCPP]],
 // CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC:![0-9]+]], file: 
[[FOOCPP]],
-// CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[FUNC]], entity: [[CTXT]],
-// CHECK: [[M7]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[FUNC]], entity: [[FOO:![0-9]+]], file: [[FOOCPP

[clang] d80fdc6 - [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)

2023-06-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-15T17:17:53+02:00
New Revision: d80fdc6fc1a6e717af1bcd7a7313e65de433ba85

URL: 
https://github.com/llvm/llvm-project/commit/d80fdc6fc1a6e717af1bcd7a7313e65de433ba85
DIFF: 
https://github.com/llvm/llvm-project/commit/d80fdc6fc1a6e717af1bcd7a7313e65de433ba85.diff

LOG: [DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported 
entities (3/7)

RFC 
https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

Fixed PR51501 (tests from D112337).

1. Reuse of DISubprogram's 'retainedNodes' to track other function-local
   entities together with local variables and labels (this patch cares about
   function-local import while D144006 and D144008 use the same approach for
   local types and static variables). So, effectively this patch moves ownership
   of tracking local import from DICompileUnit's 'imports' field to 
DISubprogram's
   'retainedNodes' and adjusts DWARF emitter for the new layout. The old layout
   is considered unsupported (DwarfDebug would assert on such debug metadata).

   DICompileUnit's 'imports' field is supposed to track global imported
   declarations as it does before.

   This addresses various FIXMEs and simplifies the next part of the patch.

2. Postpone emission of function-local imported entities from
   `DwarfDebug::endFunctionImpl()` to `DwarfDebug::endModule()`.
   While in `DwarfDebug::endFunctionImpl()` we do not have all the
   information about a parent subprogram or a referring subprogram
   (whether a subprogram inlined or not), so we can't guarantee we emit
   an imported entity correctly and place it in a proper subprogram tree.
   So now, we just gather needed details about the import itself and its
   parent entity (either a Subprogram or a LexicalBlock) during
   processing in `DwarfDebug::endFunctionImpl()`, but all the real work is
   done in `DwarfDebug::endModule()` when we have all the required
   information to make proper emission.

Authored-by: Kristina Bessonova 

Differential Revision: https://reviews.llvm.org/D144004

Added: 
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGenCXX/debug-info-namespace.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/DIImportedEntity_backward.ll
llvm/test/Bitcode/DIModule-fortran-external-module.ll
llvm/test/CodeGen/Generic/DbgValueAggregate.ll
llvm/test/DebugInfo/Generic/imported-name-inlined.ll
llvm/test/DebugInfo/Generic/namespace.ll
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
llvm/test/DebugInfo/X86/fission-inline.ll
llvm/test/DebugInfo/X86/fission-local-import.ll
llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
llvm/test/DebugInfo/X86/namelist2.ll
llvm/test/DebugInfo/omit-empty.ll
llvm/test/Linker/pr26037.ll
llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp 
b/clang/test/CodeGenCXX/debug-info-namespace.cpp
index be88feda1112f..e3cf6507e1611 100644
--- a/clang/test/CodeGenCXX/debug-info-namespace.cpp
+++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp
@@ -81,44 +81,43 @@ void C::c() {}
 // CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
-// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]
+// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]]}
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CTXT]], entity: [[NS]], file: [[FOOCPP]], line: 15)
-
 // CHECK: [[M2]] = !DIImpo

[clang] fbdeb8c - Revert "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)"

2023-06-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-15T18:04:32+02:00
New Revision: fbdeb8cbc147f8f49fbd4bf23fae01bd142f0f5d

URL: 
https://github.com/llvm/llvm-project/commit/fbdeb8cbc147f8f49fbd4bf23fae01bd142f0f5d
DIFF: 
https://github.com/llvm/llvm-project/commit/fbdeb8cbc147f8f49fbd4bf23fae01bd142f0f5d.diff

LOG: Revert "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local 
imported entities (3/7)"

This reverts commit d80fdc6fc1a6e717af1bcd7a7313e65de433ba85.
split-dwarf-local-impor3.ll fails because of an issue with
Dwo sections emission on Windows platform.

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-namespace.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/DIImportedEntity_backward.ll
llvm/test/Bitcode/DIModule-fortran-external-module.ll
llvm/test/CodeGen/Generic/DbgValueAggregate.ll
llvm/test/DebugInfo/Generic/imported-name-inlined.ll
llvm/test/DebugInfo/Generic/namespace.ll
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
llvm/test/DebugInfo/X86/fission-inline.ll
llvm/test/DebugInfo/X86/fission-local-import.ll
llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
llvm/test/DebugInfo/X86/namelist2.ll
llvm/test/DebugInfo/omit-empty.ll
llvm/test/Linker/pr26037.ll
llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Removed: 
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp 
b/clang/test/CodeGenCXX/debug-info-namespace.cpp
index e3cf6507e1611..be88feda1112f 100644
--- a/clang/test/CodeGenCXX/debug-info-namespace.cpp
+++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp
@@ -81,43 +81,44 @@ void C::c() {}
 // CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
-// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]]}
+// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CTXT]], entity: [[NS]], file: [[FOOCPP]], line: 15)
+
 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CU]], entity: [[CTXT]],
 // CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: 
"E", scope: [[CU]], entity: [[CTXT]], file: [[FOOCPP]], line: 19)
-// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[CTXT]], entity: [[I]]
-// CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4
-// CHECK-SAME:   DISPFlagDefinition
-// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} 
DISPFlagDefinition
-// CHECK-SAME: retainedNodes: 
[[FUNC_NODES:![0-9]*]]
-// CHECK: [[FUNC_NODES]] = !{[[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], 
[[M8:![0-9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], 
[[M12:![0-9]+]], [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], 
[[M16:![0-9]+]], [[M17:![0-9]+]]}
-// CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
+// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
 // CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: 
[[FOOCPP]],
 // CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC:![0-9]+]], file: 
[[FOOCPP]],
-// CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[FUNC]], entity: [[CTXT]],
-// CHECK: [[M7]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[FUNC]], entity: [[FOO:![0-9]+]], file: [[FOOCPP]], l

[clang] fcc3981 - Reland "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)"

2023-06-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-15T18:15:16+02:00
New Revision: fcc3981626821addc6c77b98006d02030b8ceb7f

URL: 
https://github.com/llvm/llvm-project/commit/fcc3981626821addc6c77b98006d02030b8ceb7f
DIFF: 
https://github.com/llvm/llvm-project/commit/fcc3981626821addc6c77b98006d02030b8ceb7f.diff

LOG: Reland "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local 
imported entities (3/7)"

Run split-dwarf-local-impor3.ll only on x86_64-linux.

Added: 
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGenCXX/debug-info-namespace.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/DIImportedEntity_backward.ll
llvm/test/Bitcode/DIModule-fortran-external-module.ll
llvm/test/CodeGen/Generic/DbgValueAggregate.ll
llvm/test/DebugInfo/Generic/imported-name-inlined.ll
llvm/test/DebugInfo/Generic/namespace.ll
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
llvm/test/DebugInfo/X86/fission-inline.ll
llvm/test/DebugInfo/X86/fission-local-import.ll
llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
llvm/test/DebugInfo/X86/namelist2.ll
llvm/test/DebugInfo/omit-empty.ll
llvm/test/Linker/pr26037.ll
llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp 
b/clang/test/CodeGenCXX/debug-info-namespace.cpp
index be88feda1112f..e3cf6507e1611 100644
--- a/clang/test/CodeGenCXX/debug-info-namespace.cpp
+++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp
@@ -81,44 +81,43 @@ void C::c() {}
 // CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
-// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]
+// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]]}
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CTXT]], entity: [[NS]], file: [[FOOCPP]], line: 15)
-
 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CU]], entity: [[CTXT]],
 // CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: 
"E", scope: [[CU]], entity: [[CTXT]], file: [[FOOCPP]], line: 19)
-// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
+// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[CTXT]], entity: [[I]]
+// CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4
+// CHECK-SAME:   DISPFlagDefinition
+// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} 
DISPFlagDefinition
+// CHECK-SAME: retainedNodes: 
[[FUNC_NODES:![0-9]*]]
+// CHECK: [[FUNC_NODES]] = !{[[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], 
[[M8:![0-9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], 
[[M12:![0-9]+]], [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], 
[[M16:![0-9]+]], [[M17:![0-9]+]]}
+// CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
 // CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: 
[[FOOCPP]],
 // CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC:![0-9]+]], file: 
[[FOOCPP]],
-
-// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} 
DISPFlagDefinition
-// CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[FUNC]], entity: [[CTXT:![0-9]+]],
-// CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[FUNC]], entity: [[FOO:![0-9]+]], file: [[FOOCPP]], line: 27

[clang] b8ea03a - Revert "Reland "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)""

2023-06-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-15T19:36:36+02:00
New Revision: b8ea03a4be0123cbff958711ec6d89e1ddaa347a

URL: 
https://github.com/llvm/llvm-project/commit/b8ea03a4be0123cbff958711ec6d89e1ddaa347a
DIFF: 
https://github.com/llvm/llvm-project/commit/b8ea03a4be0123cbff958711ec6d89e1ddaa347a.diff

LOG: Revert "Reland "[DebugMetadata][DwarfDebug] Fix DWARF emisson of 
function-local imported entities (3/7)""

This reverts commit fcc3981626821addc6c77b98006d02030b8ceb7f,
since Bitcode-upgrading code doesn't seem to be deterministic.

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-namespace.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/DIImportedEntity_backward.ll
llvm/test/Bitcode/DIModule-fortran-external-module.ll
llvm/test/CodeGen/Generic/DbgValueAggregate.ll
llvm/test/DebugInfo/Generic/imported-name-inlined.ll
llvm/test/DebugInfo/Generic/namespace.ll
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
llvm/test/DebugInfo/X86/fission-inline.ll
llvm/test/DebugInfo/X86/fission-local-import.ll
llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
llvm/test/DebugInfo/X86/namelist2.ll
llvm/test/DebugInfo/omit-empty.ll
llvm/test/Linker/pr26037.ll
llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Removed: 
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll



diff  --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp 
b/clang/test/CodeGenCXX/debug-info-namespace.cpp
index e3cf6507e1611..be88feda1112f 100644
--- a/clang/test/CodeGenCXX/debug-info-namespace.cpp
+++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp
@@ -81,43 +81,44 @@ void C::c() {}
 // CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
-// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]]}
+// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CTXT]], entity: [[NS]], file: [[FOOCPP]], line: 15)
+
 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CU]], entity: [[CTXT]],
 // CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: 
"E", scope: [[CU]], entity: [[CTXT]], file: [[FOOCPP]], line: 19)
-// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[CTXT]], entity: [[I]]
-// CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4
-// CHECK-SAME:   DISPFlagDefinition
-// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} 
DISPFlagDefinition
-// CHECK-SAME: retainedNodes: 
[[FUNC_NODES:![0-9]*]]
-// CHECK: [[FUNC_NODES]] = !{[[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], 
[[M8:![0-9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], 
[[M12:![0-9]+]], [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], 
[[M16:![0-9]+]], [[M17:![0-9]+]]}
-// CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
+// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
 // CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: 
[[FOOCPP]],
 // CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC:![0-9]+]], file: 
[[FOOCPP]],
-// CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[FUNC]], entity: [[CTXT]],
-// CHECK: [[M7]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[FUNC]], entity: [[FOO:![0-9]+]], file: [[FOOCPP]], line: 27)
+
+// CHECK: [[FUNC:!

[clang] 06a0ae6 - Reland "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local imported entities (3/7)"

2023-06-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2023-06-16T00:49:59+02:00
New Revision: 06a0ae652497513398865d9a1b0cc3f95aa82f54

URL: 
https://github.com/llvm/llvm-project/commit/06a0ae652497513398865d9a1b0cc3f95aa82f54
DIFF: 
https://github.com/llvm/llvm-project/commit/06a0ae652497513398865d9a1b0cc3f95aa82f54.diff

LOG: Reland "[DebugMetadata][DwarfDebug] Fix DWARF emisson of function-local 
imported entities (3/7)"

Got rid of non-determinism in MetadataLoader.cpp.

Authored-by: Kristina Bessonova 

Differential Revision: https://reviews.llvm.org/D144004

Added: 
llvm/test/Bitcode/upgrade-cu-locals.ll
llvm/test/Bitcode/upgrade-cu-locals.ll.bc
llvm/test/DebugInfo/Generic/import-inlined-declaration.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import2.ll
llvm/test/DebugInfo/Generic/split-dwarf-local-import3.ll

Modified: 
clang/test/CodeGenCXX/debug-info-namespace.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Linker/IRMover.cpp
llvm/test/Bitcode/DIImportedEntity_backward.ll
llvm/test/Bitcode/DIModule-fortran-external-module.ll
llvm/test/CodeGen/Generic/DbgValueAggregate.ll
llvm/test/DebugInfo/Generic/imported-name-inlined.ll
llvm/test/DebugInfo/Generic/namespace.ll
llvm/test/DebugInfo/Generic/verifier-invalid-disubprogram.ll
llvm/test/DebugInfo/X86/dimodule-external-fortran.ll
llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
llvm/test/DebugInfo/X86/fission-inline.ll
llvm/test/DebugInfo/X86/fission-local-import.ll
llvm/test/DebugInfo/X86/fission-no-inline-gsym.ll
llvm/test/DebugInfo/X86/lexical-block-file-inline.ll
llvm/test/DebugInfo/X86/namelist2.ll
llvm/test/DebugInfo/omit-empty.ll
llvm/test/Linker/pr26037.ll
llvm/test/ThinLTO/X86/debuginfo-cu-import.ll

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-namespace.cpp 
b/clang/test/CodeGenCXX/debug-info-namespace.cpp
index be88feda1112f..e3cf6507e1611 100644
--- a/clang/test/CodeGenCXX/debug-info-namespace.cpp
+++ b/clang/test/CodeGenCXX/debug-info-namespace.cpp
@@ -81,44 +81,43 @@ void C::c() {}
 // CHECK: !DINamespace(scope: null)
 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-SAME:imports: [[MODULES:![0-9]*]]
-// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], 
[[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], 
[[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], 
[[M17:![0-9]+]]
+// CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], 
[[M4:![0-9]+]]}
 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CTXT]], entity: [[NS]], file: [[FOOCPP]], line: 15)
-
 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[CU]], entity: [[CTXT]],
 // CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: 
"E", scope: [[CU]], entity: [[CTXT]], file: [[FOOCPP]], line: 19)
-// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
+// CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[CTXT]], entity: [[I]]
+// CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4
+// CHECK-SAME:   DISPFlagDefinition
+// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} 
DISPFlagDefinition
+// CHECK-SAME: retainedNodes: 
[[FUNC_NODES:![0-9]*]]
+// CHECK: [[FUNC_NODES]] = !{[[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], 
[[M8:![0-9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], 
[[M12:![0-9]+]], [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], 
[[M16:![0-9]+]], [[M17:![0-9]+]]}
+// CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[LEX2:![0-9]+]], entity: [[NS]], file: [[FOOCPP]], line: 23)
 // CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: 
[[FOOCPP]],
 // CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC:![0-9]+]], file: 
[[FOOCPP]],
-
-// CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} 
DISPFlagDefinition
-// CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: 
[[FUNC]], entity: [[CTXT:![0-9]+]],
-// CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_impo

[clang] 731abdf - [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2022-12-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2022-12-15T15:10:41+03:00
New Revision: 731abdfdcc33d813e6c3b4b89eff307aa5c18083

URL: 
https://github.com/llvm/llvm-project/commit/731abdfdcc33d813e6c3b4b89eff307aa5c18083
DIFF: 
https://github.com/llvm/llvm-project/commit/731abdfdcc33d813e6c3b4b89eff307aa5c18083.diff

LOG: [clang][CodeGen] Use base subobject type layout for 
potentially-overlapping fields

RecordLayoutBuilder assumes the size of a potentially-overlapping field
with non-zero size as the size of the base subobject type corresponding
to the field type.
Make CGRecordLayoutBuilder to acknowledge that in order to avoid incorrect
padding insertion.

Differential Revision: https://reviews.llvm.org/D139741

Added: 
clang/test/CodeGenCXX/no-unique-address-3.cpp

Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index cd33fcef56619..268ec7deeb814 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3062,6 +3062,10 @@ class FieldDecl : public DeclaratorDecl, public 
Mergeable {
   /// [[no_unique_address]] attribute.
   bool isZeroSize(const ASTContext &Ctx) const;
 
+  /// Determine if this field is of potentially-overlapping class type, that
+  /// is, subobject with the [[no_unique_address]] attribute
+  bool isPotentiallyOverlapping() const;
+
   /// Get the kind of (C++11) default member initializer that this field has.
   InClassInitStyle getInClassInitStyle() const {
 InitStorageKind storageKind = InitStorage.getInt();

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index b1fdc897bf27e..0f15d7b3b6d33 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4339,6 +4339,10 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
   return true;
 }
 
+bool FieldDecl::isPotentiallyOverlapping() const {
+  return hasAttr() && getType()->getAsCXXRecordDecl();
+}
+
 unsigned FieldDecl::getFieldIndex() const {
   const FieldDecl *Canonical = getCanonicalDecl();
   if (Canonical != this)

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 52bd3f20221f4..56cdbb75dd4b2 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1853,9 +1853,8 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const 
FieldDecl *D) {
 void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
  bool InsertExtraPadding) {
   auto *FieldClass = D->getType()->getAsCXXRecordDecl();
-  bool PotentiallyOverlapping = D->hasAttr() && 
FieldClass;
   bool IsOverlappingEmptyField =
-  PotentiallyOverlapping && FieldClass->isEmpty();
+  D->isPotentiallyOverlapping() && FieldClass->isEmpty();
 
   CharUnits FieldOffset =
   (IsUnion || IsOverlappingEmptyField) ? CharUnits::Zero() : getDataSize();
@@ -1916,7 +1915,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
 
 // A potentially-overlapping field occupies its dsize or nvsize, whichever
 // is larger.
-if (PotentiallyOverlapping) {
+if (D->isPotentiallyOverlapping()) {
   const ASTRecordLayout &Layout = Context.getASTRecordLayout(FieldClass);
   EffectiveFieldSize =
   std::max(Layout.getNonVirtualSize(), Layout.getDataSize());

diff  --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp 
b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 6f85bca8a2013..0f2d764bc9498 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -379,9 +379,14 @@ void CGRecordLowering::accumulateFields() {
   for (++Field; Field != FieldEnd && Field->isBitField(); ++Field);
   accumulateBitFields(Start, Field);
 } else if (!Field->isZeroSize(Context)) {
+  // Use base subobject layout for the potentially-overlapping field,
+  // as it is done in RecordLayoutBuilder
   Members.push_back(MemberInfo(
   bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
-  getStorageType(*Field), *Field));
+  Field->isPotentiallyOverlapping()
+  ? getStorageType(Field->getType()->getAsCXXRecordDecl())
+  : getStorageType(*Field),
+  *Field));
   ++Field;
 } else {
   ++Field;

diff  --git a/clang/test/CodeGenCXX/no-unique-address-3.cpp 
b/clang/test/CodeGenCXX/no-unique-address-3.cpp
new file mode 100644
index 0..f21e9d1d2b01e
--- /dev/null
+++ b/clang/test/CodeGenCXX/no-unique-address-3.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm 
-fdump-record-layouts -std=c++17 %s -o %t | FileCheck %s
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Empty (e

[clang] 19d300f - Revert "[clang][CodeGen] Use base subobject type layout for potentially-overlapping fields"

2022-12-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2022-12-15T18:12:26+03:00
New Revision: 19d300fb4150b94f6dc7d8d230553d36349a3002

URL: 
https://github.com/llvm/llvm-project/commit/19d300fb4150b94f6dc7d8d230553d36349a3002
DIFF: 
https://github.com/llvm/llvm-project/commit/19d300fb4150b94f6dc7d8d230553d36349a3002.diff

LOG: Revert "[clang][CodeGen] Use base subobject type layout for 
potentially-overlapping fields"

This reverts commit 731abdfdcc33d813e6c3b4b89eff307aa5c18083.

This commit breaks some tests in libcxx, e.g.
`std/utilities/expected/expected.expected/ctor/ctor.inplace.pass.cpp`

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Removed: 
clang/test/CodeGenCXX/no-unique-address-3.cpp



diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 268ec7deeb81..cd33fcef5661 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3062,10 +3062,6 @@ class FieldDecl : public DeclaratorDecl, public 
Mergeable {
   /// [[no_unique_address]] attribute.
   bool isZeroSize(const ASTContext &Ctx) const;
 
-  /// Determine if this field is of potentially-overlapping class type, that
-  /// is, subobject with the [[no_unique_address]] attribute
-  bool isPotentiallyOverlapping() const;
-
   /// Get the kind of (C++11) default member initializer that this field has.
   InClassInitStyle getInClassInitStyle() const {
 InitStorageKind storageKind = InitStorage.getInt();

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 0f15d7b3b6d3..b1fdc897bf27 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4339,10 +4339,6 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
   return true;
 }
 
-bool FieldDecl::isPotentiallyOverlapping() const {
-  return hasAttr() && getType()->getAsCXXRecordDecl();
-}
-
 unsigned FieldDecl::getFieldIndex() const {
   const FieldDecl *Canonical = getCanonicalDecl();
   if (Canonical != this)

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 56cdbb75dd4b..52bd3f20221f 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1853,8 +1853,9 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const 
FieldDecl *D) {
 void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
  bool InsertExtraPadding) {
   auto *FieldClass = D->getType()->getAsCXXRecordDecl();
+  bool PotentiallyOverlapping = D->hasAttr() && 
FieldClass;
   bool IsOverlappingEmptyField =
-  D->isPotentiallyOverlapping() && FieldClass->isEmpty();
+  PotentiallyOverlapping && FieldClass->isEmpty();
 
   CharUnits FieldOffset =
   (IsUnion || IsOverlappingEmptyField) ? CharUnits::Zero() : getDataSize();
@@ -1915,7 +1916,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
 
 // A potentially-overlapping field occupies its dsize or nvsize, whichever
 // is larger.
-if (D->isPotentiallyOverlapping()) {
+if (PotentiallyOverlapping) {
   const ASTRecordLayout &Layout = Context.getASTRecordLayout(FieldClass);
   EffectiveFieldSize =
   std::max(Layout.getNonVirtualSize(), Layout.getDataSize());

diff  --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp 
b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 0f2d764bc949..6f85bca8a201 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -379,14 +379,9 @@ void CGRecordLowering::accumulateFields() {
   for (++Field; Field != FieldEnd && Field->isBitField(); ++Field);
   accumulateBitFields(Start, Field);
 } else if (!Field->isZeroSize(Context)) {
-  // Use base subobject layout for the potentially-overlapping field,
-  // as it is done in RecordLayoutBuilder
   Members.push_back(MemberInfo(
   bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
-  Field->isPotentiallyOverlapping()
-  ? getStorageType(Field->getType()->getAsCXXRecordDecl())
-  : getStorageType(*Field),
-  *Field));
+  getStorageType(*Field), *Field));
   ++Field;
 } else {
   ++Field;

diff  --git a/clang/test/CodeGenCXX/no-unique-address-3.cpp 
b/clang/test/CodeGenCXX/no-unique-address-3.cpp
deleted file mode 100644
index f21e9d1d2b01..
--- a/clang/test/CodeGenCXX/no-unique-address-3.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm 
-fdump-record-layouts -std=c++17 %s -o %t | FileCheck %s
-
-// CHECK:   *** Dumping AST Record Layout
-// CHECK-NEXT:   0 | class Empty (empty)
-// CHECK-NEXT: | [sizeof=1, dsize=1, align=1,
-// CHECK-NEXT: |  nvsize=1, nvalign=1]
-// CHECK: 

[clang] [llvm] [DebugInfo] Place local ODR-uniqued types in decl DISubprograms (PR #119001)

2025-02-26 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

Apologies for the delay in reviewing that. I was stuck on the original issue, 
so I appreciate this contribution. Now it's clear what was the root cause of 
the problem.

> There's also a risk that I misapplied D144008, which I had to copy-and-paste 
> out of Phab, @dzhidzhoev would you have a public-github branch that contains 
> that patch?.

Yes, it is here https://github.com/dzhidzhoev/llvm-project/tree/rfc-krisb. I've 
rebased it on top of your changes. I can try merging the rest of the patches 
from the set after this one, though I'm not sure if I should open new PRs here 
on GitHub for them, or how else we're going to collect feedback after a commit 
gets merged.


> While it passes the FileCheck lines in the test, it lacks the 
> DW_AT_abstract_origin that gcc produces -- observe that nothing references 
> addresses 8a or 5b. The consumer is then presumably left with a problem: it 
> might be able to discover the static variables A and B, and that they're in a 
> lexical block, but not _which_ lexical block.

Are we sure that is a problem right now? I've tried to generate LLVM IR from 
the C++ source provided in the .ll test comments, and it seems that we get all 
static local DIGlobalVariables having DISubprogram declaration scopes, not 
DILexicalBlock scopes, despite we have such structure in the .ll test file. 

https://github.com/llvm/llvm-project/pull/119001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits