[PATCH] D133945: [clang][ASTImporter] Continue with slow lookup in DeclContext::localUncachedLookup when regular lookup fails

2022-09-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, martong.
Herald added a subscriber: rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added projects: clang, LLDB.
Herald added subscribers: lldb-commits, cfe-commits.

The uncached lookup is mainly used in the ASTImporter/LLDB code-path
where we're not allowed to load from external storage. When importing
a FieldDecl with a DeclContext that had no external visible storage
(but came from a Clang module or PCH) the above call to `lookup(Name)`
the regular lookup fails because:

1. `DeclContext::buildLookup` doesn't set `LookupPtr` for decls that came from 
a module
2. LLDB doesn't use the `SharedImporterState`

In such a case but we would never go on to the "slow" path of iterating
through the decls in the DeclContext. In some cases this means that
`ASTNodeImporter::VisitFieldDecl` ends up importing a decl into the
`DeclContext` a second time.

The patch removes the short-circuit in the case where we don't find
any decls via the regular lookup.

**Tests**

- Un-skip the failing LLDB API tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133945

Files:
  clang/lib/AST/DeclBase.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py


Index: 
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
===
--- 
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
+++ 
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
@@ -30,7 +30,6 @@
 class TestBaseTemplateWithSameArg(TestBase):
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_base_template_arg(self):
 self.build()
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.


Index: lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
===
--- lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
+++ lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
@@ -30,7 +30,6 @@
 class TestBaseTemplateWithSameArg(TestBase):
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_base_template_arg(self):
 self.build()
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   //

[PATCH] D133945: [clang][ASTImporter] Continue with slow lookup in DeclContext::localUncachedLookup when regular lookup fails

2022-09-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.
Herald added a subscriber: JDevlieghere.



Comment at: clang/lib/AST/DeclBase.cpp:1781
   if (Name && !hasLazyLocalLexicalLookups() &&
   !hasLazyExternalLexicalLookups()) {
 if (StoredDeclsMap *Map = LookupPtr) {

Could merge the two if-blocks now I suppose


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133945

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


[PATCH] D133945: [clang][ASTImporter] Continue with slow lookup in DeclContext::localUncachedLookup when regular lookup fails

2022-09-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 460420.
Michael137 added a comment.

- Merge if-blocks
- Reword commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133945

Files:
  clang/lib/AST/DeclBase.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py


Index: 
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
===
--- 
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
+++ 
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
@@ -30,7 +30,6 @@
 class TestBaseTemplateWithSameArg(TestBase):
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_base_template_arg(self):
 self.build()
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,13 +1771,11 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
-  }
+if (!Results.empty())
+  return;
 
-  // If we have a lookup table, check there first. Maybe we'll get lucky.
-  // FIXME: Should we be checking these flags on the primary context?
-  if (Name && !hasLazyLocalLexicalLookups() &&
-  !hasLazyExternalLexicalLookups()) {
+// If we have a lookup table, check there first. Maybe we'll get lucky.
+// FIXME: Should we be checking these flags on the primary context?
 if (StoredDeclsMap *Map = LookupPtr) {
   StoredDeclsMap::iterator Pos = Map->find(Name);
   if (Pos != Map->end()) {


Index: lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
===
--- lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
+++ lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
@@ -30,7 +30,6 @@
 class TestBaseTemplateWithSameArg(TestBase):
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_base_template_arg(self):
 self.build()
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,13 +1771,11 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
-  }
+if (!Results.empty())
+  return;
 
-  // If we have a lookup table, check there first. Maybe we'll get lucky.
-  // FIXME: Should we be checking these flags on the primary context?
-  if (Name && !hasLazyLocalLexicalLookups() &&
-  !hasLazyExternalLexicalLookups()) {
+// If we have a lookup table, check there first. Maybe we'll get lucky.
+// FIXME: Should we be checking these flags on the primary context?
 if (StoredDeclsMap *Map = LookupPtr) {
   StoredDeclsMap::iterator Pos = Map->find(Name);
   if (Pos != Map->end()) {
___
cf

[PATCH] D133945: [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails

2022-09-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 460429.
Michael137 added a comment.

- Undo incorrect previous change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133945

Files:
  clang/lib/AST/DeclBase.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py


Index: 
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
===
--- 
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
+++ 
lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
@@ -30,7 +30,6 @@
 class TestBaseTemplateWithSameArg(TestBase):
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_base_template_arg(self):
 self.build()
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.


Index: lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
===
--- lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
+++ lldb/test/API/lang/cpp/gmodules/base-template-with-same-arg/TestBaseTemplateWithSameArg.py
@@ -30,7 +30,6 @@
 class TestBaseTemplateWithSameArg(TestBase):
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_base_template_arg(self):
 self.build()
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133945: [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails

2022-09-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/lib/AST/DeclBase.cpp:1781
   if (Name && !hasLazyLocalLexicalLookups() &&
   !hasLazyExternalLexicalLookups()) {
 if (StoredDeclsMap *Map = LookupPtr) {

Michael137 wrote:
> Could merge the two if-blocks now I suppose
Nevermind, not true


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133945

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


[PATCH] D123319: Change how we handle auto return types for lambda operator() to be consistent with gcc

2022-07-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D123319#3680169 , @aprantl wrote:

> Sorry for the silence — I was out on vacation.
>
> @Michael137 has recently started looking into improving support for C++ 
> lambdas in LLDB.
> Michael, would you be interested in taking a fresh look at this and figure 
> out what the requirements for LLDB are here and how to answer the questions 
> @dblaikie raised specifically?

Sure will have a look what's missing from https://reviews.llvm.org/D105564 and 
whether these clang changes are indeed necessary


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123319

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


[PATCH] D123319: Change how we handle auto return types for lambda operator() to be consistent with gcc

2022-07-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D123319#3682929 , @dblaikie wrote:

> In D123319#3681884 , @Michael137 
> wrote:
>
>> In D123319#3680169 , @aprantl 
>> wrote:
>>
>>> Sorry for the silence — I was out on vacation.
>>>
>>> @Michael137 has recently started looking into improving support for C++ 
>>> lambdas in LLDB.
>>> Michael, would you be interested in taking a fresh look at this and figure 
>>> out what the requirements for LLDB are here and how to answer the questions 
>>> @dblaikie raised specifically?
>>
>> Sure will have a look at what's missing from 
>> https://reviews.llvm.org/D105564 and whether these clang changes are indeed 
>> necessary
>
> Ah, the plan is to fix lldb and then revert this clang patch?

At least will want to see why this wasn't easy to fix on the LLDB side and 
whether it ties in to some of the other lambda bugs floating around


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123319

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


[PATCH] D123319: Change how we handle auto return types for lambda operator() to be consistent with gcc

2022-08-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

FYI, had an offline chat with @dblaikie and we decided that the best way 
forward would be to try stop emitting auto return types in DWARF, instead of 
relying on lambda/member-function specific hacks. Not sure what the timeline on 
this will be but tracking it internally


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123319

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


[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-08-24 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

FYI, this broke the LLDB build bot: 
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/46324/execution/node/74/log/

Looks like we're testing that unused parameters optimise out but that's not the 
case anymore

`AssertionError: '(void *) unused1 = ' not found in '(void *) unused1 = 0x00016fdff4d0\n'`

Looks like with this patch DWARF contains this extra entry for the unused 
parameter:

  0x0045: DW_TAG_formal_parameter   
  
DW_AT_location(0x:  
  
   [0x00013f1c, 0x00013f20): DW_OP_reg0 W0  
  
   [0x00013f20, 0x00013f24): 
DW_OP_entry_value(DW_OP_reg0 W0), DW_OP_stack_value) 

whereas previously it was,

  0x0045: DW_TAG_formal_parameter   
DW_AT_abstract_origin (0x0061 "unused1")


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128830

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


[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-08-24 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added subscribers: aprantl, dblaikie.
Michael137 added a comment.

In D128830#3745069 , @psamolysov 
wrote:

> @Michael137 Thank you very much for the information!
>
> I'm not sure, but it looks like the introduced change of the `readnone` 
> attribute to `readonly` might make impact on DWARF. Unfortunately, I have no 
> idea should this changes in DWARF be fixed or just it is enough to actualize 
> the test.
>
> I've reverted the patch to give our time to make the decision about DWARF 
> generation.

Thanks!

@aprantl @dblaikie Looks like this needs to accommodate existing DWARF 
generation behaviour?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128830

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


[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-08-25 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D128830#3746153 , @aprantl wrote:

> I think we can "fix" the test with the following patch:
>
>   diff --git a/lldb/test/API/functionalities/unused-inlined-parameters/main.c 
> b/lldb/test/API/functionalities/unused-inlined-parameters/main.c
>   index f2ef5dcc213d..9b9f95f6c946 100644
>   --- a/lldb/test/API/functionalities/unused-inlined-parameters/main.c
>   +++ b/lldb/test/API/functionalities/unused-inlined-parameters/main.c
>   @@ -7,6 +7,7 @@ __attribute__((always_inline)) void f(void *unused1, int 
> used, int unused2) {
>}
>
>int main(int argc, char **argv) {
>   -  f(argv, 42, 1);
>   +  char *undefined;
>   +  f(undefined, 42, 1);
>  return 0;
>   -}

Made the change to the test. Confirmed it passes with and without the patch. 
Feel free to push again


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128830

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


[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-08-26 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Noted, thanks for the heads up

AFAIK, the only test that'd now fail on the debug-info side is: 
https://reviews.llvm.org/D132664


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128830

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


[PATCH] D133945: [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails

2022-09-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 460718.
Michael137 added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133945

Files:
  clang/lib/AST/DeclBase.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py


Index: 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
===
--- 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
+++ 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
@@ -34,7 +34,6 @@
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_template_arg(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 
@@ -51,7 +50,6 @@
 ])
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_duplicate_decls(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.


Index: lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
===
--- lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
+++ lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
@@ -34,7 +34,6 @@
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_template_arg(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)
 
@@ -51,7 +50,6 @@
 ])
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_duplicate_decls(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133945: [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails

2022-09-16 Thread Michael Buch via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe456d2ba8bca: [clang][ASTImporter] 
DeclContext::localUncachedLookup: Continue lookup into… (authored by 
Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133945

Files:
  clang/lib/AST/DeclBase.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py


Index: 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
===
--- 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
+++ 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
@@ -34,7 +34,6 @@
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_template_arg(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 
@@ -51,7 +50,6 @@
 ])
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_duplicate_decls(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.


Index: lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
===
--- lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
+++ lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
@@ -34,7 +34,6 @@
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_template_arg(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)
 
@@ -51,7 +50,6 @@
 ])
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_duplicate_decls(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140423: [WIP][clang] Add PrintingPolicy callback for identifying default template arguments

2022-12-22 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, dblaikie.
Herald added a project: All.
Michael137 added a comment.
Michael137 updated this revision to Diff 484341.
Michael137 added a reviewer: labath.
Michael137 edited the summary of this revision.
Michael137 added a reviewer: aaron.ballman.
Michael137 updated this revision to Diff 484434.
Michael137 updated this revision to Diff 484439.
Michael137 published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

An example of how this would be used from LLDB is: 
https://reviews.llvm.org/D140145


Michael137 added a comment.

- Remove debug print in test


aprantl added a comment.

Overall this seems to have a pretty small surface area, so I'd be fine with 
including this.


Michael137 added a comment.

@aaron.ballman we're trying to fix printing of C++ types with default template 
arguments in LLDB. Currently DWARF doesn't have the necessary info to construct 
a `ClassTemplateDecl` with generic parameters, which means the logic for 
suppressing them in the `TypePrinter` doesn't quite work.

This patch outlines of one approach we considered. We add a hook into the 
TypePrinter to allow external AST sources to answer the question "is template 
argument X defaulted?".

Another alternative would be to have a `TemplateArgument::IsDefaulted` which 
gets set in LLDB and read from the TypePrinter.

Do you think either of these approaches would be fine for inclusion?


Michael137 added a comment.

- Fix test. Move variable into loop


Michael137 added a comment.

- Rebase


Michael137 added a comment.

putting into review queue to hear people's opinion on something along these 
lines




Comment at: clang/include/clang/AST/PrettyPrinter.h:52
+
+  enum class TriState : int { kYes, kNo, kUnknown };
+

The TrisState is needed because LLDB has two AST sources:
1. DWARF
2. clang modules

When we import a type from a clang module we would never have consulted DWARF 
about whether a parameter was defaulted. So instead of more complex bookkeeping 
it seemed simpler to say "if we've never seen this decl when parsing DWARF, I 
can't say anything about the default-ness of the arguments"



Comment at: clang/lib/AST/TypePrinter.cpp:2095
+
+  while (!Args.empty()) {
+if (Callbacks != nullptr)

maybe this body becomes slightly less oddly indented when converting it to a 
range-based for with a counter?


This patch adds a hook into the `TypePrinter` to allow clients
decide whether a template argument corresponds to the default
parameter.

**Motivation**

DWARF encodes information about template instantiations, but
not about the generic definition of a template. If an argument
in a template instantiation corresponds to the default parameter
of the generic template then DWARF will attach a `DW_AT_default_value`
to that argument. LLDB uses the Clang TypePrinter for
displaying/formatting C++ types but currently can't give Clang the 
`ClassTemplateDecl`
that it expects. Since LLDB does know whether a particular instantiation has
default arguments, this patch allows LLDB (and other clients with external AST 
sources)
to help Clang in identifying those default arguments.

**Alternatives**

1. Encode information about generic template definitions in DWARF. It's unclear 
how long it would take to get this proposed and implemented and whether 
something like this would work in the first place. If we could construct 
`ClassTemplateDecl`s with the correct generic parameters this patch wouldn't be 
required.

2. Add something like a `bool IsDefaulted` somewhere in Clang, e.g., in 
`TemplateArgument` and consult it from the `TypePrinter`. This would be much 
simpler but requires adding a field on one of the Clang types


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140423

Files:
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/TypePrinter.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -127,3 +127,39 @@
 Policy.EntireContentsOfLargeArray = true;
   }));
 }
+
+TEST(TypePrinter, TemplateParameterListWithCallback) {
+  constexpr char Code[] = R"cpp(
+template 
+struct Foo {   
+}; 
+   
+Foo X;   
+  )cpp";
+  auto Matcher = classTemplateSpecializationDecl(
+  hasName("Foo"), has(cxxConstructorDecl(
+  has(parmVarDecl(hasType(qualType().bind("id")));
+
+  struct DefaulterCallback final : public PrintingCallbacks {
+virtual TriState
+IsTemplateArgumentDefaulted(clang::ClassTemplateSpecializationDecl const *,
+   

[PATCH] D141826: [WIP][clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-25 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 492182.
Michael137 added a comment.

- Set `IsDefaulted` when checking template arguments in `clang::Sema`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

Files:
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -490,3 +490,34 @@
   ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
   EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
 }
+
+TEST(Decl, TemplateArgumentDefaulted) {
+  llvm::Annotations Code(R"cpp(
+template
+struct Alloc {};
+
+template >
+struct Foo {
+};
+
+Foo> X;
+  )cpp");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  EXPECT_FALSE(ArgList.get(0).getIsDefaulted());
+  EXPECT_FALSE(ArgList.get(1).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(2).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(3).getIsDefaulted());
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5857,6 +5857,7 @@
   SmallVector CanonicalArgumentPack;
   unsigned ArgIdx = 0, NumArgs = NewArgs.size();
   LocalInstantiationScope InstScope(*this, true);
+
   for (TemplateParameterList::iterator Param = Params->begin(),
ParamEnd = Params->end();
Param != ParamEnd; /* increment in loop */) {
@@ -5897,6 +5898,11 @@
 CTAK_Specified))
 return true;
 
+  CanonicalConverted.back().setIsDefaulted(
+  clang::isSubstitutedDefaultArgument(
+  Context, NewArgs[ArgIdx].getArgument(), *Param,
+  CanonicalConverted, Params->getDepth()));
+
   bool PackExpansionIntoNonPack =
   NewArgs[ArgIdx].getArgument().isPackExpansion() &&
   (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param));
@@ -6020,8 +6026,8 @@
   if (!ArgType)
 return true;
 
-  Arg = TemplateArgumentLoc(TemplateArgument(ArgType->getType()),
-ArgType);
+  Arg = TemplateArgumentLoc(
+  TemplateArgument(ArgType->getType(), false, true), ArgType);
 } else if (NonTypeTemplateParmDecl *NTTP
  = dyn_cast(*Param)) {
   if (!hasReachableDefaultArgument(NTTP))
@@ -6035,7 +6041,7 @@
 return true;
 
   Expr *Ex = E.getAs();
-  Arg = TemplateArgumentLoc(TemplateArgument(Ex), Ex);
+  Arg = TemplateArgumentLoc(TemplateArgument(Ex, true), Ex);
 } else {
   TemplateTemplateParmDecl *TempParm
 = cast(*Param);
@@ -6052,7 +6058,7 @@
 return true;
 
   Arg = TemplateArgumentLoc(
-  Context, TemplateArgument(Name), QualifierLoc,
+  Context, TemplateArgument(Name, true), QualifierLoc,
   TempParm->getDefaultArgument().getTemplateNameLoc());
 }
 
@@ -6072,6 +6078,8 @@
   CTAK_Specified))
   return true;
 
+CanonicalConverted.back().setIsDefaulted(true);
+
 // Core issue 150 (assumed resolution): if this is a template template
 // parameter, keep track of the default template arguments from the
 // template definition.
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -161,8 +161,9 @@
 //===--===//
 
 TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
-   QualType Type) {
+   QualType Type, bool IsDefaulted) {
   Integer.Kind = Integral;
+  Integer.IsDefaulted = IsDefaulted;
   // Copy the APSInt value into our decomposed form.
   Integer.BitWidth = Value.getBitWidth();
   Integer.IsUnsigned = Value.isUnsigned();
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -907,19 +907,16 @@
 // ClassTemplateSpecializationDecl Implementation
 //===--===//
 
-ClassTemplateSpecializationDe

[PATCH] D141826: [WIP][clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-25 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 492184.
Michael137 added a comment.

- Fix formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

Files:
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -490,3 +490,34 @@
   ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
   EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
 }
+
+TEST(Decl, TemplateArgumentDefaulted) {
+  llvm::Annotations Code(R"cpp(
+template
+struct Alloc {};
+
+template >
+struct Foo {
+};
+
+Foo> X;
+  )cpp");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  EXPECT_FALSE(ArgList.get(0).getIsDefaulted());
+  EXPECT_FALSE(ArgList.get(1).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(2).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(3).getIsDefaulted());
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5897,6 +5897,11 @@
 CTAK_Specified))
 return true;
 
+  CanonicalConverted.back().setIsDefaulted(
+  clang::isSubstitutedDefaultArgument(
+  Context, NewArgs[ArgIdx].getArgument(), *Param,
+  CanonicalConverted, Params->getDepth()));
+
   bool PackExpansionIntoNonPack =
   NewArgs[ArgIdx].getArgument().isPackExpansion() &&
   (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param));
@@ -6020,8 +6025,8 @@
   if (!ArgType)
 return true;
 
-  Arg = TemplateArgumentLoc(TemplateArgument(ArgType->getType()),
-ArgType);
+  Arg = TemplateArgumentLoc(
+  TemplateArgument(ArgType->getType(), false, true), ArgType);
 } else if (NonTypeTemplateParmDecl *NTTP
  = dyn_cast(*Param)) {
   if (!hasReachableDefaultArgument(NTTP))
@@ -6035,7 +6040,7 @@
 return true;
 
   Expr *Ex = E.getAs();
-  Arg = TemplateArgumentLoc(TemplateArgument(Ex), Ex);
+  Arg = TemplateArgumentLoc(TemplateArgument(Ex, true), Ex);
 } else {
   TemplateTemplateParmDecl *TempParm
 = cast(*Param);
@@ -6052,7 +6057,7 @@
 return true;
 
   Arg = TemplateArgumentLoc(
-  Context, TemplateArgument(Name), QualifierLoc,
+  Context, TemplateArgument(Name, true), QualifierLoc,
   TempParm->getDefaultArgument().getTemplateNameLoc());
 }
 
@@ -6072,6 +6077,8 @@
   CTAK_Specified))
   return true;
 
+CanonicalConverted.back().setIsDefaulted(true);
+
 // Core issue 150 (assumed resolution): if this is a template template
 // parameter, keep track of the default template arguments from the
 // template definition.
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -161,8 +161,9 @@
 //===--===//
 
 TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
-   QualType Type) {
+   QualType Type, bool IsDefaulted) {
   Integer.Kind = Integral;
+  Integer.IsDefaulted = IsDefaulted;
   // Copy the APSInt value into our decomposed form.
   Integer.BitWidth = Value.getBitWidth();
   Integer.IsUnsigned = Value.isUnsigned();
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6739,26 +6739,29 @@
 
 case TemplateArgument::Declaration: {
   auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
-  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()));
+  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()),
+  Arg.getIsDefaulted());
 }
 
 case TemplateArgument::NullPtr:
   return TemplateArgument(getCanonicalType(Arg.getNullPtrType()),
-  /*isNullPtr*/true);
+  /*isNullPtr*/ true, Arg.getIsDefaulted());
 
 case TemplateArgument::Template:
-  

[PATCH] D141826: [WIP][clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-25 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 492187.
Michael137 added a comment.

- Don't need to pass flag to NewArgs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

Files:
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -490,3 +490,34 @@
   ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
   EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
 }
+
+TEST(Decl, TemplateArgumentDefaulted) {
+  llvm::Annotations Code(R"cpp(
+template
+struct Alloc {};
+
+template >
+struct Foo {
+};
+
+Foo> X;
+  )cpp");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  EXPECT_FALSE(ArgList.get(0).getIsDefaulted());
+  EXPECT_FALSE(ArgList.get(1).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(2).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(3).getIsDefaulted());
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5897,6 +5897,11 @@
 CTAK_Specified))
 return true;
 
+  CanonicalConverted.back().setIsDefaulted(
+  clang::isSubstitutedDefaultArgument(
+  Context, NewArgs[ArgIdx].getArgument(), *Param,
+  CanonicalConverted, Params->getDepth()));
+
   bool PackExpansionIntoNonPack =
   NewArgs[ArgIdx].getArgument().isPackExpansion() &&
   (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param));
@@ -6020,8 +6025,8 @@
   if (!ArgType)
 return true;
 
-  Arg = TemplateArgumentLoc(TemplateArgument(ArgType->getType()),
-ArgType);
+  Arg = TemplateArgumentLoc(
+  TemplateArgument(ArgType->getType(), false), ArgType);
 } else if (NonTypeTemplateParmDecl *NTTP
  = dyn_cast(*Param)) {
   if (!hasReachableDefaultArgument(NTTP))
@@ -6072,6 +6077,8 @@
   CTAK_Specified))
   return true;
 
+CanonicalConverted.back().setIsDefaulted(true);
+
 // Core issue 150 (assumed resolution): if this is a template template
 // parameter, keep track of the default template arguments from the
 // template definition.
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -161,8 +161,9 @@
 //===--===//
 
 TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
-   QualType Type) {
+   QualType Type, bool IsDefaulted) {
   Integer.Kind = Integral;
+  Integer.IsDefaulted = IsDefaulted;
   // Copy the APSInt value into our decomposed form.
   Integer.BitWidth = Value.getBitWidth();
   Integer.IsUnsigned = Value.isUnsigned();
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6739,26 +6739,29 @@
 
 case TemplateArgument::Declaration: {
   auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
-  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()));
+  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()),
+  Arg.getIsDefaulted());
 }
 
 case TemplateArgument::NullPtr:
   return TemplateArgument(getCanonicalType(Arg.getNullPtrType()),
-  /*isNullPtr*/true);
+  /*isNullPtr*/ true, Arg.getIsDefaulted());
 
 case TemplateArgument::Template:
-  return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()));
+  return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()),
+  Arg.getIsDefaulted());
 
 case TemplateArgument::TemplateExpansion:
-  return TemplateArgument(getCanonicalTemplateName(
- Arg.getAsTemplateOrTemplatePattern()),
-  Arg.getNumTemplateExpansions());
+  return TemplateArgument(
+  getCanonicalTemplateName(Arg.getAsTemplate

[PATCH] D141826: [clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-25 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Latest diff now sets the `IsDefaulted` flag from 
`Sema::CheckTemplateArgumentList`, which is the best point I could find for 
creation of `TemplateArgument` which are fed into the various specialization 
decls (and later on the `TypePrinter`).

The review description has some additional info about the changes.

As a result of moving the `isSubstitutedDefaultArgument` higher up into `Sema`, 
we can simplify the other remaining callers:

- https://reviews.llvm.org/D141827
- https://reviews.llvm.org/D142333

Still unsure if changing the `TemplateArgument` constructors is cleaner than 
simply calling `setIsDefaulted` from the tablegen creators but I'm open to 
suggestions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

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


[PATCH] D141826: [clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-25 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 492306.
Michael137 added a comment.

- Remove redundant constructor call change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

Files:
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -490,3 +490,34 @@
   ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
   EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
 }
+
+TEST(Decl, TemplateArgumentDefaulted) {
+  llvm::Annotations Code(R"cpp(
+template
+struct Alloc {};
+
+template >
+struct Foo {
+};
+
+Foo> X;
+  )cpp");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  EXPECT_FALSE(ArgList.get(0).getIsDefaulted());
+  EXPECT_FALSE(ArgList.get(1).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(2).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(3).getIsDefaulted());
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5897,6 +5897,11 @@
 CTAK_Specified))
 return true;
 
+  CanonicalConverted.back().setIsDefaulted(
+  clang::isSubstitutedDefaultArgument(
+  Context, NewArgs[ArgIdx].getArgument(), *Param,
+  CanonicalConverted, Params->getDepth()));
+
   bool PackExpansionIntoNonPack =
   NewArgs[ArgIdx].getArgument().isPackExpansion() &&
   (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param));
@@ -6072,6 +6077,8 @@
   CTAK_Specified))
   return true;
 
+CanonicalConverted.back().setIsDefaulted(true);
+
 // Core issue 150 (assumed resolution): if this is a template template
 // parameter, keep track of the default template arguments from the
 // template definition.
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -161,8 +161,9 @@
 //===--===//
 
 TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
-   QualType Type) {
+   QualType Type, bool IsDefaulted) {
   Integer.Kind = Integral;
+  Integer.IsDefaulted = IsDefaulted;
   // Copy the APSInt value into our decomposed form.
   Integer.BitWidth = Value.getBitWidth();
   Integer.IsUnsigned = Value.isUnsigned();
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6739,26 +6739,29 @@
 
 case TemplateArgument::Declaration: {
   auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
-  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()));
+  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()),
+  Arg.getIsDefaulted());
 }
 
 case TemplateArgument::NullPtr:
   return TemplateArgument(getCanonicalType(Arg.getNullPtrType()),
-  /*isNullPtr*/true);
+  /*isNullPtr*/ true, Arg.getIsDefaulted());
 
 case TemplateArgument::Template:
-  return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()));
+  return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()),
+  Arg.getIsDefaulted());
 
 case TemplateArgument::TemplateExpansion:
-  return TemplateArgument(getCanonicalTemplateName(
- Arg.getAsTemplateOrTemplatePattern()),
-  Arg.getNumTemplateExpansions());
+  return TemplateArgument(
+  getCanonicalTemplateName(Arg.getAsTemplateOrTemplatePattern()),
+  Arg.getNumTemplateExpansions(), Arg.getIsDefaulted());
 
 case TemplateArgument::Integral:
   return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType()));
 
 case TemplateArgument::Type:
-  return TemplateArgument(getCanonicalType(Arg.getAsType()));
+  return TemplateArgument(getCanonicalType(Arg.getAsType()),
+  /*

[PATCH] D142632: [clang][TypePrinter] Support expression template arguments when checking defaultedness

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: erichkeane, aaron.ballman, aprantl, dblaikie.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds support for `TemplateArgument`s of kind
`TemplateArgument::Expression` to `clang::isSubstitutedDefaultArgument`.
We do so by evaluating both the `Pattern` and `Arg` expression to an
`APInt`, if we can, and comparing the results.

This will be useful in an upcoming change where
`clang::isSubstitutedDefaultArgument` gets called from `clang::Sema`
where the `TemplateArgument`s are instantiated as expressions (without
being evaluted to `APInt` beforehand).

**Testing**

- Added unit-tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142632

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -127,3 +127,131 @@
 Policy.EntireContentsOfLargeArray = true;
   }));
 }
+
+TEST(TypePrinter, TemplateArgumentsSubstitution_Expressions) {
+  /// Tests clang::isSubstitutedDefaultArgument on TemplateArguments
+  /// that are of kind TemplateArgument::Expression
+  constexpr char Code[] = R"cpp(
+constexpr bool func() { return true; }
+
+template 
+struct Foo {
+};
+
+Foo X;
+  )cpp";
+
+  auto AST = tooling::buildASTFromCodeWithArgs(Code, /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTD = selectFirst(
+  "id", match(classTemplateDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTD, nullptr);
+  auto const *CTSD = *CTD->specializations().begin();
+  ASSERT_NE(CTSD, nullptr);
+  auto const *Params = CTD->getTemplateParameters();
+  ASSERT_NE(Params, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  auto createBinOpExpr = [&](uint32_t LHS, uint32_t RHS,
+ uint32_t Result) -> ConstantExpr * {
+const int numBits = 32;
+clang::APValue ResultVal{llvm::APSInt(llvm::APInt(numBits, Result))};
+auto *LHSInt = IntegerLiteral::Create(Ctx, llvm::APInt(numBits, LHS),
+  Ctx.UnsignedIntTy, {});
+auto *RHSInt = IntegerLiteral::Create(Ctx, llvm::APInt(numBits, RHS),
+  Ctx.UnsignedIntTy, {});
+auto *BinOp = BinaryOperator::Create(
+Ctx, LHSInt, RHSInt, BinaryOperatorKind::BO_Add, Ctx.UnsignedIntTy,
+ExprValueKind::VK_PRValue, ExprObjectKind::OK_Ordinary, {}, {});
+return ConstantExpr::Create(Ctx, dyn_cast(BinOp), ResultVal);
+  };
+
+  {
+// Arg is an integral '42'
+auto const &Arg = ArgList.get(1);
+ASSERT_EQ(Arg.getKind(), TemplateArgument::Integral);
+
+// Param has default expr which evaluates to '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_TRUE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+// Arg is an integral '41'
+llvm::APInt Int(32, 41);
+TemplateArgument Arg(Ctx, llvm::APSInt(Int), Ctx.UnsignedIntTy);
+
+// Param has default expr which evaluates to '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+// Arg is an integral '4'
+llvm::APInt Int(32, 4);
+TemplateArgument Arg(Ctx, llvm::APSInt(Int), Ctx.UnsignedIntTy);
+
+// Param has is value-dependent expression (i.e., sizeof(T))
+auto const *Param = Params->getParam(3);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+const int LHS = 40;
+const int RHS = 2;
+const int Result = 42;
+auto *ConstExpr = createBinOpExpr(LHS, RHS, Result);
+// Arg is instantiated with '40 + 2'
+TemplateArgument Arg(ConstExpr);
+
+// Param has default expr of '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_TRUE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+const int LHS = 40;
+const int RHS = 1;
+const int Result = 41;
+auto *ConstExpr = createBinOpExpr(LHS, RHS, Result);
+
+// Arg is instantiated with '40 + 1'
+TemplateArgument Arg(ConstExpr);
+
+// Param has default expr of '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+const int LHS = 4;
+const int RHS = 0;
+const int Result = 4;
+auto *ConstExpr = createBinOpExpr(LHS, RHS, Result);
+
+// Arg is instantiated with '4 + 0'
+TemplateAr

[PATCH] D140423: [WIP][clang] Add PrintingPolicy callback for identifying default template arguments

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
Michael137 abandoned this revision.
Michael137 added a comment.

Abandoning in favour of https://reviews.llvm.org/D141826


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140423

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


[PATCH] D142632: [clang][TypePrinter] Support expression template arguments when checking defaultedness

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/lib/AST/TypePrinter.cpp:2020
+  Expr const *pattern_expr = Pattern.getAsExpr();
+  pattern_expr->dump();
+  if (pattern_expr->isValueDependent() ||

erichkeane wrote:
> this left over from debugging?
Yes! Good catch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142632

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


[PATCH] D142632: [clang][TypePrinter] Support expression template arguments when checking defaultedness

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 492458.
Michael137 added a comment.

- Remove `dump()` leftover from debugging


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142632

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -127,3 +127,131 @@
 Policy.EntireContentsOfLargeArray = true;
   }));
 }
+
+TEST(TypePrinter, TemplateArgumentsSubstitution_Expressions) {
+  /// Tests clang::isSubstitutedDefaultArgument on TemplateArguments
+  /// that are of kind TemplateArgument::Expression
+  constexpr char Code[] = R"cpp(
+constexpr bool func() { return true; }
+
+template 
+struct Foo {
+};
+
+Foo X;
+  )cpp";
+
+  auto AST = tooling::buildASTFromCodeWithArgs(Code, /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTD = selectFirst(
+  "id", match(classTemplateDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTD, nullptr);
+  auto const *CTSD = *CTD->specializations().begin();
+  ASSERT_NE(CTSD, nullptr);
+  auto const *Params = CTD->getTemplateParameters();
+  ASSERT_NE(Params, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  auto createBinOpExpr = [&](uint32_t LHS, uint32_t RHS,
+ uint32_t Result) -> ConstantExpr * {
+const int numBits = 32;
+clang::APValue ResultVal{llvm::APSInt(llvm::APInt(numBits, Result))};
+auto *LHSInt = IntegerLiteral::Create(Ctx, llvm::APInt(numBits, LHS),
+  Ctx.UnsignedIntTy, {});
+auto *RHSInt = IntegerLiteral::Create(Ctx, llvm::APInt(numBits, RHS),
+  Ctx.UnsignedIntTy, {});
+auto *BinOp = BinaryOperator::Create(
+Ctx, LHSInt, RHSInt, BinaryOperatorKind::BO_Add, Ctx.UnsignedIntTy,
+ExprValueKind::VK_PRValue, ExprObjectKind::OK_Ordinary, {}, {});
+return ConstantExpr::Create(Ctx, dyn_cast(BinOp), ResultVal);
+  };
+
+  {
+// Arg is an integral '42'
+auto const &Arg = ArgList.get(1);
+ASSERT_EQ(Arg.getKind(), TemplateArgument::Integral);
+
+// Param has default expr which evaluates to '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_TRUE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+// Arg is an integral '41'
+llvm::APInt Int(32, 41);
+TemplateArgument Arg(Ctx, llvm::APSInt(Int), Ctx.UnsignedIntTy);
+
+// Param has default expr which evaluates to '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+// Arg is an integral '4'
+llvm::APInt Int(32, 4);
+TemplateArgument Arg(Ctx, llvm::APSInt(Int), Ctx.UnsignedIntTy);
+
+// Param has is value-dependent expression (i.e., sizeof(T))
+auto const *Param = Params->getParam(3);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+const int LHS = 40;
+const int RHS = 2;
+const int Result = 42;
+auto *ConstExpr = createBinOpExpr(LHS, RHS, Result);
+// Arg is instantiated with '40 + 2'
+TemplateArgument Arg(ConstExpr);
+
+// Param has default expr of '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_TRUE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+const int LHS = 40;
+const int RHS = 1;
+const int Result = 41;
+auto *ConstExpr = createBinOpExpr(LHS, RHS, Result);
+
+// Arg is instantiated with '40 + 1'
+TemplateArgument Arg(ConstExpr);
+
+// Param has default expr of '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+const int LHS = 4;
+const int RHS = 0;
+const int Result = 4;
+auto *ConstExpr = createBinOpExpr(LHS, RHS, Result);
+
+// Arg is instantiated with '4 + 0'
+TemplateArgument Arg(ConstExpr);
+
+// Param has is value-dependent expression (i.e., sizeof(T))
+auto const *Param = Params->getParam(3);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+}
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -2007,6 +2007,36 @@
   return false;
 }
 
+/// Evaluates the expression template argument 'Pattern' and returns true
+/// if 'Arg

[PATCH] D142632: [clang][TypePrinter] Support expression template arguments when checking defaultedness

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/lib/AST/TypePrinter.cpp:2031
+if (args_expr->isValueDependent() || 
!args_expr->isIntegerConstantExpr(Ctx))
+  return false;
+

aprantl wrote:
> Just for my own education: what's an example for a value-dependent constant 
> integer expression?
There is no such case, we're checking it here because it's a pre-condition for 
`isIntegerConstantExpr`. But we can have value-dependent expressions here like 
`sizeof(T)` we so can't unconditionally call `isIntegerConstantExpr`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142632

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


[PATCH] D142632: [clang][TypePrinter] Support expression template arguments when checking defaultedness

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/lib/AST/TypePrinter.cpp:2019
+  // Can't evaluate value-dependent expressions so bail early
+  Expr const *pattern_expr = Pattern.getAsExpr();
+  if (pattern_expr->isValueDependent() ||

aprantl wrote:
> I assume you checked that this is always non-null?
I didn't add a null-check because no other caller around clang does it 
(including `isSubstitutedTemplateArgument` which precedes this call here). So 
we've already been doing this on top-of-tree for a while in this codepath. But 
may be worth a followup audit. Though I suspect the assumption is that we never 
construct `TemplateArgument`s with `nullptr` `Expr`s. @erichkeane may know some 
more about this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142632

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


[PATCH] D142632: [clang][TypePrinter] Support expression template arguments when checking defaultedness

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG798494ed4f11: [clang][TypePrinter] Support expression 
template arguments when checking… (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142632

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -127,3 +127,131 @@
 Policy.EntireContentsOfLargeArray = true;
   }));
 }
+
+TEST(TypePrinter, TemplateArgumentsSubstitution_Expressions) {
+  /// Tests clang::isSubstitutedDefaultArgument on TemplateArguments
+  /// that are of kind TemplateArgument::Expression
+  constexpr char Code[] = R"cpp(
+constexpr bool func() { return true; }
+
+template 
+struct Foo {
+};
+
+Foo X;
+  )cpp";
+
+  auto AST = tooling::buildASTFromCodeWithArgs(Code, /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTD = selectFirst(
+  "id", match(classTemplateDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTD, nullptr);
+  auto const *CTSD = *CTD->specializations().begin();
+  ASSERT_NE(CTSD, nullptr);
+  auto const *Params = CTD->getTemplateParameters();
+  ASSERT_NE(Params, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  auto createBinOpExpr = [&](uint32_t LHS, uint32_t RHS,
+ uint32_t Result) -> ConstantExpr * {
+const int numBits = 32;
+clang::APValue ResultVal{llvm::APSInt(llvm::APInt(numBits, Result))};
+auto *LHSInt = IntegerLiteral::Create(Ctx, llvm::APInt(numBits, LHS),
+  Ctx.UnsignedIntTy, {});
+auto *RHSInt = IntegerLiteral::Create(Ctx, llvm::APInt(numBits, RHS),
+  Ctx.UnsignedIntTy, {});
+auto *BinOp = BinaryOperator::Create(
+Ctx, LHSInt, RHSInt, BinaryOperatorKind::BO_Add, Ctx.UnsignedIntTy,
+ExprValueKind::VK_PRValue, ExprObjectKind::OK_Ordinary, {}, {});
+return ConstantExpr::Create(Ctx, dyn_cast(BinOp), ResultVal);
+  };
+
+  {
+// Arg is an integral '42'
+auto const &Arg = ArgList.get(1);
+ASSERT_EQ(Arg.getKind(), TemplateArgument::Integral);
+
+// Param has default expr which evaluates to '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_TRUE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+// Arg is an integral '41'
+llvm::APInt Int(32, 41);
+TemplateArgument Arg(Ctx, llvm::APSInt(Int), Ctx.UnsignedIntTy);
+
+// Param has default expr which evaluates to '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+// Arg is an integral '4'
+llvm::APInt Int(32, 4);
+TemplateArgument Arg(Ctx, llvm::APSInt(Int), Ctx.UnsignedIntTy);
+
+// Param has is value-dependent expression (i.e., sizeof(T))
+auto const *Param = Params->getParam(3);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+const int LHS = 40;
+const int RHS = 2;
+const int Result = 42;
+auto *ConstExpr = createBinOpExpr(LHS, RHS, Result);
+// Arg is instantiated with '40 + 2'
+TemplateArgument Arg(ConstExpr);
+
+// Param has default expr of '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_TRUE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+const int LHS = 40;
+const int RHS = 1;
+const int Result = 41;
+auto *ConstExpr = createBinOpExpr(LHS, RHS, Result);
+
+// Arg is instantiated with '40 + 1'
+TemplateArgument Arg(ConstExpr);
+
+// Param has default expr of '42'
+auto const *Param = Params->getParam(1);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+
+  {
+const int LHS = 4;
+const int RHS = 0;
+const int Result = 4;
+auto *ConstExpr = createBinOpExpr(LHS, RHS, Result);
+
+// Arg is instantiated with '4 + 0'
+TemplateArgument Arg(ConstExpr);
+
+// Param has is value-dependent expression (i.e., sizeof(T))
+auto const *Param = Params->getParam(3);
+
+EXPECT_FALSE(clang::isSubstitutedDefaultArgument(
+Ctx, Arg, Param, ArgList.asArray(), Params->getDepth()));
+  }
+}
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypeP

[PATCH] D141826: [clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8b4279b66fc2: [clang][TemplateBase] Add IsDefaulted bit to 
TemplateArgument (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

Files:
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -490,3 +490,34 @@
   ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
   EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
 }
+
+TEST(Decl, TemplateArgumentDefaulted) {
+  llvm::Annotations Code(R"cpp(
+template
+struct Alloc {};
+
+template >
+struct Foo {
+};
+
+Foo> X;
+  )cpp");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  EXPECT_FALSE(ArgList.get(0).getIsDefaulted());
+  EXPECT_FALSE(ArgList.get(1).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(2).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(3).getIsDefaulted());
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5897,6 +5897,11 @@
 CTAK_Specified))
 return true;
 
+  CanonicalConverted.back().setIsDefaulted(
+  clang::isSubstitutedDefaultArgument(
+  Context, NewArgs[ArgIdx].getArgument(), *Param,
+  CanonicalConverted, Params->getDepth()));
+
   bool PackExpansionIntoNonPack =
   NewArgs[ArgIdx].getArgument().isPackExpansion() &&
   (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param));
@@ -6072,6 +6077,8 @@
   CTAK_Specified))
   return true;
 
+CanonicalConverted.back().setIsDefaulted(true);
+
 // Core issue 150 (assumed resolution): if this is a template template
 // parameter, keep track of the default template arguments from the
 // template definition.
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -161,8 +161,9 @@
 //===--===//
 
 TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
-   QualType Type) {
+   QualType Type, bool IsDefaulted) {
   Integer.Kind = Integral;
+  Integer.IsDefaulted = IsDefaulted;
   // Copy the APSInt value into our decomposed form.
   Integer.BitWidth = Value.getBitWidth();
   Integer.IsUnsigned = Value.isUnsigned();
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6821,26 +6821,29 @@
 
 case TemplateArgument::Declaration: {
   auto *D = cast(Arg.getAsDecl()->getCanonicalDecl());
-  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()));
+  return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()),
+  Arg.getIsDefaulted());
 }
 
 case TemplateArgument::NullPtr:
   return TemplateArgument(getCanonicalType(Arg.getNullPtrType()),
-  /*isNullPtr*/true);
+  /*isNullPtr*/ true, Arg.getIsDefaulted());
 
 case TemplateArgument::Template:
-  return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()));
+  return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()),
+  Arg.getIsDefaulted());
 
 case TemplateArgument::TemplateExpansion:
-  return TemplateArgument(getCanonicalTemplateName(
- Arg.getAsTemplateOrTemplatePattern()),
-  Arg.getNumTemplateExpansions());
+  return TemplateArgument(
+  getCanonicalTemplateName(Arg.getAsTemplateOrTemplatePattern()),
+  Arg.getNumTemplateExpansions(), Arg.getIsDefaulted());
 
 case TemplateArgument::Integral:
   return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType()));
 
 case TemplateArgument::Type:
-  return TemplateArgument(getCa

[PATCH] D142333: [clang][DebugInfo] Check TemplateArgument::IsDefaulted

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG29ecf0e62cd7: [clang][DebugInfo] Check 
TemplateArgument::IsDefaulted (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142333

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2010,15 +2010,10 @@
   for (unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
 const TemplateArgument &TA = Args.Args[i];
 StringRef Name;
-bool defaultParameter = false;
-if (Args.TList) {
+const bool defaultParameter = TA.getIsDefaulted();
+if (Args.TList)
   Name = Args.TList->getParam(i)->getName();
 
-  NamedDecl const *ND = Args.TList->getParam(i);
-  defaultParameter = clang::isSubstitutedDefaultArgument(
-  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
-}
-
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2010,15 +2010,10 @@
   for (unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
 const TemplateArgument &TA = Args.Args[i];
 StringRef Name;
-bool defaultParameter = false;
-if (Args.TList) {
+const bool defaultParameter = TA.getIsDefaulted();
+if (Args.TList)
   Name = Args.TList->getParam(i)->getName();
 
-  NamedDecl const *ND = Args.TList->getParam(i);
-  defaultParameter = clang::isSubstitutedDefaultArgument(
-  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
-}
-
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141827: [clang][TypePrinter] Test TemplateArgument::IsDefaulted when omitting default arguments

2023-01-26 Thread Michael Buch via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3d7dcec5db2f: [clang][TypePrinter] Test 
TemplateArgument::IsDefaulted when omitting default… (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141827

Files:
  clang/lib/AST/TypePrinter.cpp


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -2109,14 +2109,10 @@
   if (TPL && Policy.SuppressDefaultTemplateArgs &&
   !Policy.PrintCanonicalTypes && !Args.empty() && !IsPack &&
   Args.size() <= TPL->size()) {
-ASTContext &Ctx = TPL->getParam(0)->getASTContext();
 llvm::SmallVector OrigArgs;
 for (const TA &A : Args)
   OrigArgs.push_back(getArgument(A));
-while (!Args.empty() &&
-   isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()),
-TPL->getParam(Args.size() - 1),
-OrigArgs, TPL->getDepth()))
+while (!Args.empty() && getArgument(Args.back()).getIsDefaulted())
   Args = Args.drop_back();
   }
 


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -2109,14 +2109,10 @@
   if (TPL && Policy.SuppressDefaultTemplateArgs &&
   !Policy.PrintCanonicalTypes && !Args.empty() && !IsPack &&
   Args.size() <= TPL->size()) {
-ASTContext &Ctx = TPL->getParam(0)->getASTContext();
 llvm::SmallVector OrigArgs;
 for (const TA &A : Args)
   OrigArgs.push_back(getArgument(A));
-while (!Args.empty() &&
-   isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()),
-TPL->getParam(Args.size() - 1),
-OrigArgs, TPL->getDepth()))
+while (!Args.empty() && getArgument(Args.back()).getIsDefaulted())
   Args = Args.drop_back();
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141827: [clang][TypePrinter] Test TemplateArgument::IsDefaulted when omitting default arguments

2023-01-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

This caused some LLDB test failures for the `import-std-module` setting.  
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/

We construct `TemplateArgument`s manually in the `CxxModuleHandler`. Fix is 
in-flight.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141827

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


[PATCH] D142713: [clang][ASTImporter] Propagate TemplateArgument::IsDefaulted during import

2023-01-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: martong, aprantl.
Herald added a subscriber: rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With https://reviews.llvm.org/D141826 `TemplateArgument`s have an
additional field that indicates their defaulted-ness. This gets
used during debug-info generation and in the `clang::TypePrinter`.

This patch copies the field during the import process so consumers
of the ASTImporter can benefit from the other Clang components that
read the field.

**Testing**

- Added unit-test
- Checked that this fixes (in addition to a follow-up LLDB patch) fix current 
test failures in LLDB


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142713

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1158,6 +1158,25 @@
   ASSERT_EQ(cast(ToArg)->getValue().getLimitedValue(), 1U);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateArgumentsDefaulted) {
+  Decl *FromTU = getTuDecl(R"(
+   template struct X {};
+   template typename TT = X> struct 
S {};
+   S<> s;
+   )", Lang_CXX17);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("S")));
+  ASSERT_TRUE(FromSpec);
+  auto *ToSpec = Import(FromSpec, Lang_CXX03);
+  ASSERT_TRUE(ToSpec);
+  auto const& TList = ToSpec->getTemplateArgs();
+  for (auto const& Arg : TList.asArray()) {
+ASSERT_TRUE(Arg.getIsDefaulted());
+  }
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportOfTemplatedDeclOfClassTemplateDecl) {
   Decl *FromTU = getTuDecl("template struct S{};", Lang_CXX03);
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -836,7 +836,7 @@
 ExpectedType ToTypeOrErr = import(From.getAsType());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToTypeOrErr);
+return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/false, 
From.getIsDefaulted());
   }
 
   case TemplateArgument::Integral: {
@@ -853,14 +853,14 @@
 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToOrErr, *ToTypeOrErr);
+return TemplateArgument(*ToOrErr, *ToTypeOrErr, From.getIsDefaulted());
   }
 
   case TemplateArgument::NullPtr: {
 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true);
+return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true, 
From.getIsDefaulted());
   }
 
   case TemplateArgument::Template: {
@@ -868,7 +868,7 @@
 if (!ToTemplateOrErr)
   return ToTemplateOrErr.takeError();
 
-return TemplateArgument(*ToTemplateOrErr);
+return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
   }
 
   case TemplateArgument::TemplateExpansion: {
@@ -878,12 +878,12 @@
   return ToTemplateOrErr.takeError();
 
 return TemplateArgument(
-*ToTemplateOrErr, From.getNumTemplateExpansions());
+*ToTemplateOrErr, From.getNumTemplateExpansions(), 
From.getIsDefaulted());
   }
 
   case TemplateArgument::Expression:
 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
-  return TemplateArgument(*ToExpr);
+  return TemplateArgument(*ToExpr, From.getIsDefaulted());
 else
   return ToExpr.takeError();
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1158,6 +1158,25 @@
   ASSERT_EQ(cast(ToArg)->getValue().getLimitedValue(), 1U);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateArgumentsDefaulted) {
+  Decl *FromTU = getTuDecl(R"(
+   template struct X {};
+   template typename TT = X> struct S {};
+   S<> s;
+   )", Lang_CXX17);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("S")));
+  ASSERT_TRUE(FromSpec);
+  auto *ToSpec = Import(FromSpec, Lang_CXX03);
+  ASSERT_TRUE(ToSpec);
+  auto const& TList = ToSpec->getTemplateArgs();
+  for (auto const& Arg : TList.asArray()) {
+ASSERT_TRUE(Arg.getIsDefaulted());
+  }
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportOfTemplatedDeclO

[PATCH] D142713: [clang][ASTImporter] Propagate TemplateArgument::IsDefaulted during import

2023-01-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 492728.
Michael137 added a comment.

- clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142713

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1158,6 +1158,26 @@
   ASSERT_EQ(cast(ToArg)->getValue().getLimitedValue(), 1U);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateArgumentsDefaulted) {
+  Decl *FromTU = getTuDecl(R"(
+   template struct X {};
+   template typename TT = X> struct 
S {};
+   S<> s;
+   )",
+   Lang_CXX17);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("S")));
+  ASSERT_TRUE(FromSpec);
+  auto *ToSpec = Import(FromSpec, Lang_CXX03);
+  ASSERT_TRUE(ToSpec);
+  auto const &TList = ToSpec->getTemplateArgs();
+  for (auto const &Arg : TList.asArray()) {
+ASSERT_TRUE(Arg.getIsDefaulted());
+  }
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportOfTemplatedDeclOfClassTemplateDecl) {
   Decl *FromTU = getTuDecl("template struct S{};", Lang_CXX03);
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -836,7 +836,8 @@
 ExpectedType ToTypeOrErr = import(From.getAsType());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToTypeOrErr);
+return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
+From.getIsDefaulted());
   }
 
   case TemplateArgument::Integral: {
@@ -853,14 +854,15 @@
 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToOrErr, *ToTypeOrErr);
+return TemplateArgument(*ToOrErr, *ToTypeOrErr, From.getIsDefaulted());
   }
 
   case TemplateArgument::NullPtr: {
 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true);
+return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
+From.getIsDefaulted());
   }
 
   case TemplateArgument::Template: {
@@ -868,7 +870,7 @@
 if (!ToTemplateOrErr)
   return ToTemplateOrErr.takeError();
 
-return TemplateArgument(*ToTemplateOrErr);
+return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
   }
 
   case TemplateArgument::TemplateExpansion: {
@@ -877,13 +879,13 @@
 if (!ToTemplateOrErr)
   return ToTemplateOrErr.takeError();
 
-return TemplateArgument(
-*ToTemplateOrErr, From.getNumTemplateExpansions());
+return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
+From.getIsDefaulted());
   }
 
   case TemplateArgument::Expression:
 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
-  return TemplateArgument(*ToExpr);
+  return TemplateArgument(*ToExpr, From.getIsDefaulted());
 else
   return ToExpr.takeError();
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1158,6 +1158,26 @@
   ASSERT_EQ(cast(ToArg)->getValue().getLimitedValue(), 1U);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateArgumentsDefaulted) {
+  Decl *FromTU = getTuDecl(R"(
+   template struct X {};
+   template typename TT = X> struct S {};
+   S<> s;
+   )",
+   Lang_CXX17);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("S")));
+  ASSERT_TRUE(FromSpec);
+  auto *ToSpec = Import(FromSpec, Lang_CXX03);
+  ASSERT_TRUE(ToSpec);
+  auto const &TList = ToSpec->getTemplateArgs();
+  for (auto const &Arg : TList.asArray()) {
+ASSERT_TRUE(Arg.getIsDefaulted());
+  }
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportOfTemplatedDeclOfClassTemplateDecl) {
   Decl *FromTU = getTuDecl("template struct S{};", Lang_CXX03);
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -836,7 +836,8 @@
 ExpectedType ToTypeOrErr = import(From.getAsType());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToTypeOrErr);
+return TemplateAr

[PATCH] D142713: [clang][ASTImporter] Propagate TemplateArgument::IsDefaulted during import

2023-01-27 Thread Michael Buch via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd194d817b0b2: [clang][ASTImporter] Propagate 
TemplateArgument::IsDefaulted during import (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142713

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1158,6 +1158,26 @@
   ASSERT_EQ(cast(ToArg)->getValue().getLimitedValue(), 1U);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateArgumentsDefaulted) {
+  Decl *FromTU = getTuDecl(R"(
+   template struct X {};
+   template typename TT = X> struct 
S {};
+   S<> s;
+   )",
+   Lang_CXX17);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("S")));
+  ASSERT_TRUE(FromSpec);
+  auto *ToSpec = Import(FromSpec, Lang_CXX03);
+  ASSERT_TRUE(ToSpec);
+  auto const &TList = ToSpec->getTemplateArgs();
+  for (auto const &Arg : TList.asArray()) {
+ASSERT_TRUE(Arg.getIsDefaulted());
+  }
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportOfTemplatedDeclOfClassTemplateDecl) {
   Decl *FromTU = getTuDecl("template struct S{};", Lang_CXX03);
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -836,7 +836,8 @@
 ExpectedType ToTypeOrErr = import(From.getAsType());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToTypeOrErr);
+return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
+From.getIsDefaulted());
   }
 
   case TemplateArgument::Integral: {
@@ -853,14 +854,15 @@
 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToOrErr, *ToTypeOrErr);
+return TemplateArgument(*ToOrErr, *ToTypeOrErr, From.getIsDefaulted());
   }
 
   case TemplateArgument::NullPtr: {
 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
 if (!ToTypeOrErr)
   return ToTypeOrErr.takeError();
-return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true);
+return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
+From.getIsDefaulted());
   }
 
   case TemplateArgument::Template: {
@@ -868,7 +870,7 @@
 if (!ToTemplateOrErr)
   return ToTemplateOrErr.takeError();
 
-return TemplateArgument(*ToTemplateOrErr);
+return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
   }
 
   case TemplateArgument::TemplateExpansion: {
@@ -877,13 +879,13 @@
 if (!ToTemplateOrErr)
   return ToTemplateOrErr.takeError();
 
-return TemplateArgument(
-*ToTemplateOrErr, From.getNumTemplateExpansions());
+return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
+From.getIsDefaulted());
   }
 
   case TemplateArgument::Expression:
 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
-  return TemplateArgument(*ToExpr);
+  return TemplateArgument(*ToExpr, From.getIsDefaulted());
 else
   return ToExpr.takeError();
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1158,6 +1158,26 @@
   ASSERT_EQ(cast(ToArg)->getValue().getLimitedValue(), 1U);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateArgumentsDefaulted) {
+  Decl *FromTU = getTuDecl(R"(
+   template struct X {};
+   template typename TT = X> struct S {};
+   S<> s;
+   )",
+   Lang_CXX17);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("S")));
+  ASSERT_TRUE(FromSpec);
+  auto *ToSpec = Import(FromSpec, Lang_CXX03);
+  ASSERT_TRUE(ToSpec);
+  auto const &TList = ToSpec->getTemplateArgs();
+  for (auto const &Arg : TList.asArray()) {
+ASSERT_TRUE(Arg.getIsDefaulted());
+  }
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportOfTemplatedDeclOfClassTemplateDecl) {
   Decl *FromTU = getTuDecl("template struct S{};", Lang_CXX03);
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -836,7 +836,8 @@
 ExpectedTy

[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-02-05 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

From a first glance looks ok but ideally the clang changes would be a separate 
review. Particularly the ASTImporter change could use a unittest


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D141826: [WIP][clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: erichkeane, aaron.ballman, dblaikie.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

**Summary**

This patch adds a `IsDefaulted` field to `clang::TemplateArgument`.

To prevent memory footprint increase we still 1 bit from `ArgKind`.

**Background**

In LLDB we construct ASTs from debug-info and hand it to clang
to perform actions such as printing/formatting a typenames.
Some debug formats, specifically DWARF, may only encode information
about class template instantiations, losing the structure of the generic
class definition. However, the `clang::TypePrinter` needs a properly
constructed `ClassTemplateDecl` with generic default argument decls
to be able to deduce whether a `ClassTemplateSpecializationDecl` was
instantiatiated with `TemplateArgument`s that correspond to the
defaults. LLDB does know whether a particular template argument was
defaulted, but can't currently tell clang about it.

This patch allows LLDB to set the defaulted-ness of a `TemplateArgument`
and thus benefit more from `clang::TypePrinter`.

See discussion in https://reviews.llvm.org/D140423

**Testing**

- TODO


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141826

Files:
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/TemplateBase.cpp

Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -162,6 +162,7 @@
 TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
QualType Type) {
   Integer.Kind = Integral;
+  Integer.IsDefaulted = false;
   // Copy the APSInt value into our decomposed form.
   Integer.BitWidth = Value.getBitWidth();
   Integer.IsUnsigned = Value.isUnsigned();
Index: clang/include/clang/AST/TemplateBase.h
===
--- clang/include/clang/AST/TemplateBase.h
+++ clang/include/clang/AST/TemplateBase.h
@@ -103,12 +103,14 @@
   /// The kind of template argument we're storing.
 
   struct DA {
-unsigned Kind;
+unsigned Kind : 31;
+unsigned IsDefaulted : 1;
 void *QT;
 ValueDecl *D;
   };
   struct I {
-unsigned Kind;
+unsigned Kind : 31;
+unsigned IsDefaulted : 1;
 // We store a decomposed APSInt with the data allocated by ASTContext if
 // BitWidth > 64. The memory may be shared between multiple
 // TemplateArgument instances.
@@ -124,17 +126,20 @@
 void *Type;
   };
   struct A {
-unsigned Kind;
+unsigned Kind : 31;
+unsigned IsDefaulted : 1;
 unsigned NumArgs;
 const TemplateArgument *Args;
   };
   struct TA {
-unsigned Kind;
+unsigned Kind : 31;
+unsigned IsDefaulted : 1;
 unsigned NumExpansions;
 void *Name;
   };
   struct TV {
-unsigned Kind;
+unsigned Kind : 31;
+unsigned IsDefaulted : 1;
 uintptr_t V;
   };
   union {
@@ -147,11 +152,12 @@
 
 public:
   /// Construct an empty, invalid template argument.
-  constexpr TemplateArgument() : TypeOrValue({Null, 0}) {}
+  constexpr TemplateArgument() : TypeOrValue({Null, /* IsDefaulted */ 0, 0}) {}
 
   /// Construct a template type argument.
   TemplateArgument(QualType T, bool isNullPtr = false) {
 TypeOrValue.Kind = isNullPtr ? NullPtr : Type;
+TypeOrValue.IsDefaulted = false;
 TypeOrValue.V = reinterpret_cast(T.getAsOpaquePtr());
   }
 
@@ -161,6 +167,7 @@
   TemplateArgument(ValueDecl *D, QualType QT) {
 assert(D && "Expected decl");
 DeclArg.Kind = Declaration;
+DeclArg.IsDefaulted = false;
 DeclArg.QT = QT.getAsOpaquePtr();
 DeclArg.D = D;
   }
@@ -186,6 +193,7 @@
   /// \param Name The template name.
   TemplateArgument(TemplateName Name) {
 TemplateArg.Kind = Template;
+TemplateArg.IsDefaulted = false;
 TemplateArg.Name = Name.getAsVoidPointer();
 TemplateArg.NumExpansions = 0;
   }
@@ -203,6 +211,7 @@
   /// instantiating
   TemplateArgument(TemplateName Name, Optional NumExpansions) {
 TemplateArg.Kind = TemplateExpansion;
+TemplateArg.IsDefaulted = false;
 TemplateArg.Name = Name.getAsVoidPointer();
 if (NumExpansions)
   TemplateArg.NumExpansions = *NumExpansions + 1;
@@ -217,6 +226,7 @@
   /// occur in a non-dependent, canonical template argument list.
   TemplateArgument(Expr *E) {
 TypeOrValue.Kind = Expression;
+TypeOrValue.IsDefaulted = false;
 TypeOrValue.V = reinterpret_cast(E);
   }
 
@@ -226,6 +236,7 @@
   /// outlives the TemplateArgument itself.
   explicit TemplateArgument(ArrayRef Args) {
 this->Args.Kind = Pack;
+this->Args.IsDefaulted = false;
 this->Args.Args = Args.data();
 this->Args.NumArgs = Args.size();
   }
@@ -334,6 +345,10 @@
 Integer.Type = T.getAsOpaquePtr();
   }
 
+  void setIsDefaulted(bool v) { TypeOrVa

[PATCH] D141827: [WIP][clang][TypePrinter] Test TemplateArgument::IsDefaulted when omitting default arguments

2023-01-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: erichkeane, aaron.ballman, dblaikie.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

**Summary**

This patch allows clients who can't properly construct
a `ClassTemplateDecl` to still benefit from the `clang::TypePrinter`s
ability to skip printing defaulted template arguments. The
clients simply have to call `TemplateArgument::setIsDefaulted`
in advance.

See discussion in https://reviews.llvm.org/D140423

**Testing**

- TODO


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141827

Files:
  clang/lib/AST/TypePrinter.cpp


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -2090,11 +2090,19 @@
 llvm::SmallVector OrigArgs;
 for (const TA &A : Args)
   OrigArgs.push_back(getArgument(A));
-while (!Args.empty() &&
-   isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()),
-TPL->getParam(Args.size() - 1),
-OrigArgs, TPL->getDepth()))
+while (!Args.empty()) {
+  const auto &CurrArg = getArgument(Args.back());
+
+  const bool IsDefaulted = CurrArg.getIsDefaulted() ||
+   isSubstitutedDefaultArgument(
+   Ctx, CurrArg, TPL->getParam(Args.size() - 
1),
+   OrigArgs, TPL->getDepth());
+
+  if (!IsDefaulted)
+break;
+
   Args = Args.drop_back();
+}
   }
 
   const char *Comma = Policy.MSVCFormatting ? "," : ", ";


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -2090,11 +2090,19 @@
 llvm::SmallVector OrigArgs;
 for (const TA &A : Args)
   OrigArgs.push_back(getArgument(A));
-while (!Args.empty() &&
-   isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()),
-TPL->getParam(Args.size() - 1),
-OrigArgs, TPL->getDepth()))
+while (!Args.empty()) {
+  const auto &CurrArg = getArgument(Args.back());
+
+  const bool IsDefaulted = CurrArg.getIsDefaulted() ||
+   isSubstitutedDefaultArgument(
+   Ctx, CurrArg, TPL->getParam(Args.size() - 1),
+   OrigArgs, TPL->getDepth());
+
+  if (!IsDefaulted)
+break;
+
   Args = Args.drop_back();
+}
   }
 
   const char *Comma = Policy.MSVCFormatting ? "," : ", ";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140423: [WIP][clang] Add PrintingPolicy callback for identifying default template arguments

2023-01-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D140423#4052442 , @aaron.ballman 
wrote:

> In D140423#4052271 , @dblaikie 
> wrote:
>
>> In D140423#4051262 , 
>> @aaron.ballman wrote:
>>
 Add something like a bool IsDefaulted somewhere in Clang, e.g., in 
 TemplateArgument and consult it from the TypePrinter. This would be much 
 simpler but requires adding a field on one of the Clang types
>>>
>>> I think this might be worth exploring as a cleaner solution to the problem. 
>>> `TemplateArgument` has a union of structures for the various kinds of 
>>> template arguments it represents 
>>> (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/TemplateBase.h#L140).
>>>  All of the structures in that union start with an `unsigned Kind` field to 
>>> discriminate between the members. There are only 8 kinds currently 
>>> (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/TemplateBase.h#L63),
>>>  so we could turn `Kind` into a bit-field and then steal a bit for 
>>> `IsDefaulted` without increasing memory overhead. Do you think that's a 
>>> reasonable approach to try instead?
>>
>> FWIW, I Think I discouraged @Michael137 from going down that direction since 
>> it felt weird to me to add that sort of thing to the Clang ASTs for an 
>> lldb-only use case, and a callback seemed more suitable. But this is hardly 
>> my wheelhouse - if you reckon that's the better direction, carry on, I 
>> expect @Michael137 will be on board with that.
>
> Adding in @erichkeane as templates code owner in case he has opinions.
>
> I agree it's a bit weird to modify the AST only for lldb only, but adding a 
> callback to the printing policy is basically an lldb-only change as well (I 
> don't imagine folks would use that callback all that often). So my thinking 
> is that if we can encode the information in the AST for effectively zero 
> cost, that helps every consumer of the AST (thinking about things like 
> clang-tidy) and not just people printing. However, this is not a strongly 
> held position, so if there's a preference for the current approach, it seems 
> workable to me.

Thanks for taking a look @aaron.ballman

I prepared an alternative draft patch series with your suggestion of adding an 
`IsDefaulted` bit to `TemplateArgument`:

- https://reviews.llvm.org/D141826
- https://reviews.llvm.org/D141827

Is this what you had in mind?

This *significantly* simplifies the LLDB support: 
https://reviews.llvm.org/D141828

So I'd prefer this over the callback approach TBH.

> A Class template instantiation SHOULD have its link back to the class 
> template, and should be able to calculate whether the template argument is 
> defaulted, right? At least if it is the SAME as the default (that is, I'm not 
> sure how well we can tell the difference between a defaulted arg, and a arg 
> set to the default value).
>
> I wouldn't expect a bool to be necessary, and I see 
> isSubstitutedDefaultArgument seems to do that work, right?

As @dblaikie mentioned, unfortunately LLDB currently isn't able to construct 
the `ClassTemplateDecl` in a way where this `isSubstitutedDefaultArgument` 
would correctly deduce whether a template instantiation has defaulted 
arguments. In DWARF we only have info about a template instantiation, but the 
structure of the generic template parameters is not encoded. So we can't supply 
`(Non)TypeTemplateParamDecl::setDefaultArgument` with the generic arguments 
Clang expects. The `ClassTemplateDecl` parameters are set up here: 
https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp#L1391-L1402

Regardless of how complex the template parameters get, LLDB just turns each 
into a plain `(Non)TypeTemplateParamDecl`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140423

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


[PATCH] D141826: [WIP][clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-17 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D141826#4058866 , @erichkeane 
wrote:

> This seems innocuous enough/easy enough to use.  I'd like a comment on the 
> functions at least and types in TemplateBase.h to specify that this is for 
> printing-policy only?  Alternatively (and perhaps MUCH more appreciated) 
> would be to make sure we mark the defaulted during AST generation as well.

I'll have a look at doing that

Are you suggesting we do the substitution check that the TypePrinter currently 
does when constructing the specialisation decls? So the TypePrinter simply 
needs to check the `TemplateArgument::getIsDefaulted`? I like the sound of that.

Unfortunately we'd still need the `setIsDefaulted` because of the DWARF 
limitation in LLDB


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

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


[PATCH] D142268: [clang][DebugInfo] Don't canonicalize names in template argument list for alias templates

2023-01-20 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: dblaikie, aprantl.
Herald added a subscriber: jeroen.dobbelaere.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

**Summary**

This patch customizes the `CGDebugInfo` printing policy to stop canonicalizing
the template arugment list in `DW_AT_name` for alias templates. The motivation 
for
this is that we want to be able to use the `TypePrinter`s support for
omitting defaulted template arguments when emitting `DW_AT_name`.

For reference, GCC currently completely omits the template arguments
when emitting alias template DIEs.

**Testing**

- Added unit-test


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142268

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-alias.cpp


Index: clang/test/CodeGenCXX/debug-info-alias.cpp
===
--- clang/test/CodeGenCXX/debug-info-alias.cpp
+++ clang/test/CodeGenCXX/debug-info-alias.cpp
@@ -3,6 +3,11 @@
 template
 struct foo {
 };
+
+template
+struct baz {
+};
+
 namespace x {
 // splitting these over multiple lines to make sure the right token is used for
 // the location
@@ -18,6 +23,9 @@
 // CHECK: !DIGlobalVariable(name: "bf",{{.*}} type: [[BFLOAT:![0-9]+]]
 // CHECK: [[BFLOAT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar"
 x::bar bf;
+// CHECK: !DIGlobalVariable(name: "bz",{{.*}} type: [[BBAZ:![0-9]+]]
+// CHECK: [[BBAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar >"
+x::bar> bz;
 
 using
 // CHECK: !DIGlobalVariable(name: "n",{{.*}} type: [[NARF:![0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1288,9 +1288,21 @@
 
   SmallString<128> NS;
   llvm::raw_svector_ostream OS(NS);
-  Ty->getTemplateName().print(OS, getPrintingPolicy(),
-  TemplateName::Qualified::None);
-  printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy());
+
+  auto PP = getPrintingPolicy();
+  Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
+
+  // Disable PrintCanonicalTypes here because we want
+  // the DW_AT_name to benefit from the TypePrinter's ability
+  // to skip defaulted template arguments.
+  //
+  // FIXME: Once -gsimple-template-names is enabled by default
+  // and we attach template parameters to alias template DIEs
+  // we don't need to worry about customizing the PrintingPolicy
+  // here anymore.
+  PP.PrintCanonicalTypes = false;
+  printTemplateArgumentList(OS, Ty->template_arguments(), PP,
+TD->getTemplateParameters());
 
   SourceLocation Loc = AliasDecl->getLocation();
   return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),


Index: clang/test/CodeGenCXX/debug-info-alias.cpp
===
--- clang/test/CodeGenCXX/debug-info-alias.cpp
+++ clang/test/CodeGenCXX/debug-info-alias.cpp
@@ -3,6 +3,11 @@
 template
 struct foo {
 };
+
+template
+struct baz {
+};
+
 namespace x {
 // splitting these over multiple lines to make sure the right token is used for
 // the location
@@ -18,6 +23,9 @@
 // CHECK: !DIGlobalVariable(name: "bf",{{.*}} type: [[BFLOAT:![0-9]+]]
 // CHECK: [[BFLOAT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar"
 x::bar bf;
+// CHECK: !DIGlobalVariable(name: "bz",{{.*}} type: [[BBAZ:![0-9]+]]
+// CHECK: [[BBAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar >"
+x::bar> bz;
 
 using
 // CHECK: !DIGlobalVariable(name: "n",{{.*}} type: [[NARF:![0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1288,9 +1288,21 @@
 
   SmallString<128> NS;
   llvm::raw_svector_ostream OS(NS);
-  Ty->getTemplateName().print(OS, getPrintingPolicy(),
-  TemplateName::Qualified::None);
-  printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy());
+
+  auto PP = getPrintingPolicy();
+  Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
+
+  // Disable PrintCanonicalTypes here because we want
+  // the DW_AT_name to benefit from the TypePrinter's ability
+  // to skip defaulted template arguments.
+  //
+  // FIXME: Once -gsimple-template-names is enabled by default
+  // and we attach template parameters to alias template DIEs
+  // we don't need to worry about customizing the PrintingPolicy
+  // here anymore.
+  PP.PrintCanonicalTypes = false;
+  printTemplateArgumentList(OS, Ty->template_arguments(), PP,
+TD->getTemplateParameters());
 
   SourceLocation Loc = AliasDecl->getLocation();
   return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
___

[PATCH] D142268: [clang][DebugInfo] Don't canonicalize names in template argument list for alias templates

2023-01-20 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 491015.
Michael137 added a comment.

- Update commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142268

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-alias.cpp


Index: clang/test/CodeGenCXX/debug-info-alias.cpp
===
--- clang/test/CodeGenCXX/debug-info-alias.cpp
+++ clang/test/CodeGenCXX/debug-info-alias.cpp
@@ -3,6 +3,11 @@
 template
 struct foo {
 };
+
+template
+struct baz {
+};
+
 namespace x {
 // splitting these over multiple lines to make sure the right token is used for
 // the location
@@ -18,6 +23,9 @@
 // CHECK: !DIGlobalVariable(name: "bf",{{.*}} type: [[BFLOAT:![0-9]+]]
 // CHECK: [[BFLOAT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar"
 x::bar bf;
+// CHECK: !DIGlobalVariable(name: "bz",{{.*}} type: [[BBAZ:![0-9]+]]
+// CHECK: [[BBAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar >"
+x::bar> bz;
 
 using
 // CHECK: !DIGlobalVariable(name: "n",{{.*}} type: [[NARF:![0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1288,9 +1288,21 @@
 
   SmallString<128> NS;
   llvm::raw_svector_ostream OS(NS);
-  Ty->getTemplateName().print(OS, getPrintingPolicy(),
-  TemplateName::Qualified::None);
-  printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy());
+
+  auto PP = getPrintingPolicy();
+  Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
+
+  // Disable PrintCanonicalTypes here because we want
+  // the DW_AT_name to benefit from the TypePrinter's ability
+  // to skip defaulted template arguments.
+  //
+  // FIXME: Once -gsimple-template-names is enabled by default
+  // and we attach template parameters to alias template DIEs
+  // we don't need to worry about customizing the PrintingPolicy
+  // here anymore.
+  PP.PrintCanonicalTypes = false;
+  printTemplateArgumentList(OS, Ty->template_arguments(), PP,
+TD->getTemplateParameters());
 
   SourceLocation Loc = AliasDecl->getLocation();
   return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),


Index: clang/test/CodeGenCXX/debug-info-alias.cpp
===
--- clang/test/CodeGenCXX/debug-info-alias.cpp
+++ clang/test/CodeGenCXX/debug-info-alias.cpp
@@ -3,6 +3,11 @@
 template
 struct foo {
 };
+
+template
+struct baz {
+};
+
 namespace x {
 // splitting these over multiple lines to make sure the right token is used for
 // the location
@@ -18,6 +23,9 @@
 // CHECK: !DIGlobalVariable(name: "bf",{{.*}} type: [[BFLOAT:![0-9]+]]
 // CHECK: [[BFLOAT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar"
 x::bar bf;
+// CHECK: !DIGlobalVariable(name: "bz",{{.*}} type: [[BBAZ:![0-9]+]]
+// CHECK: [[BBAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar >"
+x::bar> bz;
 
 using
 // CHECK: !DIGlobalVariable(name: "n",{{.*}} type: [[NARF:![0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1288,9 +1288,21 @@
 
   SmallString<128> NS;
   llvm::raw_svector_ostream OS(NS);
-  Ty->getTemplateName().print(OS, getPrintingPolicy(),
-  TemplateName::Qualified::None);
-  printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy());
+
+  auto PP = getPrintingPolicy();
+  Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
+
+  // Disable PrintCanonicalTypes here because we want
+  // the DW_AT_name to benefit from the TypePrinter's ability
+  // to skip defaulted template arguments.
+  //
+  // FIXME: Once -gsimple-template-names is enabled by default
+  // and we attach template parameters to alias template DIEs
+  // we don't need to worry about customizing the PrintingPolicy
+  // here anymore.
+  PP.PrintCanonicalTypes = false;
+  printTemplateArgumentList(OS, Ty->template_arguments(), PP,
+TD->getTemplateParameters());
 
   SourceLocation Loc = AliasDecl->getLocation();
   return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142268: [clang][DebugInfo] Don't canonicalize names in template argument list for alias templates

2023-01-20 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

@dblaikie suggested that the best way to go about the recurring "how do we 
print template names" question is to turn on `-gsimple-template-names` on by 
default. For alias templates this means we would have to attach template 
parameters to their DIEs too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142268

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


[PATCH] D141826: [WIP][clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-23 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 491251.
Michael137 added a comment.

- `setIsDefaulted` when constructing `ClassTemplateSpecializationDecl`s
- Propagate `IsDefaulted` on serialization


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

Files:
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -490,3 +490,34 @@
   ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
   EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
 }
+
+TEST(Decl, TemplateParameterListWithCallback) {
+  llvm::Annotations Code(R"cpp(
+template
+struct Alloc {};
+
+template >
+struct Foo {
+};
+
+Foo> X;
+  )cpp");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  EXPECT_FALSE(ArgList.get(0).getIsDefaulted());
+  EXPECT_FALSE(ArgList.get(1).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(2).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(3).getIsDefaulted());
+}
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -161,8 +161,9 @@
 //===--===//
 
 TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
-   QualType Type) {
+   QualType Type, bool IsDefaulted) {
   Integer.Kind = Integral;
+  Integer.IsDefaulted = IsDefaulted;
   // Copy the APSInt value into our decomposed form.
   Integer.BitWidth = Value.getBitWidth();
   Integer.IsUnsigned = Value.isUnsigned();
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -903,22 +903,42 @@
   FD, Template, TSK, TemplateArgs, ArgsAsWritten, POI, MSInfo);
 }
 
+/// Creates a copy of the 'TemplateArgument's in 'Args'.
+/// If a 'TemplateArgument' corresponds to a default template
+/// parameter this function will mark it as such.
+static TemplateArgumentList *
+CreateCopyWithDefaultedArgs(ASTContext &Ctx,
+TemplateParameterList const *Params,
+ArrayRef Args) {
+  int i = 0;
+  auto MutArgs = Args.copy(Ctx);
+  for (auto &Arg : MutArgs) {
+if (clang::isSubstitutedDefaultArgument(Ctx, Arg, Params->getParam(i), Args,
+Params->getDepth())) {
+  Arg.setIsDefaulted(true);
+}
+++i;
+  }
+
+  return TemplateArgumentList::CreateCopy(Ctx, MutArgs);
+}
+
 //===--===//
 // ClassTemplateSpecializationDecl Implementation
 //===--===//
 
-ClassTemplateSpecializationDecl::
-ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
-DeclContext *DC, SourceLocation StartLoc,
-SourceLocation IdLoc,
-ClassTemplateDecl *SpecializedTemplate,
-ArrayRef Args,
-ClassTemplateSpecializationDecl *PrevDecl)
+ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(
+ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC,
+SourceLocation StartLoc, SourceLocation IdLoc,
+ClassTemplateDecl *SpecializedTemplate, ArrayRef Args,
+ClassTemplateSpecializationDecl *PrevDecl)
 : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
 SpecializedTemplate->getIdentifier(), PrevDecl),
-SpecializedTemplate(SpecializedTemplate),
-TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
-SpecializationKind(TSK_Undeclared) {
+  SpecializedTemplate(SpecializedTemplate),
+  SpecializationKind(TSK_Undeclared) {
+
+  TemplateArgs = CreateCopyWithDefaultedArgs(
+  Context, SpecializedTemplate->getTemplateParameters(), Args);
 }
 
 ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C,
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTConte

[PATCH] D141827: [WIP][clang][TypePrinter] Test TemplateArgument::IsDefaulted when omitting default arguments

2023-01-23 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 491254.
Michael137 added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141827

Files:
  clang/lib/AST/TypePrinter.cpp


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -2086,14 +2086,10 @@
   if (TPL && Policy.SuppressDefaultTemplateArgs &&
   !Policy.PrintCanonicalTypes && !Args.empty() && !IsPack &&
   Args.size() <= TPL->size()) {
-ASTContext &Ctx = TPL->getParam(0)->getASTContext();
 llvm::SmallVector OrigArgs;
 for (const TA &A : Args)
   OrigArgs.push_back(getArgument(A));
-while (!Args.empty() &&
-   isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()),
-TPL->getParam(Args.size() - 1),
-OrigArgs, TPL->getDepth()))
+while (!Args.empty() && getArgument(Args.back()).getIsDefaulted())
   Args = Args.drop_back();
   }
 


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -2086,14 +2086,10 @@
   if (TPL && Policy.SuppressDefaultTemplateArgs &&
   !Policy.PrintCanonicalTypes && !Args.empty() && !IsPack &&
   Args.size() <= TPL->size()) {
-ASTContext &Ctx = TPL->getParam(0)->getASTContext();
 llvm::SmallVector OrigArgs;
 for (const TA &A : Args)
   OrigArgs.push_back(getArgument(A));
-while (!Args.empty() &&
-   isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()),
-TPL->getParam(Args.size() - 1),
-OrigArgs, TPL->getDepth()))
+while (!Args.empty() && getArgument(Args.back()).getIsDefaulted())
   Args = Args.drop_back();
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142333: [clang][DebugInfo] Check TemplateArgument::IsDefaulted

2023-01-23 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: dblaikie, aprantl.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since `ClassTemplateSpecializationDecl`s now set the
`TemplateArgument::IsDefaulted` bit, there's no need
to derive it here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142333

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2010,15 +2010,10 @@
   for (unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
 const TemplateArgument &TA = Args.Args[i];
 StringRef Name;
-bool defaultParameter = false;
-if (Args.TList) {
+bool defaultParameter = TA.getIsDefaulted();
+if (Args.TList)
   Name = Args.TList->getParam(i)->getName();
 
-  NamedDecl const *ND = Args.TList->getParam(i);
-  defaultParameter = clang::isSubstitutedDefaultArgument(
-  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
-}
-
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2010,15 +2010,10 @@
   for (unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
 const TemplateArgument &TA = Args.Args[i];
 StringRef Name;
-bool defaultParameter = false;
-if (Args.TList) {
+bool defaultParameter = TA.getIsDefaulted();
+if (Args.TList)
   Name = Args.TList->getParam(i)->getName();
 
-  NamedDecl const *ND = Args.TList->getParam(i);
-  defaultParameter = clang::isSubstitutedDefaultArgument(
-  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
-}
-
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142268: [clang][DebugInfo] Don't canonicalize names in template argument list for alias templates

2023-01-23 Thread Michael Buch via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbee8860525ac: [clang][DebugInfo] Don't canonicalize 
names in template argument list for alias… (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142268

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-alias.cpp


Index: clang/test/CodeGenCXX/debug-info-alias.cpp
===
--- clang/test/CodeGenCXX/debug-info-alias.cpp
+++ clang/test/CodeGenCXX/debug-info-alias.cpp
@@ -3,6 +3,11 @@
 template
 struct foo {
 };
+
+template
+struct baz {
+};
+
 namespace x {
 // splitting these over multiple lines to make sure the right token is used for
 // the location
@@ -18,6 +23,9 @@
 // CHECK: !DIGlobalVariable(name: "bf",{{.*}} type: [[BFLOAT:![0-9]+]]
 // CHECK: [[BFLOAT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar"
 x::bar bf;
+// CHECK: !DIGlobalVariable(name: "bz",{{.*}} type: [[BBAZ:![0-9]+]]
+// CHECK: [[BBAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar >"
+x::bar> bz;
 
 using
 // CHECK: !DIGlobalVariable(name: "n",{{.*}} type: [[NARF:![0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1288,9 +1288,21 @@
 
   SmallString<128> NS;
   llvm::raw_svector_ostream OS(NS);
-  Ty->getTemplateName().print(OS, getPrintingPolicy(),
-  TemplateName::Qualified::None);
-  printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy());
+
+  auto PP = getPrintingPolicy();
+  Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
+
+  // Disable PrintCanonicalTypes here because we want
+  // the DW_AT_name to benefit from the TypePrinter's ability
+  // to skip defaulted template arguments.
+  //
+  // FIXME: Once -gsimple-template-names is enabled by default
+  // and we attach template parameters to alias template DIEs
+  // we don't need to worry about customizing the PrintingPolicy
+  // here anymore.
+  PP.PrintCanonicalTypes = false;
+  printTemplateArgumentList(OS, Ty->template_arguments(), PP,
+TD->getTemplateParameters());
 
   SourceLocation Loc = AliasDecl->getLocation();
   return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),


Index: clang/test/CodeGenCXX/debug-info-alias.cpp
===
--- clang/test/CodeGenCXX/debug-info-alias.cpp
+++ clang/test/CodeGenCXX/debug-info-alias.cpp
@@ -3,6 +3,11 @@
 template
 struct foo {
 };
+
+template
+struct baz {
+};
+
 namespace x {
 // splitting these over multiple lines to make sure the right token is used for
 // the location
@@ -18,6 +23,9 @@
 // CHECK: !DIGlobalVariable(name: "bf",{{.*}} type: [[BFLOAT:![0-9]+]]
 // CHECK: [[BFLOAT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar"
 x::bar bf;
+// CHECK: !DIGlobalVariable(name: "bz",{{.*}} type: [[BBAZ:![0-9]+]]
+// CHECK: [[BBAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar >"
+x::bar> bz;
 
 using
 // CHECK: !DIGlobalVariable(name: "n",{{.*}} type: [[NARF:![0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1288,9 +1288,21 @@
 
   SmallString<128> NS;
   llvm::raw_svector_ostream OS(NS);
-  Ty->getTemplateName().print(OS, getPrintingPolicy(),
-  TemplateName::Qualified::None);
-  printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy());
+
+  auto PP = getPrintingPolicy();
+  Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
+
+  // Disable PrintCanonicalTypes here because we want
+  // the DW_AT_name to benefit from the TypePrinter's ability
+  // to skip defaulted template arguments.
+  //
+  // FIXME: Once -gsimple-template-names is enabled by default
+  // and we attach template parameters to alias template DIEs
+  // we don't need to worry about customizing the PrintingPolicy
+  // here anymore.
+  PP.PrintCanonicalTypes = false;
+  printTemplateArgumentList(OS, Ty->template_arguments(), PP,
+TD->getTemplateParameters());
 
   SourceLocation Loc = AliasDecl->getLocation();
   return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141826: [WIP][clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-23 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D141826#4059088 , @erichkeane 
wrote:

> In D141826#4059073 , @Michael137 
> wrote:
>
>> In D141826#4058866 , @erichkeane 
>> wrote:
>>
>>> This seems innocuous enough/easy enough to use.  I'd like a comment on the 
>>> functions at least and types in TemplateBase.h to specify that this is for 
>>> printing-policy only?  Alternatively (and perhaps MUCH more appreciated) 
>>> would be to make sure we mark the defaulted during AST generation as well.
>>
>> I'll have a look at doing that
>>
>> Are you suggesting we do the substitution check that the TypePrinter 
>> currently does when constructing the specialisation decls? So the 
>> TypePrinter simply needs to check the `TemplateArgument::getIsDefaulted`? I 
>> like the sound of that.
>>
>> Unfortunately we'd still need the `setIsDefaulted` because of the DWARF 
>> limitation in LLDB
>
> Yes, thats my thought.  Of course we'd still need the 'setIsDefaulted', but 
> at least it would be something that coudl be generally useful.

So I've been having a go at this. The latest diff sets the bit when creating 
`ClassTemplateSpecializationDecl`s. However, we end up having to copy the 
`ArrayRef` twice (because of the current assumptions that a 
`TemplateArgumentList` is immutable, which seems like a nice property to 
maintain). But the double copy does seem iffy.

I also had to add the flag to the `TemplateArgument` tablegen description to 
support deserialized `ClassTemplateSpecializationDecl`.

I've been playing around with setting the flag at construction of 
`TemplateArgument`s instead. Not sure how much cleaner that's going to be 
because so far I've not found a good single point of entry (been looking at 
CheckTemplateArgumentList 

 in `SemaTemplate`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

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


[PATCH] D142268: [clang][DebugInfo] Don't canonicalize names in template argument list for alias templates

2023-01-23 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D142268#4072358 , @dblaikie wrote:

> So @Michael137 and I talked about this offline, and a few extra details:
>
> - Generally it's important that types have identical names. Templates try to 
> do this, but get it wrong in a bunch of ways (& certainly between GCC and 
> Clang we get it different in a bunch of ways too) which are all 
> problematic/could cause a debugger to not correctly identify two types in 
> distinct CUs as being actually the same type.
>   - That's why we usually use the full name of a template, to ensure it's 
> identical between instantiations in different CUs
> - Because compilers don't all produce character-for-character identical 
> names, debuggers mostly have to throw away the "<.*>" and recanonicalize from 
> the `DW_TAG_template_*_parameter`s anyway..
> - But none of that matters, because alias templates aren't strong aliases - 
> they aren't part of the type system, they're just a name that code can use
> - As mentioned, GCC currently only uses the base name, no template parameters 
> - which isn't super helpful (since you'd then end up with a bunch of 
> different alias template instantiations all with the same name).
> - Clang produces the alias template with the template parameters in the 
> `DW_AT_name`, but without any `DW_TAG_template_*_parameter` DIEs, which means 
> we can't apply Simple Template Names here, currently - though might be a nice 
> thing to do at somepoint.
>
> But for now, since the name doesn't actually have to be 
> deconstruct/canonicalize the template parameters - we can just pick whatever 
> name is nice for the user, really.
>
> So, I think this is an OK change to make for now - though probably the nicer 
> thing, long-term, would be to add the template parameter DIEs, and under 
> `-gsimple-template-names` remove the template parameters from the 
> `DW_AT_name` (& maybe eventually turn that on by default/migrate to 
> `-gsimple-template-names`) but for now/when using 
> non`-gsimple-template-names`, this seems OK, if a bit weird/inconsistent, but 
> for good reasons because the alias template isn't part of the type system. 
> (thanks for including the FIXME there)

Thanks for the extensive summary!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142268

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


[PATCH] D142333: [clang][DebugInfo] Check TemplateArgument::IsDefaulted

2023-01-23 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 491257.
Michael137 added a comment.

- Make variable `const`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142333

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2010,15 +2010,10 @@
   for (unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
 const TemplateArgument &TA = Args.Args[i];
 StringRef Name;
-bool defaultParameter = false;
-if (Args.TList) {
+const bool defaultParameter = TA.getIsDefaulted();
+if (Args.TList)
   Name = Args.TList->getParam(i)->getName();
 
-  NamedDecl const *ND = Args.TList->getParam(i);
-  defaultParameter = clang::isSubstitutedDefaultArgument(
-  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
-}
-
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);


Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2010,15 +2010,10 @@
   for (unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
 const TemplateArgument &TA = Args.Args[i];
 StringRef Name;
-bool defaultParameter = false;
-if (Args.TList) {
+const bool defaultParameter = TA.getIsDefaulted();
+if (Args.TList)
   Name = Args.TList->getParam(i)->getName();
 
-  NamedDecl const *ND = Args.TList->getParam(i);
-  defaultParameter = clang::isSubstitutedDefaultArgument(
-  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
-}
-
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141826: [WIP][clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

2023-01-23 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 491265.
Michael137 added a comment.

- Rename test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141826

Files:
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -490,3 +490,34 @@
   ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
   EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
 }
+
+TEST(Decl, TemplateArgumentDefaulted) {
+  llvm::Annotations Code(R"cpp(
+template
+struct Alloc {};
+
+template >
+struct Foo {
+};
+
+Foo> X;
+  )cpp");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const &ArgList = CTSD->getTemplateArgs();
+
+  EXPECT_FALSE(ArgList.get(0).getIsDefaulted());
+  EXPECT_FALSE(ArgList.get(1).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(2).getIsDefaulted());
+  EXPECT_TRUE(ArgList.get(3).getIsDefaulted());
+}
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -161,8 +161,9 @@
 //===--===//
 
 TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
-   QualType Type) {
+   QualType Type, bool IsDefaulted) {
   Integer.Kind = Integral;
+  Integer.IsDefaulted = IsDefaulted;
   // Copy the APSInt value into our decomposed form.
   Integer.BitWidth = Value.getBitWidth();
   Integer.IsUnsigned = Value.isUnsigned();
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -903,22 +903,42 @@
   FD, Template, TSK, TemplateArgs, ArgsAsWritten, POI, MSInfo);
 }
 
+/// Creates a copy of the 'TemplateArgument's in 'Args'.
+/// If a 'TemplateArgument' corresponds to a default template
+/// parameter this function will mark it as such.
+static TemplateArgumentList *
+CreateCopyWithDefaultedArgs(ASTContext &Ctx,
+TemplateParameterList const *Params,
+ArrayRef Args) {
+  int i = 0;
+  auto MutArgs = Args.copy(Ctx);
+  for (auto &Arg : MutArgs) {
+if (clang::isSubstitutedDefaultArgument(Ctx, Arg, Params->getParam(i), Args,
+Params->getDepth())) {
+  Arg.setIsDefaulted(true);
+}
+++i;
+  }
+
+  return TemplateArgumentList::CreateCopy(Ctx, MutArgs);
+}
+
 //===--===//
 // ClassTemplateSpecializationDecl Implementation
 //===--===//
 
-ClassTemplateSpecializationDecl::
-ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
-DeclContext *DC, SourceLocation StartLoc,
-SourceLocation IdLoc,
-ClassTemplateDecl *SpecializedTemplate,
-ArrayRef Args,
-ClassTemplateSpecializationDecl *PrevDecl)
+ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(
+ASTContext &Context, Kind DK, TagKind TK, DeclContext *DC,
+SourceLocation StartLoc, SourceLocation IdLoc,
+ClassTemplateDecl *SpecializedTemplate, ArrayRef Args,
+ClassTemplateSpecializationDecl *PrevDecl)
 : CXXRecordDecl(DK, TK, Context, DC, StartLoc, IdLoc,
 SpecializedTemplate->getIdentifier(), PrevDecl),
-SpecializedTemplate(SpecializedTemplate),
-TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args)),
-SpecializationKind(TSK_Undeclared) {
+  SpecializedTemplate(SpecializedTemplate),
+  SpecializationKind(TSK_Undeclared) {
+
+  TemplateArgs = CreateCopyWithDefaultedArgs(
+  Context, SpecializedTemplate->getTemplateParameters(), Args);
 }
 
 ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(ASTContext &C,
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6739,26 +6739,29 @@
 
 case TemplateArgument::Declaration: {
   auto *D = cast(Arg.getAsDe

[PATCH] D142024: [clang] Optimize clang::Builtin::Info density

2023-01-23 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Seems like this broke the LLDB incremental build: 
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/50184/execution/node/43/log/?consoleFull

We build with `LLVM_ENABLE_MODULES` by default

  While building module 'Clang_Basic' imported from 
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Lex/DependencyDirectivesScanner.h:20:
  In file included from :9:
  
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:54:1:
 error: expected identifier
  #include "clang/Basic/BuiltinHeaders.def"
  ^
  
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:54:1:
 error: expected '}'
  
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:52:28:
 note: to match this '{'
enum HeaderID : uint16_t {
 ^
  
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:52:29:
 error: expected ';' after enum
enum HeaderID : uint16_t {
  ^
  ;
  
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:54:1:
 fatal error: import of module 'Clang_Basic.BuiltinHeaders' appears within 
'clang::HeaderDesc'
  #include "clang/Basic/BuiltinHeaders.def"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142024

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


[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

2023-08-04 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Could you please elaborate in the commit message what exactly the issue 
currently is and how the patch addresses it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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


[PATCH] D154709: [clang][ASTImporter] Add a 'Message' member to ASTImportError use it throught ASTImporter

2023-07-07 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: martong, balazske.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

This patch adds a new `ASTImportError::Message` which is used
to more accurately describe a failure when `ASTImportError::log`
is called. We then set this error message throughout ASTImporter.

The motivation for this is that in upcoming patches LLDB will
check `ASTImportError`s and log them on failures. At the moment
these logs wouldn't be helpful since we wouldn't be able to
differentiate between the different conflicts that occur
during a single import process.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154709

Files:
  clang/include/clang/AST/ASTImportError.h
  clang/lib/AST/ASTImporter.cpp

Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/ASTImporter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTDiagnostic.h"
+#include "clang/AST/ASTImportError.h"
 #include "clang/AST/ASTImporterSharedState.h"
 #include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/AST/Attr.h"
@@ -34,6 +35,7 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -61,7 +63,9 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 #include 
@@ -84,7 +88,6 @@
   using ExpectedName = llvm::Expected;
 
   std::string ASTImportError::toString() const {
-// FIXME: Improve error texts.
 switch (Error) {
 case NameConflict:
   return "NameConflict";
@@ -97,7 +100,11 @@
 return "Invalid error code.";
   }
 
-  void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
+  void ASTImportError::log(raw_ostream &OS) const {
+OS << toString();
+if (!Message.empty())
+  OS << ": " << Message;
+  }
 
   std::error_code ASTImportError::convertToErrorCode() const {
 llvm_unreachable("Function not implemented.");
@@ -1066,7 +1073,8 @@
 ExpectedType ASTNodeImporter::VisitType(const Type *T) {
   Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
 << T->getTypeClassName();
-  return make_error(ASTImportError::UnsupportedConstruct);
+  return make_error(ASTImportError::UnsupportedConstruct,
+T->getTypeClassName());
 }
 
 ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
@@ -1715,7 +1723,8 @@
   if (RT && RT->getDecl() == D) {
 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
 << D->getDeclKindName();
-return make_error(ASTImportError::UnsupportedConstruct);
+return make_error(ASTImportError::UnsupportedConstruct,
+  D->getDeclKindName());
   }
 }
   }
@@ -2238,13 +2247,15 @@
 ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) {
   Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
 << D->getDeclKindName();
-  return make_error(ASTImportError::UnsupportedConstruct);
+  return make_error(ASTImportError::UnsupportedConstruct,
+D->getDeclKindName());
 }
 
 ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) {
   Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
   << D->getDeclKindName();
-  return make_error(ASTImportError::UnsupportedConstruct);
+  return make_error(ASTImportError::UnsupportedConstruct,
+D->getDeclKindName());
 }
 
 ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) {
@@ -3893,7 +3904,13 @@
   Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
 << FoundField->getType();
 
-  return make_error(ASTImportError::NameConflict);
+  std::string ErrMessage;
+  llvm::raw_string_ostream OS(ErrMessage);
+  OS << "Field '" << Name.getAsString()
+ << "' declared with incompatible types in different TUs ('"
+ << D->getType() << "' and '" << FoundField->getType() << "')";
+  return make_error(ASTImportError::NameConflict,
+std::move(ErrMessage));
 }
   }
 
@@ -3972,7 +3989,13 @@
   Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
 << FoundField->getType();
 
-  return make_error(ASTImportError::NameConflict);
+  std::string ErrMessage;
+  llvm::ra

[PATCH] D154709: [clang][ASTImporter] Add a 'Message' member to ASTImportError use it throught ASTImporter

2023-07-07 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 538110.
Michael137 added a comment.

- Remove redundant header additions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154709

Files:
  clang/include/clang/AST/ASTImportError.h
  clang/lib/AST/ASTImporter.cpp

Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -84,7 +84,6 @@
   using ExpectedName = llvm::Expected;
 
   std::string ASTImportError::toString() const {
-// FIXME: Improve error texts.
 switch (Error) {
 case NameConflict:
   return "NameConflict";
@@ -97,7 +96,11 @@
 return "Invalid error code.";
   }
 
-  void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
+  void ASTImportError::log(raw_ostream &OS) const {
+OS << toString();
+if (!Message.empty())
+  OS << ": " << Message;
+  }
 
   std::error_code ASTImportError::convertToErrorCode() const {
 llvm_unreachable("Function not implemented.");
@@ -1066,7 +1069,8 @@
 ExpectedType ASTNodeImporter::VisitType(const Type *T) {
   Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
 << T->getTypeClassName();
-  return make_error(ASTImportError::UnsupportedConstruct);
+  return make_error(ASTImportError::UnsupportedConstruct,
+T->getTypeClassName());
 }
 
 ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
@@ -1715,7 +1719,8 @@
   if (RT && RT->getDecl() == D) {
 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
 << D->getDeclKindName();
-return make_error(ASTImportError::UnsupportedConstruct);
+return make_error(ASTImportError::UnsupportedConstruct,
+  D->getDeclKindName());
   }
 }
   }
@@ -2238,13 +2243,15 @@
 ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) {
   Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
 << D->getDeclKindName();
-  return make_error(ASTImportError::UnsupportedConstruct);
+  return make_error(ASTImportError::UnsupportedConstruct,
+D->getDeclKindName());
 }
 
 ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) {
   Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
   << D->getDeclKindName();
-  return make_error(ASTImportError::UnsupportedConstruct);
+  return make_error(ASTImportError::UnsupportedConstruct,
+D->getDeclKindName());
 }
 
 ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) {
@@ -3893,7 +3900,13 @@
   Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
 << FoundField->getType();
 
-  return make_error(ASTImportError::NameConflict);
+  std::string ErrMessage;
+  llvm::raw_string_ostream OS(ErrMessage);
+  OS << "Field '" << Name.getAsString()
+ << "' declared with incompatible types in different TUs ('"
+ << D->getType() << "' and '" << FoundField->getType() << "')";
+  return make_error(ASTImportError::NameConflict,
+std::move(ErrMessage));
 }
   }
 
@@ -3972,7 +3985,13 @@
   Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
 << FoundField->getType();
 
-  return make_error(ASTImportError::NameConflict);
+  std::string ErrMessage;
+  llvm::raw_string_ostream OS(ErrMessage);
+  OS << "IndirectField '" << Name.getAsString()
+ << "' declared with incompatible types in different TUs ('"
+ << D->getType() << "' and '" << FoundField->getType() << "')";
+  return make_error(ASTImportError::NameConflict,
+std::move(ErrMessage));
 }
   }
 
@@ -4163,7 +4182,13 @@
   Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
 << FoundIvar->getType();
 
-  return make_error(ASTImportError::NameConflict);
+  std::string ErrMessage;
+  llvm::raw_string_ostream OS(ErrMessage);
+  OS << "ObjCIvarDecl '" << Name.getAsString()
+ << "' declared with incompatible types in different TUs ('"
+ << D->getType() << "' and '" << FoundIvar->getType() << "')";
+  return make_error(ASTImportError::NameConflict,
+std::move(ErrMessage));
 }
   }
 
@@ -4471,7 +4496,14 @@
 diag::note_odr_objc_method_here)
   << D->isInstanceMethod() << Name;
 
-return make_error(ASTImportError::NameConflict);
+std::string ErrMessage;
+llvm::raw_string_ostream OS(ErrMessage);
+OS << "ObjCMethodDecl '" << Name.getAsString()
+   << "' has incompatible result types in different TUs ('"
+   << D->getReturnType() << "' and '" << FoundMethod->getReturnType()
+   

[PATCH] D154709: [clang][ASTImporter] Add a 'Message' member to ASTImportError use it throught ASTImporter

2023-07-07 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Didn't add tests for this since checking the contents of the error message 
didn't seem worth testing.
But don't mind adding tests if reviewers feel more comfortable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154709

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


[PATCH] D154709: [clang][ASTImporter] Add a 'Message' member to ASTImportError and use it throughout ASTImporter

2023-07-07 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 538111.
Michael137 added a comment.

- Fix commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154709

Files:
  clang/include/clang/AST/ASTImportError.h
  clang/lib/AST/ASTImporter.cpp

Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -84,7 +84,6 @@
   using ExpectedName = llvm::Expected;
 
   std::string ASTImportError::toString() const {
-// FIXME: Improve error texts.
 switch (Error) {
 case NameConflict:
   return "NameConflict";
@@ -97,7 +96,11 @@
 return "Invalid error code.";
   }
 
-  void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
+  void ASTImportError::log(raw_ostream &OS) const {
+OS << toString();
+if (!Message.empty())
+  OS << ": " << Message;
+  }
 
   std::error_code ASTImportError::convertToErrorCode() const {
 llvm_unreachable("Function not implemented.");
@@ -1066,7 +1069,8 @@
 ExpectedType ASTNodeImporter::VisitType(const Type *T) {
   Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
 << T->getTypeClassName();
-  return make_error(ASTImportError::UnsupportedConstruct);
+  return make_error(ASTImportError::UnsupportedConstruct,
+T->getTypeClassName());
 }
 
 ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
@@ -1715,7 +1719,8 @@
   if (RT && RT->getDecl() == D) {
 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
 << D->getDeclKindName();
-return make_error(ASTImportError::UnsupportedConstruct);
+return make_error(ASTImportError::UnsupportedConstruct,
+  D->getDeclKindName());
   }
 }
   }
@@ -2238,13 +2243,15 @@
 ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) {
   Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
 << D->getDeclKindName();
-  return make_error(ASTImportError::UnsupportedConstruct);
+  return make_error(ASTImportError::UnsupportedConstruct,
+D->getDeclKindName());
 }
 
 ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) {
   Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
   << D->getDeclKindName();
-  return make_error(ASTImportError::UnsupportedConstruct);
+  return make_error(ASTImportError::UnsupportedConstruct,
+D->getDeclKindName());
 }
 
 ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) {
@@ -3893,7 +3900,13 @@
   Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
 << FoundField->getType();
 
-  return make_error(ASTImportError::NameConflict);
+  std::string ErrMessage;
+  llvm::raw_string_ostream OS(ErrMessage);
+  OS << "Field '" << Name.getAsString()
+ << "' declared with incompatible types in different TUs ('"
+ << D->getType() << "' and '" << FoundField->getType() << "')";
+  return make_error(ASTImportError::NameConflict,
+std::move(ErrMessage));
 }
   }
 
@@ -3972,7 +3985,13 @@
   Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
 << FoundField->getType();
 
-  return make_error(ASTImportError::NameConflict);
+  std::string ErrMessage;
+  llvm::raw_string_ostream OS(ErrMessage);
+  OS << "IndirectField '" << Name.getAsString()
+ << "' declared with incompatible types in different TUs ('"
+ << D->getType() << "' and '" << FoundField->getType() << "')";
+  return make_error(ASTImportError::NameConflict,
+std::move(ErrMessage));
 }
   }
 
@@ -4163,7 +4182,13 @@
   Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
 << FoundIvar->getType();
 
-  return make_error(ASTImportError::NameConflict);
+  std::string ErrMessage;
+  llvm::raw_string_ostream OS(ErrMessage);
+  OS << "ObjCIvarDecl '" << Name.getAsString()
+ << "' declared with incompatible types in different TUs ('"
+ << D->getType() << "' and '" << FoundIvar->getType() << "')";
+  return make_error(ASTImportError::NameConflict,
+std::move(ErrMessage));
 }
   }
 
@@ -4471,7 +4496,14 @@
 diag::note_odr_objc_method_here)
   << D->isInstanceMethod() << Name;
 
-return make_error(ASTImportError::NameConflict);
+std::string ErrMessage;
+llvm::raw_string_ostream OS(ErrMessage);
+OS << "ObjCMethodDecl '" << Name.getAsString()
+   << "' has incompatible result types in different TUs ('"
+   << D->getReturnType() << "' and '" << FoundMethod->getReturnType()
+   << "')"

[PATCH] D154709: [clang][ASTImporter] Add a 'Message' member to ASTImportError and use it throughout ASTImporter

2023-07-11 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D154709#4487776 , @balazske wrote:

> The goal is to have a message always in `ASTImportError`? Then probably the 
> constructor without message can be removed, at least to check if really the 
> message is added at all places. I found that it is missing in 
> `VisitObjCImplementationDecl`.

Agree, will do that

> I do not know what happens with messages passed to FromDiag or ToDiag and if 
> these are available somehow to LLDB.

Ideally yes, but I found they're not very helpful in LLDB's use-case because:

1. the diagnostic doesn't get issued at all call-sites
2. LLDB switches off any `odr` related warnings because AFAIU they occur a lot 
(outside the ASTImporter) and would flood the user with redundant information

> Otherwise it would be even better to remove all FromDiag and ToDiag messages 
> from ASTImporter and put these messages into ASTImportError and use later in 
> the way that is needed by the use case. This would require to pass a message 
> to HandleNameConflict but then we have always the detailed message. There are 
> places where diagnostic is generated but there is no error, we should check 
> if this is correct and if we can remove the diagnostic or make import error.

That sounds like a good way forward. The `-ast-merge` clang option does benefit 
from these diagnostics. So we would probably need to change it to dump the 
`ASTImportError` instead of relying on the diagnostics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154709

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-20 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 506588.
Michael137 added a comment.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

- Fix cycle in `DIDerivedType` when we deal with forward declarations and 
complete explicitly via `completeClassData` (e.g., with `-gmodules`)
- Add tests for `-gmodules`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/preferred_name.cpp
  clang/test/Modules/Inputs/gmodules-preferred-name-alias.h
  clang/test/Modules/Inputs/gmodules-preferred-name-alias.modulemap
  clang/test/Modules/Inputs/gmodules-preferred-name-typedef.h
  clang/test/Modules/Inputs/gmodules-preferred-name-typedef.modulemap
  clang/test/Modules/gmodules-preferred-name-alias.cpp
  clang/test/Modules/gmodules-preferred-name-typedef.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
@@ -22,7 +22,7 @@
 
 def make_expected_basic_string_ptr(self) -> str:
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(['>', '16.0']):
-return f'std::unique_ptr >'
+return f'std::unique_ptr'
 else:
 return 'std::unique_ptr, std::allocator >, ' \
'std::default_delete, std::allocator > > >'
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
@@ -59,13 +59,13 @@
 self.assertNotEqual(valobj.child[0].unsigned, 0)
 
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(['>', '16.0']):
-string_type = "std::basic_string"
+string_type = "std::string"
 else:
-string_type = "std::basic_string, std::allocator >"
+string_type = "std::basic_string, std::allocator > "
 
 valobj = self.expect_var_path(
 "sp_str",
-type="std::shared_ptr<" + string_type + " >",
+type="std::shared_ptr<" + string_type + ">",
 children=[ValueCheck(name="__ptr_", summary='"hello"')],
 )
 self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')
Index: clang/test/Modules/gmodules-preferred-name-typedef.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-preferred-name-typedef.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
+// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-typedef.modulemap \
+// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
+// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
+// RUN: -I %S/Inputs %s &> %t.ll
+// RUN: cat %t.ll | FileCheck %s
+
+#include "gmodules-preferred-name-typedef.h"
+
+// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
+// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
Index: clang/test/Modules/gmodules-preferred-name-alias.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-preferred-name-alias.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
+// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-alias.modulemap \
+// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
+// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
+// RUN: -I %S/Inputs %s &> %t.ll
+// RUN: cat %t.ll | FileCheck %s
+
+#include "gmodules-preferred-name-alias.h"
+
+// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
+// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name:

[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-23 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2640
   if (!D || !D->isCompleteDefinition())
-return FwdDecl;
+return {FwdDecl, nullptr};
 

aprantl wrote:
> I'm curious if this works if we encounter a forward declaration, early exit 
> here, then encounter a use of the type, and then the definition, since 
> completeClass effectively also ignores the preferred name?
Good point. If we ever take this branch we won't end up emitting the preferred 
name. For my `-gmodules` test cases this works out fine because the modules 
that contain the instantiations would see the preferred name. But I can indeed 
construct a non-modules test case where we end up using a forward declared 
structure where the preferred name gets ignored here. Not sure we can do much 
here for such cases.

The alternative I considered where we create some sort of 
`PreferredNameCache[TagType*] => DIDerivedType` and use it when replacing 
forward declarations in `finalize()` doesn't work for the normal case because 
we don't have any forward declarations to replace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-03-24 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

FWIW here's some info on how we get to the assert. Maybe someone with more 
understanding of the `clang::SourceManager` and how it interacts with `.pcm`s 
will be able to spot something.

Here's a bit more of the stack trace:

  frame #41: 0x00013844c7e0 
liblldb.17.0.0git.dylib`clang::Sema::LookupParsedName(this=0x000177def200, 
R=0x00016fdea010, S=0x000164a6e300, SS=0x00016fdeb1b8, 
AllowBuiltinCreation=true, EnteringContext=false) at SemaLookup.cpp:2741:10
  frame #40: 0x00013844afd0 
liblldb.17.0.0git.dylib`clang::Sema::LookupName(this=0x000177def200, 
R=0x00016fdea010, S=0x000164a6e300, AllowBuiltinCreation=true, 
ForceNoCPlusPlus=false) at SemaLookup.cpp:2267:9
  frame #39: 0x0001384468a0 
liblldb.17.0.0git.dylib`clang::Sema::CppLookupName(this=0x000177def200, 
R=0x00016fdea010, S=0x000164a6df70) at SemaLookup.cpp:1495:15
  frame #38: 0x0001384474e4 
liblldb.17.0.0git.dylib`CppNamespaceLookup(S=0x000177def200, 
R=0x00016fdea010, Context=0x000177de2c00, NS=0x000177deb830, 
UDirs=0x00016fde9a78)::UnqualUsingDirectiveSet&) at SemaLookup.cpp:1207:16
  frame #37: 0x00013844b208 
liblldb.17.0.0git.dylib`LookupDirect(S=0x000177def200, 
R=0x00016fdea010, DC=0x000177deb830) at SemaLookup.cpp:1109:39
  frame #36: 0x000139512644 
liblldb.17.0.0git.dylib`clang::DeclContext::lookup(this=0x000177deb830, 
Name=(Ptr = 5968768496)) const at DeclBase.cpp:1743:17
  frame #35: 0x000131c48b88 
liblldb.17.0.0git.dylib`lldb_private::ClangASTSource::ClangASTSourceProxy::FindExternalVisibleDeclsByName(this=0x60344060,
 DC=0x000177deb830, Name=(Ptr = 5968768496)) at ClangASTSource.h:216:25
  frame #34: 0x000134f0ab40 
liblldb.17.0.0git.dylib`lldb_private::ClangASTSource::FindExternalVisibleDeclsByName(this=0x63b3e140,
 decl_ctx=0x000177deb830, clang_decl_name=(Ptr = 5968768496)) at 
ClangASTSource.cpp:180:3
  frame #33: 0x000134f3b9d8 
liblldb.17.0.0git.dylib`lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(this=0x63b3e140,
 context=0x00016fde9008) at ClangExpressionDeclMap.cpp:727:5
  frame #32: 0x000134f3c1d8 
liblldb.17.0.0git.dylib`lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(this=0x63b3e140,
 context=0x00016fde9008, module_sp=nullptr, 
namespace_decl=0x00016fde8c90) at ClangExpressionDeclMap.cpp:1450:3
  frame #31: 0x000134f3fb80 
liblldb.17.0.0git.dylib`lldb_private::ClangExpressionDeclMap::LookupFunction(this=0x63b3e140,
 context=0x00016fde9008, module_sp=nullptr, name=(m_string = 
"CGImageGetRenderingIntent"), namespace_decl=0x00016fde8c90) at 
ClangExpressionDeclMap.cpp:1333:48
  frame #30: 0x000134f0e2c0 
liblldb.17.0.0git.dylib`lldb_private::ClangASTSource::CopyDecl(this=0x63b3e140,
 src_decl=0x00016462a480) at ClangASTSource.cpp:1728:29
  frame #29: 0x000134eedd58 
liblldb.17.0.0git.dylib`lldb_private::ClangASTImporter::CopyDecl(this=0x0001050683a8,
 dst_ast=0x000177de2c00, decl=0x00016462a480) at 
ClangASTImporter.cpp:78:55
  frame #28: 0x00013924cbd4 
liblldb.17.0.0git.dylib`clang::ASTImporter::Import(this=0x00010b42, 
FromD=0x00016462a480) at ASTImporter.cpp:9036:27
  frame #27: 0x000134ef2a84 
liblldb.17.0.0git.dylib`lldb_private::ClangASTImporter::ASTImporterDelegate::ImportImpl(this=0x00010b42,
 From=0x00016462a480) at ClangASTImporter.cpp:892:23
  frame #26: 0x0001392748dc 
liblldb.17.0.0git.dylib`clang::ASTImporter::ImportImpl(this=0x00010b42, 
FromD=0x00016462a480) at ASTImporter.cpp:8633:19
  frame #25: 0x000139274dc0 
liblldb.17.0.0git.dylib`clang::declvisitor::Base>::Visit(this=0x00016fde7a40, 
D=0x00016462a480) at DeclNodes.inc:433:1
  frame #24: 0x00013923e90c 
liblldb.17.0.0git.dylib`clang::ASTNodeImporter::VisitFunctionDecl(this=0x00016fde7a40,
 D=0x00016462a480) at ASTImporter.cpp:3603:44
  frame #23: 0x00013924026c 
liblldb.17.0.0git.dylib`std::__1::conditional, llvm::Expected, 
llvm::Expected>::type 
clang::ASTNodeImporter::import(this=0x00016fde7a40, 
From=0x0001035d6e80) at AS
  frame #22: 0x00013924cbd4 
liblldb.17.0.0git.dylib`clang::ASTImporter::Import(this=0x00010b42, 
FromD=0x0001035d6e80) at ASTImporter.cpp:9036:27
  frame #21: 0x000134ef2a84 
liblldb.17.0.0git.dylib`lldb_private::ClangASTImporter::ASTImporterDelegate::ImportImpl(this=0x00010b42,
 From=0x0001035d6e80) at ClangASTImporter.cpp:892:23
  frame #20: 0x0001392748dc 
liblldb.17.0.0git.dylib`clang::ASTImporter::ImportImpl(this=0x00010b42, 
FromD=0x0001035d6e80) at ASTImporter.cpp:8633:19
  frame #19: 0x000139274eb0 
liblldb.17.0.0git.dylib`clang::declvisitor::Base>::Visit(this=0x00016fde6530, 
D=0x0001035d6e80) at DeclNodes.inc:507:1
  frame #18: 0x000139246aec 
liblldb.17.0.0git.dylib`clang::ASTNodeImporter

[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-26 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/test/CodeGen/preferred_name.cpp:49
+
+Foo> varFooInt;
+

probinson wrote:
> This doesn't become `Foo` ?
The name stays as `Foo>` but the type of the template parameter 
becomes `BarInt`. So the dwarf would look like:
```
DW_TAG_structure_type
  DW_AT_name  ("Foo >")

  DW_TAG_template_type_parameter
DW_AT_type(0x0095 "BarInt")
DW_AT_name("T")

```
Will add the parameter metadata to the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 508562.
Michael137 added a comment.

- Refine tests:
  - Check for type of template parameter
  - Add test for chained typedefs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/preferred_name-chain.cpp
  clang/test/CodeGen/preferred_name.cpp
  clang/test/Modules/Inputs/gmodules-preferred-name-alias.h
  clang/test/Modules/Inputs/gmodules-preferred-name-alias.modulemap
  clang/test/Modules/Inputs/gmodules-preferred-name-typedef.h
  clang/test/Modules/Inputs/gmodules-preferred-name-typedef.modulemap
  clang/test/Modules/gmodules-preferred-name-alias.cpp
  clang/test/Modules/gmodules-preferred-name-typedef.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
@@ -22,7 +22,7 @@
 
 def make_expected_basic_string_ptr(self) -> str:
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(['>', '16.0']):
-return f'std::unique_ptr >'
+return f'std::unique_ptr'
 else:
 return 'std::unique_ptr, std::allocator >, ' \
'std::default_delete, std::allocator > > >'
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
@@ -59,13 +59,13 @@
 self.assertNotEqual(valobj.child[0].unsigned, 0)
 
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(['>', '16.0']):
-string_type = "std::basic_string"
+string_type = "std::string"
 else:
-string_type = "std::basic_string, std::allocator >"
+string_type = "std::basic_string, std::allocator > "
 
 valobj = self.expect_var_path(
 "sp_str",
-type="std::shared_ptr<" + string_type + " >",
+type="std::shared_ptr<" + string_type + ">",
 children=[ValueCheck(name="__ptr_", summary='"hello"')],
 )
 self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')
Index: clang/test/Modules/gmodules-preferred-name-typedef.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-preferred-name-typedef.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
+// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-typedef.modulemap \
+// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
+// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
+// RUN: -I %S/Inputs %s &> %t.ll
+// RUN: cat %t.ll | FileCheck %s
+
+#include "gmodules-preferred-name-typedef.h"
+
+// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
+// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
Index: clang/test/Modules/gmodules-preferred-name-alias.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-preferred-name-alias.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
+// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-alias.modulemap \
+// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
+// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
+// RUN: -I %S/Inputs %s &> %t.ll
+// RUN: cat %t.ll | FileCheck %s
+
+#include "gmodules-preferred-name-alias.h"
+
+// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
+// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
Index: clang/test/Modules/Inputs/gmodules-preferred-name-typedef.modulemap
===

[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 508563.
Michael137 added a comment.

- Fix function docstring


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/preferred_name-chain.cpp
  clang/test/CodeGen/preferred_name.cpp
  clang/test/Modules/Inputs/gmodules-preferred-name-alias.h
  clang/test/Modules/Inputs/gmodules-preferred-name-alias.modulemap
  clang/test/Modules/Inputs/gmodules-preferred-name-typedef.h
  clang/test/Modules/Inputs/gmodules-preferred-name-typedef.modulemap
  clang/test/Modules/gmodules-preferred-name-alias.cpp
  clang/test/Modules/gmodules-preferred-name-typedef.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
@@ -22,7 +22,7 @@
 
 def make_expected_basic_string_ptr(self) -> str:
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(['>', '16.0']):
-return f'std::unique_ptr >'
+return f'std::unique_ptr'
 else:
 return 'std::unique_ptr, std::allocator >, ' \
'std::default_delete, std::allocator > > >'
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
@@ -59,13 +59,13 @@
 self.assertNotEqual(valobj.child[0].unsigned, 0)
 
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(['>', '16.0']):
-string_type = "std::basic_string"
+string_type = "std::string"
 else:
-string_type = "std::basic_string, std::allocator >"
+string_type = "std::basic_string, std::allocator > "
 
 valobj = self.expect_var_path(
 "sp_str",
-type="std::shared_ptr<" + string_type + " >",
+type="std::shared_ptr<" + string_type + ">",
 children=[ValueCheck(name="__ptr_", summary='"hello"')],
 )
 self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')
Index: clang/test/Modules/gmodules-preferred-name-typedef.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-preferred-name-typedef.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
+// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-typedef.modulemap \
+// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
+// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
+// RUN: -I %S/Inputs %s &> %t.ll
+// RUN: cat %t.ll | FileCheck %s
+
+#include "gmodules-preferred-name-typedef.h"
+
+// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
+// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
Index: clang/test/Modules/gmodules-preferred-name-alias.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-preferred-name-alias.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
+// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-alias.modulemap \
+// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
+// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
+// RUN: -I %S/Inputs %s &> %t.ll
+// RUN: cat %t.ll | FileCheck %s
+
+#include "gmodules-preferred-name-alias.h"
+
+// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
+// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
Index: clang/test/Modules/Inputs/gmodules-preferred-name-typedef.modulemap
===
--- /dev/null
+++ clan

[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-27 Thread Michael Buch via Phabricator via cfe-commits
Michael137 marked an inline comment as not done.
Michael137 added inline comments.



Comment at: clang/test/CodeGen/preferred_name.cpp:49
+
+Foo> varFooInt;
+

dblaikie wrote:
> Michael137 wrote:
> > probinson wrote:
> > > This doesn't become `Foo` ?
> > The name stays as `Foo>` but the type of the template parameter 
> > becomes `BarInt`. So the dwarf would look like:
> > ```
> > DW_TAG_structure_type
> >   DW_AT_name  ("Foo >")
> > 
> >   DW_TAG_template_type_parameter
> > DW_AT_type(0x0095 "BarInt")
> > DW_AT_name("T")
> > 
> > ```
> > Will add the parameter metadata to the test
> Hmm, that seems buggy - why doesn't `Foo >` become `Foo`? 
> (is the preferred name ever used in the DW_AT_name? I'd have thought it 
> should be unless it's explicitly avoided to ensure type 
> compatibility/collapsing with debug info built without this feature enabled?)
I suspect it's because the name is constructed using the clang TypePrinter. And 
we turn off `PrintingPolicy::UsePreferredNames` by default to avoid divergence 
from GCC.

Will double check though


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-28 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D145803#4220124 , @wolfgangp wrote:

> In D145803#4219894 , @probinson 
> wrote:
>
>> This is pretty different from the "always desugar to the canonical type" 
>> habit that has always been in place. Sony has done some downstream things to 
>> try to work around that in the past. @wolfgangp will remember it better than 
>> I do, but I think we make some effort to preserve the type-as-written. This 
>> goes in completely the other direction.
>
> The Sony solution does not rely on a user-specified attribute, but uniformly 
> preserves all typedefs, though only in template argument types. Similar to 
> this solution, it adds a second type to keep track of the preferred type, 
> though it does so in the TemplateArgument structure as a separate QualType. A 
> client can then either print the preferred type or the canonical type, 
> depending on a printing policy, which is controlled by an option. This leads 
> to a similar result in the resulting DWARF, i.e. the DW_AT_type node gets the 
> preferred type string. The preferred type can also be used for diagnostic 
> messages.

Neat, thanks for outlining your approach. IIUC, this basically just replicates 
the `PrintingPolicy::UsePreferredNames` when printing the names of template 
specializations. But it works for all typedefs, not just those annotated with 
the attribute.

@probinson Sounds like Sony's solution also changes the `DW_AT_type` to a 
non-canonical form. Do you still have concerns with the direction of this 
patch? Would it cause any problems for you downstream?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, dblaikie.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With this patch, we now emit a `DW_AT_LLVM_preferred_name` for
the `[clang::preferred_name]]` attribute attached to a class template.

This is useful for consumers in case they want to display the
name in terms of the preferred name, e.g., LLDB's type-summaries.

For now this is behind an LLDB tuning.

E.g., for following code:

  template struct Foo;
  
  typedef Foo BarInt;
  typedef Foo BarDouble;
  
  template
  struct [[clang::preferred_name(BarInt),
   clang::preferred_name(BarDouble)]] Foo {};

...the generated DWARF with this patch looks as follows:

  0x006b:   DW_TAG_structure_type
  DW_AT_LLVM_preferred_name   (0x0082)
  DW_AT_name  ("Foo")
  
  0x0082:   DW_TAG_typedef
 DW_AT_type  (0x006b "Foo")
 DW_AT_name  ("BarInt")
  
  0x008d:   DW_TAG_structure_type
  DW_AT_LLVM_preferred_name   (0x00ab)
  DW_AT_name  ("Foo")
  
  0x00ab:   DW_TAG_typedef
  DW_AT_type  (0x008d "Foo")
  DW_AT_name  ("BarDouble")


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145077

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-preferred_name-alias-template.cpp
  clang/test/CodeGen/attr-preferred_name-typedef.cpp

Index: clang/test/CodeGen/attr-preferred_name-typedef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-typedef.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+typedef Foo BarInt;
+typedef Foo BarDouble;
+
+template
+struct [[clang::preferred_name(BarInt),
+ clang::preferred_name(BarDouble)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+
+// LLDB:  ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]])
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/test/CodeGen/attr-preferred_name-alias-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-alias-template.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar)]] Foo {};
+
+Foo varInt;
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -267,6 +267,11 @@
SmallVectorImpl &EltTys,
llvm::DIType *RecordTy);
 
+  /// Helper class that retrieves returns llvm::DIType the that
+  /// PreferredNameAttr attribute on \ref RD refers to. If no such
+  /// attribute exists, returns nullptr.
+  llvm::DIType * GetPreferredNameType(const CXXRecordDecl *RD, llvm::DIFile *Unit);
+
   /// Helper function for CollectCXXBases.
   /// Adds debug info entries for types in Bases that are not in SeenTypes.
   void CollectCXXBasesAux(
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1301,6 +1301,8 @@
   llvm::raw_svector_ostream OS(NS);
 
   auto PP = getPrintingPolicy();
+  // TODO: Not strictly needed for std::string?
+  PP.UsePreferredNames = CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB;
   Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
 
   // Disable PrintCanonicalTypes here because we want
@@ -2

[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 501540.
Michael137 added a comment.

- Remove redundant TODO


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-preferred_name-alias-template.cpp
  clang/test/CodeGen/attr-preferred_name-typedef.cpp

Index: clang/test/CodeGen/attr-preferred_name-typedef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-typedef.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+typedef Foo BarInt;
+typedef Foo BarDouble;
+
+template
+struct [[clang::preferred_name(BarInt),
+ clang::preferred_name(BarDouble)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+
+// LLDB:  ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]])
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/test/CodeGen/attr-preferred_name-alias-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-alias-template.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar)]] Foo {};
+
+Foo varInt;
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -267,6 +267,11 @@
SmallVectorImpl &EltTys,
llvm::DIType *RecordTy);
 
+  /// Helper class that retrieves returns llvm::DIType the that
+  /// PreferredNameAttr attribute on \ref RD refers to. If no such
+  /// attribute exists, returns nullptr.
+  llvm::DIType * GetPreferredNameType(const CXXRecordDecl *RD, llvm::DIFile *Unit);
+
   /// Helper function for CollectCXXBases.
   /// Adds debug info entries for types in Bases that are not in SeenTypes.
   void CollectCXXBasesAux(
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2576,6 +2576,18 @@
   return CreateTypeDefinition(Ty);
 }
 
+llvm::DIType * CGDebugInfo::GetPreferredNameType(
+const CXXRecordDecl *RD, llvm::DIFile *Unit) {
+  if (!RD)
+return nullptr;
+
+  auto const* PNA = RD->getAttr();
+  if (!PNA)
+return nullptr;
+
+  return getOrCreateType(PNA->getTypedefType(), Unit);
+}
+
 llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
   RecordDecl *RD = Ty->getDecl();
 
@@ -2630,6 +2642,9 @@
 FwdDecl =
 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
 
+  if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
+FwdDecl->replacePreferredName(GetPreferredNameType(CXXDecl, DefUnit));
+
   RegionMap[Ty->getDecl()].reset(FwdDecl);
   return FwdDecl;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 501544.
Michael137 added a comment.

- clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-preferred_name-alias-template.cpp
  clang/test/CodeGen/attr-preferred_name-typedef.cpp

Index: clang/test/CodeGen/attr-preferred_name-typedef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-typedef.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+typedef Foo BarInt;
+typedef Foo BarDouble;
+
+template
+struct [[clang::preferred_name(BarInt),
+ clang::preferred_name(BarDouble)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+
+// LLDB:  ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]])
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/test/CodeGen/attr-preferred_name-alias-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-alias-template.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar)]] Foo {};
+
+Foo varInt;
+Foo> varFooInt;
+
+// LLDB:  ![[FOO_FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo >"
+// GDB-NOT:   preferredName: ![[FOO_INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[FOO_INT_PREF:[0-9]+]])
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_INT]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "Bar >",
+// LLDB-SAME: baseType: ![[FOO_FOO_INT]])
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -267,6 +267,12 @@
SmallVectorImpl &EltTys,
llvm::DIType *RecordTy);
 
+  /// Helper class that retrieves returns llvm::DIType the that
+  /// PreferredNameAttr attribute on \ref RD refers to. If no such
+  /// attribute exists, returns nullptr.
+  llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD,
+ llvm::DIFile *Unit);
+
   /// Helper function for CollectCXXBases.
   /// Adds debug info entries for types in Bases that are not in SeenTypes.
   void CollectCXXBasesAux(
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2576,6 +2576,18 @@
   return CreateTypeDefinition(Ty);
 }
 
+llvm::DIType *CGDebugInfo::GetPreferredNameType(const CXXRecordDecl *RD,
+llvm::DIFile *Unit) {
+  if (!RD)
+return nullptr;
+
+  auto const *PNA = RD->getAttr();
+  if (!PNA)
+return nullptr;
+
+  return getOrCreateType(PNA->getTypedefType(), Unit);
+}
+
 llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
   RecordDecl *RD = Ty->getDecl();
 
@@ -2630,6 +2642,9 @@
 FwdDecl =
 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
 
+  if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
+FwdDecl->replacePreferredName(GetPreferredNameType(CXXDecl, DefUnit));
+
   RegionMap[Ty->getDecl()].reset(FwdDecl);
   return FwdDecl;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Since the new attribute only gets attached to a structure definition, and the 
preferred_name attribute is currently only really used in a handful of places 
in libcxx, this practically doesn't affect debug-info size


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

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


[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 501568.
Michael137 added a comment.

- Add test case for multiple alias templates


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-preferred_name-alias-template.cpp
  clang/test/CodeGen/attr-preferred_name-typedef.cpp

Index: clang/test/CodeGen/attr-preferred_name-typedef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-typedef.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template
+struct Foo;
+
+typedef Foo BarInt;
+typedef Foo BarDouble;
+
+template
+struct [[clang::preferred_name(BarInt),
+ clang::preferred_name(BarDouble)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+
+// LLDB:  ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]])
+
+// LLDB:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/test/CodeGen/attr-preferred_name-alias-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-alias-template.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=LLDB,COMMON
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=GDB,COMMON
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar),
+ clang::preferred_name(Bar)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+Foo varChar;
+
+// COMMON:  ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT: preferredName: [[#]]
+// LLDB-SAME:   preferredName: ![[DOUBLE_PREF:[0-9]+]]
+// COMMON-SAME: )
+
+// LLDB:  ![[DOUBLE_PREF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]]
+
+// COMMON:   !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:  preferredName: [[#]]
+// LLDB-NOT: preferredName: [[#]]
+// COMMON-SAME:  )
+
+// COMMON:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT: preferredName: [[#]]
+// LLDB-SAME:   preferredName: ![[INT_PREF:[0-9]+]]
+// COMMON-SAME: )
+
+// LLDB:  ![[INT_PREF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_INT]]
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -267,6 +267,12 @@
SmallVectorImpl &EltTys,
llvm::DIType *RecordTy);
 
+  /// Helper class that retrieves returns llvm::DIType the that
+  /// PreferredNameAttr attribute on \ref RD refers to. If no such
+  /// attribute exists, returns nullptr.
+  llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD,
+ llvm::DIFile *Unit);
+
   /// Helper function for CollectCXXBases.
   /// Adds debug info entries for types in Bases that are not in SeenTypes.
   void CollectCXXBasesAux(
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2576,6 +2576,18 @@
   return CreateTypeDefinition(Ty);
 }
 
+llvm::DIType *CGDebugInfo::GetPreferredNameType(const CXXRecordDecl *RD,
+llvm::DIFile *Unit) {
+  if (!RD)
+return nullptr;
+
+  auto const *PNA = RD->getAttr();
+  if (!PNA)
+return nullptr;
+
+  return getOrCreateType(PNA->getTypedefType(), Unit);
+}
+
 llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
   RecordDecl *RD = Ty->getDecl();
 
@@ -2630,6 +2642,9 @@
 FwdDecl =
 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
 
+  if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
+FwdDecl->replacePreferredName(GetPreferredNameType(CXXDecl, DefUnit));
+
   RegionMap[Ty->getDecl()].reset(FwdDecl);
   return FwdDecl;
 }
__

[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-01 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 501569.
Michael137 added a comment.

- Update test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/attr-preferred_name-alias-template.cpp
  clang/test/CodeGen/attr-preferred_name-typedef.cpp

Index: clang/test/CodeGen/attr-preferred_name-typedef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-typedef.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=LLDB,COMMON
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=GDB,COMMON
+
+template
+struct Foo;
+
+typedef Foo BarInt;
+typedef Foo BarDouble;
+typedef Foo BarChar;
+
+template
+struct [[clang::preferred_name(BarInt),
+ clang::preferred_name(BarDouble)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+Foo varChar;
+
+// COMMON:![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: [[#]]
+// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// COMMON:)
+
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]])
+
+// COMMON:!DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: [[#]]
+// LLDB-NOT:  preferredName: [[#]]
+// COMMON:)
+
+// COMMON:![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:   preferredName: [[#]]
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// COMMON:)
+
+// LLDB:  !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt",
+// LLDB-SAME: baseType: ![[FOO_INT]])
Index: clang/test/CodeGen/attr-preferred_name-alias-template.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-preferred_name-alias-template.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=LLDB,COMMON
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=GDB,COMMON
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar),
+ clang::preferred_name(Bar)]] Foo {};
+
+Foo varInt;
+Foo varDouble;
+Foo varChar;
+
+// COMMON:  ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT: preferredName: [[#]]
+// LLDB-SAME:   preferredName: ![[DOUBLE_PREF:[0-9]+]]
+// COMMON-SAME: )
+
+// LLDB:  ![[DOUBLE_PREF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]]
+
+// COMMON:   !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT:  preferredName: [[#]]
+// LLDB-NOT: preferredName: [[#]]
+// COMMON-SAME:  )
+
+// COMMON:  ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB-NOT: preferredName: [[#]]
+// LLDB-SAME:   preferredName: ![[INT_PREF:[0-9]+]]
+// COMMON-SAME: )
+
+// LLDB:  ![[INT_PREF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar",
+// LLDB-SAME: baseType: ![[FOO_INT]]
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -267,6 +267,12 @@
SmallVectorImpl &EltTys,
llvm::DIType *RecordTy);
 
+  /// Helper class that retrieves returns llvm::DIType the that
+  /// PreferredNameAttr attribute on \ref RD refers to. If no such
+  /// attribute exists, returns nullptr.
+  llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD,
+ llvm::DIFile *Unit);
+
   /// Helper function for CollectCXXBases.
   /// Adds debug info entries for types in Bases that are not in SeenTypes.
   void CollectCXXBasesAux(
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2576,6 +2576,18 @@
   return CreateTypeDefinition(Ty);
 }
 
+llvm::DIType *CGDebugInfo::GetPreferredNameType(const CXXRecordDecl *RD,
+llvm::DIFile *Unit) {
+  if (!RD)
+return nullptr;
+
+  auto const *PNA = RD->getAttr();
+  if (!PNA)
+return nullptr;
+
+  return getOrCreateType(PNA->getTypedefType(), Unit);
+}
+
 llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
   RecordDecl *RD = Ty->getDecl();
 
@@ -2630,6 +2642,9 @@
 FwdDecl =
 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
 
+  if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind:

[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-10 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a project: All.
Michael137 added a comment.
Michael137 updated this revision to Diff 504274.
Michael137 updated this revision to Diff 504276.
Michael137 edited the summary of this revision.
Michael137 added a reviewer: dblaikie.
Michael137 published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Yet another alternative for emitting preferred_names.

Makes the attribute introduced in https://reviews.llvm.org/D145077 redundant. 
Also doesn't require any changes to LLDB (making 
https://reviews.llvm.org/D145078 redundant, which got a bit hairy)


aprantl added a comment.

This seems to be a much simpler implementation that just automatically works. I 
think I'd prefer that over adding new DWARF attributes.


Michael137 added a comment.

- Add test


Michael137 added a comment.

- Update commit message


[clang][DebugInfo] Emit DW_AT_type of preferred name if available

With this patch, whenever we emit a `DW_AT_type` for some declaration
and the type is a template class with a `clang::PreferredNameAttr`, we
will emit the typedef that the attribute refers to instead. I.e.,

  0x123 DW_TAG_variable
  DW_AT_name "var"
  DW_AT_type (0x123 "basic_string")
  
  0x124 DW_TAG_structure_type
  DW_AT_name "basic_string"

...becomes

  0x123 DW_TAG_variable
  DW_AT_name "var"
  DW_AT_type (0x124 "std::string")
  
  0x124 DW_TAG_structure_type
  DW_AT_name "basic_string"
  
  0x125 DW_TAG_typedef
  DW_AT_name "std::string"
  DW_AT_type (0x124 "basic_string")

For now we keep this behind LLDB tuning.

**Testing**

- Added clang unit-test
- `check-llvm`, `check-clang` pass
- Confirmed that this change correctly repoints

`basic_string` references in some of my test programs.

- Will add follow-up LLDB API tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145803

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/preferred_name.cpp

Index: clang/test/CodeGen/preferred_name.cpp
===
--- /dev/null
+++ clang/test/CodeGen/preferred_name.cpp
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=standalone -debugger-tuning=lldb %s | FileCheck %s --check-prefixes=COMMON,LLDB
+// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=standalone -debugger-tuning=gdb %s | FileCheck %s --check-prefixes=COMMON,GDB
+
+template 
+struct Foo;
+
+typedef Foo BarInt;
+typedef Foo BarDouble;
+
+template 
+using Bar = Foo;
+
+template 
+struct [[clang::preferred_name(BarInt),
+ clang::preferred_name(BarDouble),
+ clang::preferred_name(Bar),
+ clang::preferred_name(Bar)]] Foo{
+ };
+
+int main() {
+Foo varInt;
+
+// COMMON: !DILocalVariable(name: "varInt", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_INT_TY:[0-9]+]])
+// LLDB:   ![[BAR_INT_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt", file: ![[#]], line: [[#]], baseType: ![[BAR_INT_BASE:[0-9]+]])
+// LLDB:   ![[BAR_INT_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: ![[#]], line: [[#]], size: [[#]]
+// GDB:![[BAR_INT_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: ![[#]], line: [[#]], size: [[#]]
+
+Foo varDouble;
+
+// COMMON: !DILocalVariable(name: "varDouble", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_DOUBLE_TY:[0-9]+]])
+// LLDB:   ![[BAR_DOUBLE_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble", file: ![[#]], line: [[#]], baseType: ![[BAR_DOUBLE_BASE:[0-9]+]])
+// LLDB:   ![[BAR_DOUBLE_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB:![[BAR_DOUBLE_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+
+Foo varShort;
+
+// COMMON: !DILocalVariable(name: "varShort", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_SHORT_TY:[0-9]+]])
+// LLDB:   ![[BAR_SHORT_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", file: ![[#]], line: [[#]], baseType: ![[BAR_SHORT_BASE:[0-9]+]])
+// LLDB:   ![[BAR_SHORT_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB:![[BAR_SHORT_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+
+Foo varChar;
+
+// COMMON: !DILocalVariable(name: "varChar", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_CHAR_TY:[0-9]+]])
+// LLDB:   ![[BAR_CHAR_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", file: ![[#]], line: [[#]], baseType: ![[BAR_CHAR_BASE:[0-9]+]])
+// LLDB:   ![[BAR_CHAR_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+// GDB:![[BAR_CHAR_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+
+Foo> varFooInt;
+
+// COMMON: !DILocalVariable(name: "varFooInt", scope: ![[#]], file: ![[#]], line: [[#]

[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

2023-03-10 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Making use of this in LLDB (see https://reviews.llvm.org/D145078) was a bit too 
finicky for my taste, so I prepared an alternative which doesn't require adding 
a new attribute and no LLDB changes. I *think* this is what @aprantl and 
@dblaikie had in mind couple of weeks back


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145077

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-11 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D145803#4186805 , @dblaikie wrote:

> Yeah, can't say this had occurred to me - but totally makes sense/reckon it's 
> OK. Any reason to limit this to lldb? I'd expect it'd probably "Just 
> Work(tm)" on any DWARF consumer?

No particular reason other than being on the safe side and get field experience 
before enabling it for all consumers. But I agree, I don't see why this 
couldn't be enabled always.

> it doesn't hit any recursion issues? (I guess maybe skirts it due to the 
> existing recursion handling in the decl/def structure type stuff - so it 
> creates a declaration for the type, then creates the typedef, which can find 
> that existing declaration, then return the typedef from the create type 
> query?)

Yup that's the intention

> I guess it means that references to the type even for like, the type of the 
> "this" parameter - would refer to the typedef? That's /probably/ OK if a bit 
> surprising to some people/consumers sometimes?

Good point, it does also repoint the `this` pointer to the typedef. LLDB seems 
to handle this fine. Can add some test cases for this (in Clang and LLDB)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-03-11 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Apparently some Objective-C/gmodules LLDB tests aren't happy with this change
Investigating...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D153282: [clang][DebugInfo] Emit DW_AT_deleted on any deleted member function

2023-06-19 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, dblaikie.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Currently we emit `DW_AT_deleted` for `deleted` special-member
functions (i.e., ctors/dtors). However, in C++ one can mark any
member function as deleted. This patch expands the set of member
functions for which we emit `DW_AT_deleted`.

The DWARFv5 spec section 5.7.8 says:

  
  In C++, a member function may be declared as deleted. This prevents the 
compiler from
  generating a default implementation of a special member function such as a 
constructor
  or destructor, and can affect overload resolution when used on other member 
functions.
  
  
  If the member function entry has been declared as deleted, then that entry 
has a
  DW_AT_deleted attribute.

Thus this change is conforming.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153282

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-deleted.cpp
  llvm/test/DebugInfo/X86/DW_AT_deleted.ll

Index: llvm/test/DebugInfo/X86/DW_AT_deleted.ll
===
--- llvm/test/DebugInfo/X86/DW_AT_deleted.ll
+++ llvm/test/DebugInfo/X86/DW_AT_deleted.ll
@@ -12,6 +12,9 @@
 ; 
 ;   deleted(deleted &&) = delete;
 ;   deleted &operator=(deleted &&) = delete;
+;
+;   void func() && {}
+;   static void bar() = delete;
 ; 
 ;   ~deleted() = default;
 ; };
@@ -48,6 +51,16 @@
 ; CHECK-NEXT: DW_AT_name [DW_FORM_strx1](indexed (0008) string = "operator=")
 ; CHECK:  DW_AT_deleted [DW_FORM_flag_present]  (true)
 
+; CHECK: DW_TAG_subprogram [10]
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed (000b) string = "_ZNO7deleted4funcEv")
+; CHECK-NEXT: DW_AT_name [DW_FORM_strx1](indexed (000c) string = "func")
+; CHECK:  DW_AT_deleted [DW_FORM_flag_present]  (true)
+
+; CHECK: DW_TAG_subprogram [11]
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed (000d) string = "_ZN7deleted3barEv")
+; CHECK-NEXT: DW_AT_name [DW_FORM_strx1](indexed (000e) string = "bar")
+; CHECK:  DW_AT_deleted [DW_FORM_flag_present]  (true)
+
 ; ModuleID = 'debug-info-deleted.cpp'
 source_filename = "debug-info-deleted.cpp"
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
@@ -58,8 +71,8 @@
 ; Function Attrs: noinline nounwind optnone uwtable
 define dso_local void @_Z3foov() #0 !dbg !7 {
   %1 = alloca %class.deleted, align 1
-  call void @llvm.dbg.declare(metadata ptr %1, metadata !10, metadata !DIExpression()), !dbg !34
-  ret void, !dbg !35
+  call void @llvm.dbg.declare(metadata ptr %1, metadata !10, metadata !DIExpression()), !dbg !39
+  ret void, !dbg !40
 }
 
 ; Function Attrs: nounwind readnone speculatable willreturn
@@ -84,7 +97,7 @@
 !9 = !{null}
 !10 = !DILocalVariable(name: "obj1", scope: !7, file: !1, line: 15, type: !11)
 !11 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "deleted", file: !1, line: 1, size: 8, flags: DIFlagTypePassByReference, elements: !12, identifier: "_ZTS7deleted")
-!12 = !{!13, !17, !22, !26, !30, !33}
+!12 = !{!13, !17, !22, !26, !30, !33, !34, !36}
 !13 = !DISubprogram(name: "deleted", scope: !11, file: !1, line: 3, type: !14, scopeLine: 3, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0)
 !14 = !DISubroutineType(types: !15)
 !15 = !{null, !16}
@@ -106,5 +119,10 @@
 !31 = !DISubroutineType(types: !32)
 !32 = !{!25, !16, !29}
 !33 = !DISubprogram(name: "~deleted", scope: !11, file: !1, line: 11, type: !14, scopeLine: 11, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0)
-!34 = !DILocation(line: 15, column: 13, scope: !7)
-!35 = !DILocation(line: 16, column: 3, scope: !7)
+!34 = !DISubprogram(name: "func", linkageName: "_ZNO7deleted4funcEv", scope: !11, file: !1, line: 13, type: !35, scopeLine: 13, flags: DIFlagPublic | DIFlagPrototyped | DIFlagRValueReference, spFlags: DISPFlagDeleted)   
+!35 = !DISubroutineType(flags: DIFlagRValueReference, types: !15) 
+!36 = !DISubprogram(name: "bar", linkageName: "_ZN7deleted3barEv", scope: !11, file: !1, line: 15, type: !37, scopeLine: 15, flags: DIFlagPublic | DIFlagPrototyped | DIFlagStaticMember, spFlags: DISPFlagDeleted) 
+!37 = !DISubroutineType(types: !38)
+!38 = !{null}
+!39 = !DILocation(line: 15, column: 13, scope: !7)
+!40 = !

[PATCH] D153282: [clang][DebugInfo] Emit DW_AT_deleted on any deleted member function

2023-06-19 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 532664.
Michael137 added a comment.

- fix test comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153282

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-deleted.cpp
  llvm/test/DebugInfo/X86/DW_AT_deleted.ll

Index: llvm/test/DebugInfo/X86/DW_AT_deleted.ll
===
--- llvm/test/DebugInfo/X86/DW_AT_deleted.ll
+++ llvm/test/DebugInfo/X86/DW_AT_deleted.ll
@@ -12,6 +12,9 @@
 ; 
 ;   deleted(deleted &&) = delete;
 ;   deleted &operator=(deleted &&) = delete;
+;
+;   void func() && = delete;
+;   static void bar() = delete;
 ; 
 ;   ~deleted() = default;
 ; };
@@ -48,6 +51,16 @@
 ; CHECK-NEXT: DW_AT_name [DW_FORM_strx1](indexed (0008) string = "operator=")
 ; CHECK:  DW_AT_deleted [DW_FORM_flag_present]  (true)
 
+; CHECK: DW_TAG_subprogram [10]
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed (000b) string = "_ZNO7deleted4funcEv")
+; CHECK-NEXT: DW_AT_name [DW_FORM_strx1](indexed (000c) string = "func")
+; CHECK:  DW_AT_deleted [DW_FORM_flag_present]  (true)
+
+; CHECK: DW_TAG_subprogram [11]
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed (000d) string = "_ZN7deleted3barEv")
+; CHECK-NEXT: DW_AT_name [DW_FORM_strx1](indexed (000e) string = "bar")
+; CHECK:  DW_AT_deleted [DW_FORM_flag_present]  (true)
+
 ; ModuleID = 'debug-info-deleted.cpp'
 source_filename = "debug-info-deleted.cpp"
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
@@ -58,8 +71,8 @@
 ; Function Attrs: noinline nounwind optnone uwtable
 define dso_local void @_Z3foov() #0 !dbg !7 {
   %1 = alloca %class.deleted, align 1
-  call void @llvm.dbg.declare(metadata ptr %1, metadata !10, metadata !DIExpression()), !dbg !34
-  ret void, !dbg !35
+  call void @llvm.dbg.declare(metadata ptr %1, metadata !10, metadata !DIExpression()), !dbg !39
+  ret void, !dbg !40
 }
 
 ; Function Attrs: nounwind readnone speculatable willreturn
@@ -84,7 +97,7 @@
 !9 = !{null}
 !10 = !DILocalVariable(name: "obj1", scope: !7, file: !1, line: 15, type: !11)
 !11 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "deleted", file: !1, line: 1, size: 8, flags: DIFlagTypePassByReference, elements: !12, identifier: "_ZTS7deleted")
-!12 = !{!13, !17, !22, !26, !30, !33}
+!12 = !{!13, !17, !22, !26, !30, !33, !34, !36}
 !13 = !DISubprogram(name: "deleted", scope: !11, file: !1, line: 3, type: !14, scopeLine: 3, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0)
 !14 = !DISubroutineType(types: !15)
 !15 = !{null, !16}
@@ -106,5 +119,10 @@
 !31 = !DISubroutineType(types: !32)
 !32 = !{!25, !16, !29}
 !33 = !DISubprogram(name: "~deleted", scope: !11, file: !1, line: 11, type: !14, scopeLine: 11, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0)
-!34 = !DILocation(line: 15, column: 13, scope: !7)
-!35 = !DILocation(line: 16, column: 3, scope: !7)
+!34 = !DISubprogram(name: "func", linkageName: "_ZNO7deleted4funcEv", scope: !11, file: !1, line: 13, type: !35, scopeLine: 13, flags: DIFlagPublic | DIFlagPrototyped | DIFlagRValueReference, spFlags: DISPFlagDeleted)   
+!35 = !DISubroutineType(flags: DIFlagRValueReference, types: !15) 
+!36 = !DISubprogram(name: "bar", linkageName: "_ZN7deleted3barEv", scope: !11, file: !1, line: 15, type: !37, scopeLine: 15, flags: DIFlagPublic | DIFlagPrototyped | DIFlagStaticMember, spFlags: DISPFlagDeleted) 
+!37 = !DISubroutineType(types: !38)
+!38 = !{null}
+!39 = !DILocation(line: 15, column: 13, scope: !7)
+!40 = !DILocation(line: 16, column: 3, scope: !7)
Index: clang/test/CodeGenCXX/debug-info-deleted.cpp
===
--- clang/test/CodeGenCXX/debug-info-deleted.cpp
+++ clang/test/CodeGenCXX/debug-info-deleted.cpp
@@ -11,6 +11,8 @@
 // ATTR: DISubprogram(name: "operator=", linkageName: "_ZN7deletedaSERKS_", {{.*}}, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagDeleted
 // ATTR: DISubprogram(name: "deleted", {{.*}}, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagDeleted
 // ATTR: DISubprogram(name: "operator=", linkageName: "_ZN7deletedaSEOS_", {{.*}}, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagDeleted
+// ATTR: DISubprogram(name: "func", {{.*}}, flags: DIFlagPublic | DIFlagPrototype

[PATCH] D153282: [clang][DebugInfo] Emit DW_AT_deleted on any deleted member function

2023-06-20 Thread Michael Buch via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc146df961876: [clang][DebugInfo] Emit DW_AT_deleted on any 
deleted member function (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153282

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-deleted.cpp
  llvm/test/DebugInfo/X86/DW_AT_deleted.ll

Index: llvm/test/DebugInfo/X86/DW_AT_deleted.ll
===
--- llvm/test/DebugInfo/X86/DW_AT_deleted.ll
+++ llvm/test/DebugInfo/X86/DW_AT_deleted.ll
@@ -12,6 +12,9 @@
 ; 
 ;   deleted(deleted &&) = delete;
 ;   deleted &operator=(deleted &&) = delete;
+;
+;   void func() && = delete;
+;   static void bar() = delete;
 ; 
 ;   ~deleted() = default;
 ; };
@@ -48,6 +51,16 @@
 ; CHECK-NEXT: DW_AT_name [DW_FORM_strx1](indexed (0008) string = "operator=")
 ; CHECK:  DW_AT_deleted [DW_FORM_flag_present]  (true)
 
+; CHECK: DW_TAG_subprogram [10]
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed (000b) string = "_ZNO7deleted4funcEv")
+; CHECK-NEXT: DW_AT_name [DW_FORM_strx1](indexed (000c) string = "func")
+; CHECK:  DW_AT_deleted [DW_FORM_flag_present]  (true)
+
+; CHECK: DW_TAG_subprogram [11]
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed (000d) string = "_ZN7deleted3barEv")
+; CHECK-NEXT: DW_AT_name [DW_FORM_strx1](indexed (000e) string = "bar")
+; CHECK:  DW_AT_deleted [DW_FORM_flag_present]  (true)
+
 ; ModuleID = 'debug-info-deleted.cpp'
 source_filename = "debug-info-deleted.cpp"
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
@@ -58,8 +71,8 @@
 ; Function Attrs: noinline nounwind optnone uwtable
 define dso_local void @_Z3foov() #0 !dbg !7 {
   %1 = alloca %class.deleted, align 1
-  call void @llvm.dbg.declare(metadata ptr %1, metadata !10, metadata !DIExpression()), !dbg !34
-  ret void, !dbg !35
+  call void @llvm.dbg.declare(metadata ptr %1, metadata !10, metadata !DIExpression()), !dbg !39
+  ret void, !dbg !40
 }
 
 ; Function Attrs: nounwind readnone speculatable willreturn
@@ -84,7 +97,7 @@
 !9 = !{null}
 !10 = !DILocalVariable(name: "obj1", scope: !7, file: !1, line: 15, type: !11)
 !11 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "deleted", file: !1, line: 1, size: 8, flags: DIFlagTypePassByReference, elements: !12, identifier: "_ZTS7deleted")
-!12 = !{!13, !17, !22, !26, !30, !33}
+!12 = !{!13, !17, !22, !26, !30, !33, !34, !36}
 !13 = !DISubprogram(name: "deleted", scope: !11, file: !1, line: 3, type: !14, scopeLine: 3, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0)
 !14 = !DISubroutineType(types: !15)
 !15 = !{null, !16}
@@ -106,5 +119,10 @@
 !31 = !DISubroutineType(types: !32)
 !32 = !{!25, !16, !29}
 !33 = !DISubprogram(name: "~deleted", scope: !11, file: !1, line: 11, type: !14, scopeLine: 11, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0)
-!34 = !DILocation(line: 15, column: 13, scope: !7)
-!35 = !DILocation(line: 16, column: 3, scope: !7)
+!34 = !DISubprogram(name: "func", linkageName: "_ZNO7deleted4funcEv", scope: !11, file: !1, line: 13, type: !35, scopeLine: 13, flags: DIFlagPublic | DIFlagPrototyped | DIFlagRValueReference, spFlags: DISPFlagDeleted)   
+!35 = !DISubroutineType(flags: DIFlagRValueReference, types: !15) 
+!36 = !DISubprogram(name: "bar", linkageName: "_ZN7deleted3barEv", scope: !11, file: !1, line: 15, type: !37, scopeLine: 15, flags: DIFlagPublic | DIFlagPrototyped | DIFlagStaticMember, spFlags: DISPFlagDeleted) 
+!37 = !DISubroutineType(types: !38)
+!38 = !{null}
+!39 = !DILocation(line: 15, column: 13, scope: !7)
+!40 = !DILocation(line: 16, column: 3, scope: !7)
Index: clang/test/CodeGenCXX/debug-info-deleted.cpp
===
--- clang/test/CodeGenCXX/debug-info-deleted.cpp
+++ clang/test/CodeGenCXX/debug-info-deleted.cpp
@@ -11,6 +11,8 @@
 // ATTR: DISubprogram(name: "operator=", linkageName: "_ZN7deletedaSERKS_", {{.*}}, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagDeleted
 // ATTR: DISubprogram(name: "deleted", {{.*}}, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagDeleted
 // ATTR: DISubprogram(name: "operator=", linkageName: "_ZN7deletedaSEOS_", {{.*}}, flags: DIFlagPublic | DIFlagPrototyped, sp

[PATCH] D153362: [clang][DebugInfo] Emit DW_AT_defaulted for defaulted C++ member functions

2023-06-20 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: dblaikie, aprantl.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch implements the DWARFv5 feature where a
`DW_AT_defaulted` is attached to `DW_TAG_subprogram`s
which are explicitly defaulted in C++, i.e., member
functions such as the following:

  class C {
C() = default;
~C() = default;
  };

We add two new `spFlags`, one for each possible value of
`DW_AT_defaulted` (see table in section 5.7.8 of DWARFv5
specification).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153362

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-defaulted.cpp
  llvm/include/llvm/IR/DebugInfoFlags.def
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/DW_AT_defaulted.ll

Index: llvm/test/DebugInfo/DW_AT_defaulted.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/DW_AT_defaulted.ll
@@ -0,0 +1,130 @@
+; RUN: llc < %s -filetype=obj -o %t
+; RUN: llvm-dwarfdump -v %t | FileCheck %s
+
+; C++ source to regenerate:
+; struct defaulted {
+;   // inline defaulted
+;   defaulted() = default;
+; 
+;   // out-of-line defaulted (inline keyword
+;   // shouldn't change that)
+;   inline ~defaulted();
+; 
+;   // These shouldn't produce a defaulted-ness DI flag
+;   // (though technically they are DW_DEFAULTED_no)
+;   defaulted& operator=(defaulted const&) { return *this; }
+;   defaulted& operator=(defaulted &&);
+; 
+;   bool operator==(defaulted const&) const = default;
+; };
+; 
+; defaulted::~defaulted() = default;
+; defaulted& defaulted::operator=(defaulted &&) { return *this; }
+; 
+; void foo() {
+;   defaulted d;
+; }
+; $ clang++ -O0 -g -gdwarf-5 debug-info-defaulted.cpp -c
+
+; CHECK: .debug_info contents:
+
+; CHECK:  DW_TAG_structure_type
+; CHECK:DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "defaulted")
+
+; CHECK:DW_TAG_subprogram [5]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "defaulted")
+; CHECK:  DW_AT_defaulted [DW_FORM_data1]	(DW_DEFAULTED_in_class)
+; CHECK:  NULL
+
+; CHECK:DW_TAG_subprogram [5]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "~defaulted")
+; CHECK:  DW_AT_defaulted [DW_FORM_data1]	(DW_DEFAULTED_out_of_class)
+; CHECK:  NULL
+
+; CHECK:DW_TAG_subprogram [7]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "operator=")
+; CHECK-NOT:  DW_AT_defaulted
+; CHECK:  NULL
+
+; CHECK:DW_TAG_subprogram [7]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "operator=")
+; CHECK-NOT:  DW_AT_defaulted
+; CHECK:  NULL
+
+; CHECK:DW_TAG_subprogram [9]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "operator==")
+; CHECK:  DW_AT_defaulted [DW_FORM_data1]	(DW_DEFAULTED_in_class)
+; CHECK:  NULL
+
+; CHECK:NULL
+
+%struct.defaulted = type { i8 }
+
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+define void @_Z3foov() !dbg !39 {
+entry:
+  %d = alloca %struct.defaulted, align 1
+  call void @llvm.dbg.declare(metadata ptr %d, metadata !42, metadata !DIExpression()), !dbg !43
+  ret void, !dbg !47
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.linker.options = !{}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
+!1 = !DIFile(filename: "../llvm-project/clang/test/CodeGenCXX/debug-info-defaulted.cpp", directory: "/tmp", checksumkind: CSK_MD5, checksum: "ee982c44dd268333101243e050103fb8")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 8, !"PIC Level", i32 2}
+!6 = !{i32 7, !"uwtable", i32 1}
+!7 = !{i32 7, !"frame-pointer", i32 1}
+!8 = !{!"clang version 17.0.0"}
+!9 = distinct !DISubprogram(name: "operator=", linkageName: "_ZN9defaultedaSEOS_", scope: !10, file: !1, line: 29, type: !24, scopeLine: 29, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !23, retainedNodes: !32)
+!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "defaulted", file: !1, line: 12, size: 8, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !11, identifier: "_ZTS9defaulted")
+!11 = !{!12, !16, !17, !23, !27}
+!12 = !DISubprogram(name: "defaulted", scope: !10, file: !1, line: 14, type: !13, scopeLine: 14, flags: DIFlagPrototyped, spFlags: DISPFlagDefaultedInClass)
+!13 = !DISubroutineType(types: !14)
+!14 = !{null, !15}
+!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size:

[PATCH] D153362: [clang][DebugInfo] Emit DW_AT_defaulted for defaulted C++ member functions

2023-06-20 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 532952.
Michael137 added a comment.
Herald added a subscriber: ormris.

- remove redundant includes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153362

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-defaulted.cpp
  llvm/include/llvm/IR/DebugInfoFlags.def
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/DW_AT_defaulted.ll

Index: llvm/test/DebugInfo/DW_AT_defaulted.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/DW_AT_defaulted.ll
@@ -0,0 +1,130 @@
+; RUN: llc < %s -filetype=obj -o %t
+; RUN: llvm-dwarfdump -v %t | FileCheck %s
+
+; C++ source to regenerate:
+; struct defaulted {
+;   // inline defaulted
+;   defaulted() = default;
+; 
+;   // out-of-line defaulted (inline keyword
+;   // shouldn't change that)
+;   inline ~defaulted();
+; 
+;   // These shouldn't produce a defaulted-ness DI flag
+;   // (though technically they are DW_DEFAULTED_no)
+;   defaulted& operator=(defaulted const&) { return *this; }
+;   defaulted& operator=(defaulted &&);
+; 
+;   bool operator==(defaulted const&) const = default;
+; };
+; 
+; defaulted::~defaulted() = default;
+; defaulted& defaulted::operator=(defaulted &&) { return *this; }
+; 
+; void foo() {
+;   defaulted d;
+; }
+; $ clang++ -O0 -g -gdwarf-5 debug-info-defaulted.cpp -c
+
+; CHECK: .debug_info contents:
+
+; CHECK:  DW_TAG_structure_type
+; CHECK:DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "defaulted")
+
+; CHECK:DW_TAG_subprogram [5]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "defaulted")
+; CHECK:  DW_AT_defaulted [DW_FORM_data1]	(DW_DEFAULTED_in_class)
+; CHECK:  NULL
+
+; CHECK:DW_TAG_subprogram [5]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "~defaulted")
+; CHECK:  DW_AT_defaulted [DW_FORM_data1]	(DW_DEFAULTED_out_of_class)
+; CHECK:  NULL
+
+; CHECK:DW_TAG_subprogram [7]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "operator=")
+; CHECK-NOT:  DW_AT_defaulted
+; CHECK:  NULL
+
+; CHECK:DW_TAG_subprogram [7]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "operator=")
+; CHECK-NOT:  DW_AT_defaulted
+; CHECK:  NULL
+
+; CHECK:DW_TAG_subprogram [9]
+; CHECK:  DW_AT_name [DW_FORM_strx1]	(indexed ({{.*}}) string = "operator==")
+; CHECK:  DW_AT_defaulted [DW_FORM_data1]	(DW_DEFAULTED_in_class)
+; CHECK:  NULL
+
+; CHECK:NULL
+
+%struct.defaulted = type { i8 }
+
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+define void @_Z3foov() !dbg !39 {
+entry:
+  %d = alloca %struct.defaulted, align 1
+  call void @llvm.dbg.declare(metadata ptr %d, metadata !42, metadata !DIExpression()), !dbg !43
+  ret void, !dbg !47
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.linker.options = !{}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
+!1 = !DIFile(filename: "../llvm-project/clang/test/CodeGenCXX/debug-info-defaulted.cpp", directory: "/tmp", checksumkind: CSK_MD5, checksum: "ee982c44dd268333101243e050103fb8")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 8, !"PIC Level", i32 2}
+!6 = !{i32 7, !"uwtable", i32 1}
+!7 = !{i32 7, !"frame-pointer", i32 1}
+!8 = !{!"clang version 17.0.0"}
+!9 = distinct !DISubprogram(name: "operator=", linkageName: "_ZN9defaultedaSEOS_", scope: !10, file: !1, line: 29, type: !24, scopeLine: 29, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !23, retainedNodes: !32)
+!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "defaulted", file: !1, line: 12, size: 8, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !11, identifier: "_ZTS9defaulted")
+!11 = !{!12, !16, !17, !23, !27}
+!12 = !DISubprogram(name: "defaulted", scope: !10, file: !1, line: 14, type: !13, scopeLine: 14, flags: DIFlagPrototyped, spFlags: DISPFlagDefaultedInClass)
+!13 = !DISubroutineType(types: !14)
+!14 = !{null, !15}
+!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!16 = !DISubprogram(name: "~defaulted", scope: !10, file: !1, line: 18, type: !13, scopeLine: 18, flags: DIFlagPrototyped, spFlags: DISPFlagDefaultedOutOfClass)
+!17 = !DISubprogram(name: "operator=", linkageName: "_ZN9defaultedaSERKS_", scope: !10, file: !1, line: 22, type: !18, scopeLine: 22, flags: DIFlagPrototyped, spFlags: 0)
+!18 = !DISubroutineType(types: !19)
+!19 = !{!20, !15, !21}
+!20 =

[PATCH] D153362: [clang][DebugInfo] Emit DW_AT_defaulted for defaulted C++ member functions

2023-06-20 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 532957.
Michael137 added a comment.

- clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153362

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-defaulted.cpp


Index: clang/test/CodeGenCXX/debug-info-defaulted.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-defaulted.cpp
@@ -0,0 +1,38 @@
+// Test for debug info for C++ defaulted member functions
+
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu %s -o - \
+// RUN:   -O0 -debug-info-kind=standalone -std=c++20 | FileCheck %s
+
+// CHECK: DISubprogram(name: "defaulted", {{.*}}, flags: DIFlagPrototyped, 
spFlags: DISPFlagDefaultedInClass)
+// CHECK: DISubprogram(name: "~defaulted", {{.*}}, flags: 
DIFlagPrototyped, spFlags: DISPFlagDefaultedOutOfClass)
+// CHECK: DISubprogram(name: "operator=", {{.*}}, flags: DIFlagPrototyped, 
spFlags: 0)
+// CHECK: DISubprogram(name: "operator=", {{.*}}, flags: DIFlagPrototyped, 
spFlags: 0)
+// CHECK: DISubprogram(name: "operator==", {{.*}}, flags: 
DIFlagPrototyped, spFlags: DISPFlagDefaultedInClass)
+// CHECK-NOT: DISubprogram(name: "implicit_defaulted"
+struct defaulted {
+  // inline defaulted
+  defaulted() = default;
+
+  // out-of-line defaulted (inline keyword
+  // shouldn't change that)
+  inline ~defaulted();
+
+  // These shouldn't produce a defaulted-ness DI flag
+  // (though technically they are DW_DEFAULTED_no)
+  defaulted& operator=(defaulted const&) { return *this; }
+  defaulted& operator=(defaulted &&);
+
+  bool operator==(defaulted const&) const = default;
+};
+
+defaulted::~defaulted() = default;
+defaulted& defaulted::operator=(defaulted &&) { return *this; }
+
+// All ctors/dtors are implicitly defatuled.
+// So no DW_AT_defaulted expected for these.
+struct implicit_defaulted {};
+
+void foo() {
+  defaulted d;
+  implicit_defaulted i;
+}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1948,6 +1948,14 @@
   if (Method->getCanonicalDecl()->isDeleted())
 SPFlags |= llvm::DISubprogram::SPFlagDeleted;
 
+  // The defaulted-ness of an out-of-class method is a property of its
+  // definition. Hence, query the definition instead.
+  if (auto const *Def = Method->getDefinition())
+if (Def->isExplicitlyDefaulted())
+  SPFlags |= (Def->isOutOfLine())
+ ? llvm::DISubprogram::SPFlagDefaultedOutOfClass
+ : llvm::DISubprogram::SPFlagDefaultedInClass;
+
   if (Method->isNoReturn())
 Flags |= llvm::DINode::FlagNoReturn;
 


Index: clang/test/CodeGenCXX/debug-info-defaulted.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-defaulted.cpp
@@ -0,0 +1,38 @@
+// Test for debug info for C++ defaulted member functions
+
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu %s -o - \
+// RUN:   -O0 -debug-info-kind=standalone -std=c++20 | FileCheck %s
+
+// CHECK: DISubprogram(name: "defaulted", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagDefaultedInClass)
+// CHECK: DISubprogram(name: "~defaulted", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagDefaultedOutOfClass)
+// CHECK: DISubprogram(name: "operator=", {{.*}}, flags: DIFlagPrototyped, spFlags: 0)
+// CHECK: DISubprogram(name: "operator=", {{.*}}, flags: DIFlagPrototyped, spFlags: 0)
+// CHECK: DISubprogram(name: "operator==", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagDefaultedInClass)
+// CHECK-NOT: DISubprogram(name: "implicit_defaulted"
+struct defaulted {
+  // inline defaulted
+  defaulted() = default;
+
+  // out-of-line defaulted (inline keyword
+  // shouldn't change that)
+  inline ~defaulted();
+
+  // These shouldn't produce a defaulted-ness DI flag
+  // (though technically they are DW_DEFAULTED_no)
+  defaulted& operator=(defaulted const&) { return *this; }
+  defaulted& operator=(defaulted &&);
+
+  bool operator==(defaulted const&) const = default;
+};
+
+defaulted::~defaulted() = default;
+defaulted& defaulted::operator=(defaulted &&) { return *this; }
+
+// All ctors/dtors are implicitly defatuled.
+// So no DW_AT_defaulted expected for these.
+struct implicit_defaulted {};
+
+void foo() {
+  defaulted d;
+  implicit_defaulted i;
+}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1948,6 +1948,14 @@
   if (Method->getCanonicalDecl()->isDeleted())
 SPFlags |= llvm::DISubprogram::SPFlagDeleted;
 
+  // The defaulted-ness of an out-of-class method is a property of its
+  // definition. Hence, query the definition instead.
+  if (auto const *D

[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-03-30 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1482
+if (prev_base) {
+  clang::CXXRecordDecl *prev_base_decl =
+  prev_base->getType()->getAsCXXRecordDecl();

Should we add a comment describing why this block is necessary?

Perhaps even putting it into its own helper function



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1487
+assert(it != layout_info.base_offsets.end());
+if (it->second.getQuantity() == member_byte_offset) {
+  prev_base_decl->markEmpty();

The idea seem reasonable in general.

Though this wouldn't work for overlapping member offsets. E.g.,:

```
struct C
{
 long c,d;
};

struct D
{
};

struct B
{
  [[no_unique_address]] D x;
};

struct E
{
  [[no_unique_address]] D x;
};

struct Foo : B, E, C {

};
```

Here `B` and `C` have offset `0x0`, but `E` can have offset `0x1`. So we 
wouldn't attach the attribute for `E` and would still crash. Maybe we should 
check for overlapping offsets, not just equal


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-03 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

I'll submit later today then if nobody has any other objections

Will add a release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1481
+// To fix this we scan base classes in reverse order to determine
+// overlapping offsets. Wnen found we consider such class as empty
+// base with all fields having [[no_unique_address]] attribute.





Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1483
+// base with all fields having [[no_unique_address]] attribute.
+for (auto it = base_classes.rbegin(); it != base_classes.rend(); ++it) {
+  clang::CXXRecordDecl *prev_base_decl =

The main problem I still see with this is that if we have something like:
```
struct A : C, B {

};
```

then we mark `C`'s fields as empty and leave `B` as is. This still leads to the 
same crash later on.

Perhaps we should mark we could check the size of the struct and decide based 
on that which one is the "empty" one



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1498
+ast->getASTContext(), clang::SourceRange()));
+}
 layout_info.base_offsets.insert(std::make_pair(

I think it would still be nice to have this as a private helper function on 
`DWARFASTParserClang`. But don't feel very strongly about it so feel free to 
ignore



Comment at: lldb/test/API/types/TestEmptyBase.py:2
+"""
+Test that recursive types are handled correctly.
+"""

Description needs fixing



Comment at: lldb/test/API/types/TestEmptyBase.py:22
+
+self.sources = {
+'CXX_SOURCES': 'empty_base_type.cpp'}

Ideally this test would live in `lldb/test/API/lang/cpp/no_unique_address/`

The usual structure is that we have a `Makefile` in the same directory which 
consists of:
```
CXX_SOURCES := main.cpp
   
include Makefile.rules 
```

Then in the `test(self)` you just call `self.build()`. You don't need the 
`setUp(self)` and `setTearDownCleanup(...)` calls then.

Check 
`lldb/test/API/commands/expression/inline-namespace/TestInlineNamespace.py` for 
example.



Comment at: lldb/test/API/types/empty_base_type.cpp:1
+struct C
+{

Can we add more test cases. E.g.,:

```
struct A : C, B {
 ...
};
```



Comment at: lldb/test/API/types/empty_base_type.cpp:3
+{
+ long c,d;
+};

Just for sanity checking in the test



Comment at: lldb/test/API/types/empty_base_type.cpp:23
+{
+ long a,b;
+} _a;

same as above


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1483
+// base with all fields having [[no_unique_address]] attribute.
+for (auto it = base_classes.rbegin(); it != base_classes.rend(); ++it) {
+  clang::CXXRecordDecl *prev_base_decl =

Michael137 wrote:
> The main problem I still see with this is that if we have something like:
> ```
> struct A : C, B {
> 
> };
> ```
> 
> then we mark `C`'s fields as empty and leave `B` as is. This still leads to 
> the same crash later on.
> 
> Perhaps we should mark we could check the size of the struct and decide based 
> on that which one is the "empty" one
Interestingly there was a discussion on the DWARF mailing list about this some 
time ago: 
https://www.mail-archive.com/dwarf-discuss@lists.dwarfstd.org/msg00880.html

There might be room to changing the emitted DWARF to make it easier to 
determine the empty structure. I will gauge opinions on this thread later today


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: lldb/test/API/types/TestEmptyBase.py:25-42
+def test(self):
+"""Test that recursive structs are displayed correctly."""
+self.build(dictionary=self.sources)
+self.setTearDownCleanup(dictionary=self.sources)
+self.run_expr()
+
+def run_expr(self):




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

FYI, this bugfix was attempted back in 2021 here: 
https://reviews.llvm.org/D101237


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-06 Thread Michael Buch via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG711a64412749: [clang][DebugInfo] Emit DW_AT_type of 
preferred name if available (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/preferred_name-chain.cpp
  clang/test/CodeGen/preferred_name.cpp
  clang/test/Modules/Inputs/gmodules-preferred-name-alias.h
  clang/test/Modules/Inputs/gmodules-preferred-name-alias.modulemap
  clang/test/Modules/Inputs/gmodules-preferred-name-typedef.h
  clang/test/Modules/Inputs/gmodules-preferred-name-typedef.modulemap
  clang/test/Modules/gmodules-preferred-name-alias.cpp
  clang/test/Modules/gmodules-preferred-name-typedef.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
@@ -22,7 +22,7 @@
 
 def make_expected_basic_string_ptr(self) -> str:
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(['>', '16.0']):
-return f'std::unique_ptr >'
+return f'std::unique_ptr'
 else:
 return 'std::unique_ptr, std::allocator >, ' \
'std::default_delete, std::allocator > > >'
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
@@ -59,13 +59,13 @@
 self.assertNotEqual(valobj.child[0].unsigned, 0)
 
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(['>', '16.0']):
-string_type = "std::basic_string"
+string_type = "std::string"
 else:
-string_type = "std::basic_string, std::allocator >"
+string_type = "std::basic_string, std::allocator > "
 
 valobj = self.expect_var_path(
 "sp_str",
-type="std::shared_ptr<" + string_type + " >",
+type="std::shared_ptr<" + string_type + ">",
 children=[ValueCheck(name="__ptr_", summary='"hello"')],
 )
 self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')
Index: clang/test/Modules/gmodules-preferred-name-typedef.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-preferred-name-typedef.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
+// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-typedef.modulemap \
+// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
+// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
+// RUN: -I %S/Inputs %s &> %t.ll
+// RUN: cat %t.ll | FileCheck %s
+
+#include "gmodules-preferred-name-typedef.h"
+
+// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
+// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
Index: clang/test/Modules/gmodules-preferred-name-alias.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-preferred-name-alias.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
+// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-alias.modulemap \
+// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
+// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
+// RUN: -I %S/Inputs %s &> %t.ll
+// RUN: cat %t.ll | FileCheck %s
+
+#include "gmodules-preferred-name-alias.h"
+
+// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
+// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type

[PATCH] D147764: Fix the two gmoules-prefered-name-* tests

2023-04-07 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Thanks for fixing!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147764

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-10 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Looks like `gmodules` isn't supported on AIX (based on other tests that use 
`-dwarf-ext-refs`. So I'll just disable the new tests

Thanks for notifying @aaron.ballman , email notifications got lost in the inbox


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D145803: [clang][DebugInfo] Emit DW_AT_type of preferred name if available

2023-04-10 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a subscriber: Jake-Egan.
Michael137 added a comment.

Oh looks like @Jake-Egan already did


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145803

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-11 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added subscribers: aprantl, dblaikie.
Michael137 added inline comments.



Comment at: lldb/test/API/lang/cpp/no_unique_address/main.cpp:38
+ long v = 42;
+} _f3;
+

I haven't checked the reworked logic yet, but it still crashes on this:

```
self.expect_expr("_f3")
```

I'm leaning towards not trying to support older compilers if it gets too 
complicated. Proposing a `DW_AT_no_unique_address` seems like the best option 
to me since that's pretty trivial to implement and requires almost no support 
on the LLDB side.

CC: @dblaikie @aprantl (since both were part of the [[ 
https://www.mail-archive.com/dwarf-discuss@lists.dwarfstd.org/msg00876.html | 
original discussion ]])


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2212
 m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
-if (record_decl)
+if (record_decl) {
+  bool is_empty = true;

Generally I'm not sure if attaching a `clang::NoUniqueAddressAttr` to every 
empty field is the right approach. That goes slightly against our attempts to 
construct an AST that's faithful to the source to avoid unpredictable behaviour 
(which isn't always possible but for the most part we try). This approach was 
considered in https://reviews.llvm.org/D101237 but concern was raised about it 
affecting ABI, etc., leading to subtle issues down the line.

Based on the the discussion in https://reviews.llvm.org/D101237 it seemed to me 
like the only two viable solutions are:
1. Add a `DW_AT_byte_size` of `0` to the empty field
2. Add a `DW_AT_no_unique_address`

AFAICT Jan tried to implement (1) but never seemed to be able to fully add 
support for this in the ASTImporter/LLDB. Another issue I see with this is that 
sometimes the byte-size of said field is not `0`, depending on the context in 
which the structure is used.

I'm still leaning towards proposing a `DW_AT_no_unique_address`. Which is 
pretty easy to implement and also reason about from LLDB's perspective. 
@dblaikie @aprantl does that sound reasonable to you?



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2219
+if (is_empty_field)
+  field->addAttr(clang::NoUniqueAddressAttr::Create(
+  m_ast.getASTContext(), clang::SourceRange()));

Typically the call to `record_decl->fields()` below would worry me, because if 
the decl `!hasLoadedFieldsFromExternalStorage()` then we'd start another 
`ASTImport` process, which could lead to some unpredictable behaviour if we are 
already in the middle of an import. But since 
`CompleteTagDeclarationDefinition` sets 
`setHasLoadedFieldsFromExternalStorage(true)` I *think* we'd be ok. Might 
warrant a comment.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2231
+if (is_empty)
+  record_decl->markEmpty();
+  }

Why do we need to mark the parents empty here again? Wouldn't they have been 
marked in `ParseStructureLikeDIE`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D143501: [WIP][clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-07 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, dblaikie.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added projects: clang, LLDB.
Herald added subscribers: lldb-commits, cfe-commits.

**Summary**

This patch makes debug-info generation aware of the
`[[clang::preferred_name]]` attribute. The attribute tells clang
to print the annotated class template as some typedef (e.g., in
diagnostics).

When printing a typename for emission into `DW_AT_name` this patch now
uses the preferred_name (if available). This is behind an LLDB tuning
because by default we try to avoid diverging GCC and Clang typename
format (which is why the `PrintingPolicy::UsePreferredNames` has
previously been disabled by default in `CGDebugInfo`).

**Motivation**

This will reduce noise in type summaries when showing variable
types in LLDB. E.g.,:

  (lldb) v
  (std::vector >) vec = size=0 {}

becomes

  (lldb) v
  (std::vector) vec = size=0 {}

**Testing**

- Added Clang test
- Adjusted LLDB API tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143501

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/debug-info-preferred-names.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
@@ -22,7 +22,7 @@
 
 def make_expected_basic_string_ptr(self) -> str:
 if self.expectedCompilerVersion(['>', '16.0']):
-return f'std::unique_ptr >'
+return f'std::unique_ptr'
 else:
 return 'std::unique_ptr, std::allocator >, ' \
'std::default_delete, std::allocator > > >'
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
@@ -59,13 +59,13 @@
 self.assertNotEqual(valobj.child[0].unsigned, 0)
 
 if self.expectedCompilerVersion(['>', '16.0']):
-string_type = "std::basic_string"
+string_type = "std::string"
 else:
-string_type = "std::basic_string, std::allocator >"
+string_type = "std::basic_string, std::allocator > "
 
 valobj = self.expect_var_path(
 "sp_str",
-type="std::shared_ptr<" + string_type + " >",
+type="std::shared_ptr<" + string_type + ">",
 children=[ValueCheck(name="__ptr_", summary='"hello"')],
 )
 self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')
Index: clang/test/CodeGen/debug-info-preferred-names.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-preferred-names.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -debugger-tuning=lldb | FileCheck --check-prefixes=COMMON,LLDB %s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - -debugger-tuning=gdb | FileCheck --check-prefixes=COMMON,GDB %s
+
+template
+class Qux {};
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar)]] Foo {};
+
+int main() {
+/* Trivial cases */
+
+Bar b;
+// COMMON: !DIDerivedType(tag: DW_TAG_typedef, name: "Bar"
+
+Foo f1;
+// COMMON: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+
+/* Alias template case */
+
+Bar> f2;
+// GDB:!DIDerivedType(tag: DW_TAG_typedef, name: "Bar >"
+// LLDB:   !DIDerivedType(tag: DW_TAG_typedef, name: "Bar >"
+
+/* Nested cases */
+
+Foo> f3; 
+// GDB:!DICompositeType(tag: DW_TAG_structure_type, name: "Foo >"
+// LLDB:   !DICompositeType(tag: DW_TAG_structure_type, name: "Foo >"
+
+Qux> f4;
+// GDB:!DICompositeType(tag: DW_TAG_class_type, name: "Qux >"
+// LLDB:   !DICompositeType(tag: DW_TAG_class_type, name: "Qux >"
+
+return 0;
+}
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -789,6 +789,11 @@
   std::memcpy(Data + A.size(),

[PATCH] D143501: [WIP][clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-07 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.
Herald added a subscriber: JDevlieghere.

The alternative would be attaching the preferred name as a new attribute or an 
existing attribute like `DW_AT_description`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D143501: [WIP][clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-08 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py:61
 
 if self.expectedCompilerVersion(['>', '16.0']):
+string_type = "std::string"

aprantl wrote:
> Out of curiosity: How does this function work when building the testsuite 
> with a compiler that isn't Clang?
> I vaguely recall there was someone in the community running a bot that built 
> the LLDB testsuite against GCC.
Good point, this should also check for the compiler really. I assume because 
GCC isn't at that version yet it just works on that GCC buildbot

Will change in a different patch since there's other tests with this condition


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D143501: [WIP][clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-08 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/test/CodeGen/debug-info-preferred-names.cpp:1
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - 
-debugger-tuning=lldb | FileCheck --check-prefixes=COMMON,LLDB %s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - 
-debugger-tuning=gdb | FileCheck --check-prefixes=COMMON,GDB %s

aprantl wrote:
> Is `-debug-info-kind=limited` needed here? Using it here is odd since LLDB 
> doesn't really support it and favors `=standalone` instead.
Not needed, just leftover from different test. Will change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D143501: [WIP][clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-08 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D143501#4113347 , @aprantl wrote:

> Nice! Does `expr -- std::basic_string s` still work after this change? 
> Not that anyone would want to type this over `std::string` ...

Yup that still works. We would still emit it as `basic_string` if that was 
typed out in the source and that's how LLDB would show it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

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


[PATCH] D143501: [clang][DebugInfo] lldb: Use preferred name's type when emitting DW_AT_names

2023-02-09 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 496089.
Michael137 added a comment.

- Reword commit
- Use different debuginfo kind in tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143501

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGen/debug-info-preferred-names.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py

Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
@@ -22,7 +22,7 @@
 
 def make_expected_basic_string_ptr(self) -> str:
 if self.expectedCompilerVersion(['>', '16.0']):
-return f'std::unique_ptr >'
+return f'std::unique_ptr'
 else:
 return 'std::unique_ptr, std::allocator >, ' \
'std::default_delete, std::allocator > > >'
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
===
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
@@ -59,13 +59,13 @@
 self.assertNotEqual(valobj.child[0].unsigned, 0)
 
 if self.expectedCompilerVersion(['>', '16.0']):
-string_type = "std::basic_string"
+string_type = "std::string"
 else:
-string_type = "std::basic_string, std::allocator >"
+string_type = "std::basic_string, std::allocator > "
 
 valobj = self.expect_var_path(
 "sp_str",
-type="std::shared_ptr<" + string_type + " >",
+type="std::shared_ptr<" + string_type + ">",
 children=[ValueCheck(name="__ptr_", summary='"hello"')],
 )
 self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')
Index: clang/test/CodeGen/debug-info-preferred-names.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-preferred-names.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone %s -o - -debugger-tuning=lldb | FileCheck --check-prefixes=COMMON,LLDB %s
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone %s -o - -debugger-tuning=gdb | FileCheck --check-prefixes=COMMON,GDB %s
+
+template
+class Qux {};
+
+template
+struct Foo;
+
+template
+using Bar = Foo;
+
+template
+struct [[clang::preferred_name(Bar)]] Foo {};
+
+int main() {
+/* Trivial cases */
+
+Bar b;
+// COMMON: !DIDerivedType(tag: DW_TAG_typedef, name: "Bar"
+
+Foo f1;
+// COMMON: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
+
+/* Alias template case */
+
+Bar> f2;
+// GDB:!DIDerivedType(tag: DW_TAG_typedef, name: "Bar >"
+// LLDB:   !DIDerivedType(tag: DW_TAG_typedef, name: "Bar >"
+
+/* Nested cases */
+
+Foo> f3; 
+// GDB:!DICompositeType(tag: DW_TAG_structure_type, name: "Foo >"
+// LLDB:   !DICompositeType(tag: DW_TAG_structure_type, name: "Foo >"
+
+Qux> f4;
+// GDB:!DICompositeType(tag: DW_TAG_class_type, name: "Qux >"
+// LLDB:   !DICompositeType(tag: DW_TAG_class_type, name: "Qux >"
+
+return 0;
+}
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -789,6 +789,11 @@
   std::memcpy(Data + A.size(), B.data(), B.size());
 return StringRef(Data, A.size() + B.size());
   }
+
+  /// Returns the QualType of the typedef that the PreferredNameAttr
+  /// of 'orig' refers to, if any such attribute exists. Returns 'orig'
+  /// otherwise.
+  QualType maybeGetPreferredNameType(QualType orig) const;
 };
 
 /// A scoped helper to set the current debug location to the specified
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -250,7 +250,7 @@
 
   PP.SuppressInlineNamespace = false;
   PP.PrintCanonicalTypes = true;
-  PP.UsePreferredNames = false;
+  PP.UsePreferredNames = CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB;
   PP.AlwaysIncludeTypeForTemplateArgument = true;

  1   2   >