[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] 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] 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-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] 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] 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] 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] 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()) {
___

[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] 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] 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] 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] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-12-04 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D127284#3969458 , @v.g.vassilev 
wrote:

> In D127284#3969446 , @v.g.vassilev 
> wrote:
>
>>> UPDATE: fails with clean build too
>>>
>>> Might be best to revert it for now while we figure out what's wrong
>>
>> I fail to reproduce it, can you give me access to some node where I can 
>> debug? I suspect that should be something easy to fix.
>>
>> UPDATE: Reproduced it. Debugging.
>
> @Michael137, I think I understand what happens. This patch introduces a new 
> language option which is not benign from modules perspective. However, lldb 
> sets up modules the old way and then switches to the incremental processing 
> mode. We have two ways to fix this:
>
> - Pass `-Xclang -fincremental-extensions` in `ClangModulesDeclVendor.cpp` and 
> delete `instance->getPreprocessor().enableIncrementalProcessing();`; or
> - Apply https://reviews.llvm.org/D139258 which already does that.
>
> Can you check if https://reviews.llvm.org/D139258 passes the lldb testsuite. 
> It does pass my reproduction by hand (I still cannot run full of the lldb-api 
> tests)?

Thanks for taking a look. I tried with the suggested patch on the Objective-C 
API tests and there's only 1 test failure remaining there:

  lang/objc/modules-compile-error/TestModulesCompileError.py
  
  Expecting sub string: "module.h:4:1: error: unknown type name 
'syntax_error_for_lldb_to_find'" (was not found)

The test expects an error string that looks like "unknown type name 
'syntax_error_for_lldb_to_find' but gets use of 'undeclared identifier 
'syntax_error_for_lldb_to_find'

Haven't looked much further than that. Does that sound familiar to you? I see a 
similar test fix as part of this patch. Maybe it's just a matter of fixing up 
the expected string


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127284

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-12-05 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D127284#3969975 , @v.g.vassilev 
wrote:

> In D127284#3969593 , @Michael137 
> wrote:
>
>> In D127284#3969458 , @v.g.vassilev 
>> wrote:
>>
>>> In D127284#3969446 , 
>>> @v.g.vassilev wrote:
>>>
> UPDATE: fails with clean build too
>
> Might be best to revert it for now while we figure out what's wrong

 I fail to reproduce it, can you give me access to some node where I can 
 debug? I suspect that should be something easy to fix.

 UPDATE: Reproduced it. Debugging.
>>>
>>> @Michael137, I think I understand what happens. This patch introduces a new 
>>> language option which is not benign from modules perspective. However, lldb 
>>> sets up modules the old way and then switches to the incremental processing 
>>> mode. We have two ways to fix this:
>>>
>>> - Pass `-Xclang -fincremental-extensions` in `ClangModulesDeclVendor.cpp` 
>>> and delete `instance->getPreprocessor().enableIncrementalProcessing();`; or
>>> - Apply https://reviews.llvm.org/D139258 which already does that.
>>>
>>> Can you check if https://reviews.llvm.org/D139258 passes the lldb 
>>> testsuite. It does pass my reproduction by hand (I still cannot run full of 
>>> the lldb-api tests)?
>>
>> Thanks for taking a look. I tried with the suggested patch on the 
>> Objective-C API tests and there's only 1 test failure remaining there:
>>
>>   lang/objc/modules-compile-error/TestModulesCompileError.py
>>   
>>   Expecting sub string: "module.h:4:1: error: unknown type name 
>> 'syntax_error_for_lldb_to_find'" (was not found)
>>
>> The test expects an error string that looks like `unknown type name 
>> 'syntax_error_for_lldb_to_find'` but gets `use of 'undeclared identifier 
>> 'syntax_error_for_lldb_to_find'`
>>
>> Haven't looked much further than that. Does that sound familiar to you? I 
>> see a similar test fix as part of this patch. Maybe it's just a matter of 
>> fixing up the expected string.
>>
>> I think we should revert for now until https://reviews.llvm.org/D139258 is 
>> ready to go. Just to unblock the buildbot
>
> I have pushed a fix in 
> https://github.com/llvm/llvm-project/commit/c95a0c91c0de66eb1066f23c69332522656f188e
>  That should unblock the bot. If that does not work, I will revert.

Latest test run: 
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/48911/execution/node/74/log/
I modified the expected string slightly to make it work: 
https://reviews.llvm.org/rG811ad246ac7b
Should be all good now. Thanks for looking into this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127284

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


[PATCH] D139988: [clang][DebugInfo] Simplify logic to determine DW_AT_default_value for template parameters

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

- Remove now redundant header


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139988

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


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
-// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
value: i32 6)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i8 0)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i1 false)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}})
 
 // CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F2_TYPE:[0-9]+]]
-// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, 
defaulted: true)
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
defaulted: true, value: i32 3)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
-template 
+template 
+class bar {
+};
+
+template >
 class foo {
 };
 
 int main() {
-  foo f1;
+  foo f1;
   foo<> f2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1999,35 +1999,23 @@
 const TemplateArgument  = Args.Args[i];
 StringRef Name;
 bool defaultParameter = false;
-if (Args.TList)
+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);
-
-  if (Args.TList)
-if (auto *templateType =
-
dyn_cast_or_null(Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument() == TA.getAsType();
-
   TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
   TheCU, Name, TTy, defaultParameter));
 
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList)
-if (auto *templateType = dyn_cast_or_null(
-Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument() &&
-  !templateType->getDefaultArgument()->isValueDependent())
-defaultParameter = llvm::APSInt::isSameValue(
-templateType->getDefaultArgument()->EvaluateKnownConstInt(
-CGM.getContext()),
-TA.getAsIntegral());
-
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
   TheCU, Name, TTy, defaultParameter,
   llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral(;


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[F1_TYPE:[0-9]+]]
-// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], ![[THIRD:[0-9]+]], 

[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 marked an inline comment as done.
Michael137 added inline comments.



Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

aprantl wrote:
> dblaikie wrote:
> > aprantl wrote:
> > > aprantl wrote:
> > > > dblaikie wrote:
> > > > > aprantl wrote:
> > > > > > Michael137 wrote:
> > > > > > > Michael137 wrote:
> > > > > > > > dblaikie wrote:
> > > > > > > > > @aprantl any idea if this is good/OK? (I guess it probably is 
> > > > > > > > > - but maybe these strings were never meant to ignore/suppress 
> > > > > > > > > default arguments of any kind? or maybe this is an ABI sort 
> > > > > > > > > of thing where it suppressing some but not others is now 
> > > > > > > > > unchangeable?)
> > > > > > > > Good point. There was a thread on the cfe mailing list a while 
> > > > > > > > ago about the last time this broke: 
> > > > > > > > https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html
> > > > > > > > 
> > > > > > > > This was @rsmith's stance:
> > > > > > > > ```
> > > > > > > > I think some of the other recent TypePrinter changes might also 
> > > > > > > > risk
> > > > > > > > changing the @encode output. Generally it seems unwise for 
> > > > > > > > @encode to be
> > > > > > > > using the type pretty-printer if it wants to be ABI-stable; I 
> > > > > > > > don't think
> > > > > > > > it's reasonable to expect any guarantees as to the stability of
> > > > > > > > pretty-printed type names. I think USR generation suffers from 
> > > > > > > > similar
> > > > > > > > problems; it too uses the type pretty-printer to generate
> > > > > > > > supposedly-ABI-stable keys in at least some cases.
> > > > > > > > ```
> > > > > > > see https://reviews.llvm.org/D90622
> > > > > > To me it really looks like the intention of the feature is to not 
> > > > > > substitute default parameters. But if we stop doing this now it 
> > > > > > will likely result in a surprising code size increase, that may not 
> > > > > > be considered worth it compared to the risk of breaking ABI by 
> > > > > > changing a default template parameter.
> > > > > > 
> > > > > > As far as this patch is concerned, it's neutral to this decision 
> > > > > > (which may not have been a conscious one).
> > > > > > It's certainly not good that every type printer change is an ABI 
> > > > > > break.
> > > > > Awesome, thanks for tracking down that context @Michael137.
> > > > > 
> > > > > Not quite sure I'm following you @aprantl, but I think you're saying 
> > > > > this change is OK/seems consistent with other changes?
> > > > The current code (for @encode and USRs) seems to assume that 
> > > > TypePrinter output is stable.
> > > > 
> > > > I (personally) think that assumption ought to be wrong, because 
> > > > otherwise we'd never be able to make improvements such as this patch.
> > > > 
> > > > Aside from my personal preferences, practically this patch causes a 
> > > > problem for shipping an Objective-C compiler, since this is an 
> > > > ABI-breaking change. That's why I'd like to hear from someone with more 
> > > > insight into how `@encoding` is used in Objective-C wether this is 
> > > > something we need to be concerned about. If it is a concern we may need 
> > > > to add a TypePrinter configuration optimized for stability that 
> > > > preserves the current output format in eternity.
> > > To summarize an offline conversation about this: Because there are no 
> > > system frameworks that vend Objective-C++ types we are not concerned by a 
> > > potential ABI break caused by this patch.
> > > 
> > > LGTM!
> > Awesome - thanks for getting that info, @aprantl - any idea if we could 
> > write this down somewhere? (in comments in tests that verify `@encoding` if 
> > there aren't too many of them?) So it's easy/clear next time.
> @Michael137 You could add a comment to this very test here, stating that the 
> fact that the @encoding for C++ is effectively dependent on the TypePrinter 
> implementation is a known bug.
Done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 483476.
Michael137 marked an inline comment as done.
Michael137 added a comment.

- Add comment re. ABI break


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  clang/test/CodeGenObjCXX/encode.mm
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Misc/diag-template.cpp
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
  clang/test/SemaCXX/co_await-range-for.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/dependent-names.cpp

Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<>'
 // CHECK:   |-TemplateArgument integral 120
 // CHECK:   |-TemplateArgument type 'int'
 // CHECK:   | `-BuiltinType {{.*}} 'int'
Index: clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
===
--- clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
+++ clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
@@ -34,7 +34,7 @@
 {
 Matrix winI(0, 3);
 RGBFValue* inputPreL;
-winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
+winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
 }
 
 }
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1067,7 +1067,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1046,7 +1046,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/co_await-range-for.cpp
===
--- clang/test/SemaCXX/co_await-range-for.cpp
+++ clang/test/SemaCXX/co_await-range-for.cpp
@@ -150,7 +150,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await(auto i : R) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
 
Index: clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
===
--- clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
+++ clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
@@ -151,7 +151,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await (auto i : R) {}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template 

[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

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

- Split out LLVM changes into separate commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

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


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -23,17 +23,37 @@
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
+// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B1_TYPE:[0-9]+]]
+// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
+
+// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B2_TYPE:[0-9]+]]
+// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
+
 template 
 class bar {
 };
 
+template 
+class qux {
+};
+
 template >
 class foo {
 };
 
+template  class CT = bar>
+class baz {
+};
+
 int main() {
   foo f1;
   foo<> f2;
+  baz b1;
+  baz<> b2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2091,7 +2091,7 @@
   TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
   OS, getPrintingPolicy());
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-  TheCU, Name, nullptr, OS.str()));
+  TheCU, Name, nullptr, OS.str(), defaultParameter));
   break;
 }
 case TemplateArgument::Pack:


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -23,17 +23,37 @@
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, defaulted: true, value: i1 true)
 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, defaulted: true)
 
+// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B1_TYPE:[0-9]+]]
+// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
+
+// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B2_TYPE:[0-9]+]]
+// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
+
 template 
 class bar {
 };
 
+template 
+class qux {
+};
+
 template >
 class foo {
 };
 
+template  class CT = bar>
+class baz {
+};
+
 int main() {
   foo f1;
   foo<> f2;
+  baz b1;
+  baz<> b2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2091,7 +2091,7 @@
   TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
   OS, getPrintingPolicy());
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-  TheCU, Name, nullptr, OS.str()));
+  TheCU, Name, nullptr, OS.str(), defaultParameter));
   break;
 }
 case TemplateArgument::Pack:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

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

- Fix commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  clang/test/CodeGenObjCXX/encode.mm
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Misc/diag-template.cpp
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
  clang/test/SemaCXX/co_await-range-for.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/dependent-names.cpp

Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<>'
 // CHECK:   |-TemplateArgument integral 120
 // CHECK:   |-TemplateArgument type 'int'
 // CHECK:   | `-BuiltinType {{.*}} 'int'
Index: clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
===
--- clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
+++ clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
@@ -34,7 +34,7 @@
 {
 Matrix winI(0, 3);
 RGBFValue* inputPreL;
-winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
+winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
 }
 
 }
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1067,7 +1067,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1046,7 +1046,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/co_await-range-for.cpp
===
--- clang/test/SemaCXX/co_await-range-for.cpp
+++ clang/test/SemaCXX/co_await-range-for.cpp
@@ -150,7 +150,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await(auto i : R) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
 
Index: clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
===
--- clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
+++ clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
@@ -151,7 +151,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await (auto i : R) {}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note 

[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 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 rG1706f34d604e: [clang][TypePrinter] Teach 
isSubstitutedDefaultArgument about integral types (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  clang/test/CodeGenObjCXX/encode.mm
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Misc/diag-template.cpp
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
  clang/test/SemaCXX/co_await-range-for.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/dependent-names.cpp

Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<>'
 // CHECK:   |-TemplateArgument integral 120
 // CHECK:   |-TemplateArgument type 'int'
 // CHECK:   | `-BuiltinType {{.*}} 'int'
Index: clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
===
--- clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
+++ clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
@@ -34,7 +34,7 @@
 {
 Matrix winI(0, 3);
 RGBFValue* inputPreL;
-winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
+winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
 }
 
 }
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1067,7 +1067,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1046,7 +1046,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/co_await-range-for.cpp
===
--- clang/test/SemaCXX/co_await-range-for.cpp
+++ clang/test/SemaCXX/co_await-range-for.cpp
@@ -150,7 +150,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await(auto i : R) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
 
Index: clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
===
--- clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
+++ clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
@@ -151,7 +151,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await (auto i : R) {}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, 

[PATCH] D139988: [clang][DebugInfo] Simplify logic to determine DW_AT_default_value for template parameters

2022-12-16 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 rG8d3843badb8a: [clang][DebugInfo] Simplify logic to determine 
DW_AT_default_value for template… (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139988

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


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
-// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
value: i32 6)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i8 0)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i1 false)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}})
 
 // CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F2_TYPE:[0-9]+]]
-// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, 
defaulted: true)
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
defaulted: true, value: i32 3)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
-template 
+template 
+class bar {
+};
+
+template >
 class foo {
 };
 
 int main() {
-  foo f1;
+  foo f1;
   foo<> f2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1999,35 +1999,23 @@
 const TemplateArgument  = Args.Args[i];
 StringRef Name;
 bool defaultParameter = false;
-if (Args.TList)
+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);
-
-  if (Args.TList)
-if (auto *templateType =
-
dyn_cast_or_null(Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument() == TA.getAsType();
-
   TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
   TheCU, Name, TTy, defaultParameter));
 
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList)
-if (auto *templateType = dyn_cast_or_null(
-Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument() &&
-  !templateType->getDefaultArgument()->isValueDependent())
-defaultParameter = llvm::APSInt::isSameValue(
-templateType->getDefaultArgument()->EvaluateKnownConstInt(
-CGM.getContext()),
-TA.getAsIntegral());
-
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
   TheCU, Name, TTy, defaultParameter,
   llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral(;


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: 

[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

2022-12-16 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 rG2dff41c320fc: [llvm][DebugInfo] Add IsDefault parameter to 
DIBuilder… (authored by Michael137).

Changed prior to commit:
  https://reviews.llvm.org/D139989?vs=483477=483481#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

Files:
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -518,10 +518,10 @@
 /// \param Name Value parameter name.
 /// \param Ty   Parameter type.
 /// \param Val  The fully qualified name of the template.
-DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
-  StringRef Name,
-  DIType *Ty,
-  StringRef Val);
+/// \param IsDefaultParameter is default or not.
+DITemplateValueParameter *
+createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty,
+StringRef Val, bool IsDefault = false);
 
 /// Create debugging information for a template parameter pack.
 /// \param ScopeScope in which this type is defined.


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -518,10 +518,10 @@
 /// \param Name Value parameter name.
 /// \param Ty   Parameter type.
 /// \param Val  The fully qualified name of the template.
-DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
-  StringRef Name,
-  DIType *Ty,
-  StringRef Val);
+/// \param IsDefaultParameter is default or not.
+DITemplateValueParameter *
+createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty,
+StringRef Val, bool IsDefault = false);
 
 /// Create debugging information for a template parameter pack.
 /// \param ScopeScope in which this type is defined.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139988: [clang][DebugInfo] Re-use clang::TemplateUtils to determine guide DW_AT_default_value for template parameters

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

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139988

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


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
-// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
value: i32 6)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i8 0)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i1 false)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}})
 
 // CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F2_TYPE:[0-9]+]]
-// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, 
defaulted: true)
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
defaulted: true, value: i32 3)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
-template 
+template 
+class bar {
+};
+
+template >
 class foo {
 };
 
 int main() {
-  foo f1;
+  foo f1;
   foo<> f2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -26,6 +26,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TemplateUtils.h"
 #include "clang/AST/VTableBuilder.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/FileManager.h"
@@ -1999,35 +2000,23 @@
 const TemplateArgument  = Args.Args[i];
 StringRef Name;
 bool defaultParameter = false;
-if (Args.TList)
+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);
-
-  if (Args.TList)
-if (auto *templateType =
-
dyn_cast_or_null(Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument() == TA.getAsType();
-
   TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
   TheCU, Name, TTy, defaultParameter));
 
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList)
-if (auto *templateType = dyn_cast_or_null(
-Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument() &&
-  !templateType->getDefaultArgument()->isValueDependent())
-defaultParameter = llvm::APSInt::isSameValue(
-templateType->getDefaultArgument()->EvaluateKnownConstInt(
-CGM.getContext()),
-TA.getAsIntegral());
-
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
   TheCU, Name, TTy, defaultParameter,
   llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral(;


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 

[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

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

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -518,10 +518,10 @@
 /// \param Name Value parameter name.
 /// \param Ty   Parameter type.
 /// \param Val  The fully qualified name of the template.
-DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
-  StringRef Name,
-  DIType *Ty,
-  StringRef Val);
+/// \param IsDefaultParameter is default or not.
+DITemplateValueParameter *
+createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty,
+StringRef Val, bool IsDefault);
 
 /// Create debugging information for a template parameter pack.
 /// \param ScopeScope in which this type is defined.
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -23,17 +23,37 @@
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
+// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B1_TYPE:[0-9]+]]
+// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
+
+// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B2_TYPE:[0-9]+]]
+// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
+
 template 
 class bar {
 };
 
+template 
+class qux {
+};
+
 template >
 class foo {
 };
 
+template  class CT = bar>
+class baz {
+};
+
 int main() {
   foo f1;
   foo<> f2;
+  baz b1;
+  baz<> b2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2092,7 +2092,7 @@
   TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
   OS, getPrintingPolicy());
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-  TheCU, Name, nullptr, OS.str()));
+  TheCU, Name, nullptr, OS.str(), defaultParameter));
   break;
 }
 case TemplateArgument::Pack:


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.h

[PATCH] D139988: [clang][DebugInfo] Re-use clang::TemplateUtils to determine guide DW_AT_default_value for template parameters

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

In D139988#3999115 , @dblaikie wrote:

> Looks good to me, thanks!
>
> Patch description might need a tweak, this bit:
>
>> Type template parameters where the type is itself a template instantiation 
>> (e.g., `template>`)
>
> The quoted example is impossible (infinitely recursive) & the description 
> might be less specific than necessary - is any template instantiation a 
> problem (eg: `template`) for the existing 
> code/addressed by this patch, or only defaults that are instantiated with a 
> prior template parameter in the same template parameter list? If it's the 
> latter, would be good to include that nuance, if it's the former might be 
> worth clarifying that/using some `Foo` in the example insetad of `Foo`

Whoops good catch. What I meant to say is `template>`. Will update the commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139988

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


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

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

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  clang/test/CodeGenObjCXX/encode.mm
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Misc/diag-template.cpp
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
  clang/test/SemaCXX/co_await-range-for.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/dependent-names.cpp

Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<>'
 // CHECK:   |-TemplateArgument integral 120
 // CHECK:   |-TemplateArgument type 'int'
 // CHECK:   | `-BuiltinType {{.*}} 'int'
Index: clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
===
--- clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
+++ clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
@@ -34,7 +34,7 @@
 {
 Matrix winI(0, 3);
 RGBFValue* inputPreL;
-winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
+winI = { inputPreL->at() }; // expected-error {{call to deleted constructor of 'cva::Matrix &&'}}
 }
 
 }
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1067,7 +1067,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1046,7 +1046,7 @@
 };
 template 
 void test_dependent_param(T t, U) {
-  // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
+  // expected-error@-1 {{call to deleted constructor of 'NoCopy<>'}}
   // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
   ((void)t);
   co_return 42;
Index: clang/test/SemaCXX/co_await-range-for.cpp
===
--- clang/test/SemaCXX/co_await-range-for.cpp
+++ clang/test/SemaCXX/co_await-range-for.cpp
@@ -150,7 +150,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await(auto i : R) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}
 
Index: clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
===
--- clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
+++ clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
@@ -151,7 +151,7 @@
 ForLoopAwaiterCoawaitLookup test_coawait_lookup(T) {
   Range R;
   for co_await (auto i : R) {}
-  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag, false>'}}
+  // expected-error@-1 {{no member named 'await_ready' in 'CoawaitTag>'}}
 }
 template ForLoopAwaiterCoawaitLookup test_coawait_lookup(int); // expected-note {{requested here}}

[PATCH] D139985: [clang][AST][NFC] Move isSubstitutedDefaultArgument out of TypePrinter into separate component

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

- Don't create separate component. Instead move API into Type.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139985

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


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -2044,9 +2044,7 @@
   return false;
 }
 
-/// Make a best-effort determination of whether the type T can be produced by
-/// substituting Args into the default argument of Param.
-static bool isSubstitutedDefaultArgument(ASTContext , TemplateArgument Arg,
+bool clang::isSubstitutedDefaultArgument(ASTContext , TemplateArgument Arg,
  const NamedDecl *Param,
  ArrayRef Args,
  unsigned Depth) {
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -5460,6 +5460,13 @@
const PrintingPolicy ,
const TemplateParameterList *TPL = nullptr);
 
+/// Make a best-effort determination of whether the type T can be produced by
+/// substituting Args into the default argument of Param.
+bool isSubstitutedDefaultArgument(ASTContext , TemplateArgument Arg,
+  const NamedDecl *Param,
+  ArrayRef Args,
+  unsigned Depth);
+
 /// The injected class name of a C++ class template or class
 /// template partial specialization.  Used to record that a type was
 /// spelled with a bare identifier rather than as a template-id; the


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -2044,9 +2044,7 @@
   return false;
 }
 
-/// Make a best-effort determination of whether the type T can be produced by
-/// substituting Args into the default argument of Param.
-static bool isSubstitutedDefaultArgument(ASTContext , TemplateArgument Arg,
+bool clang::isSubstitutedDefaultArgument(ASTContext , TemplateArgument Arg,
  const NamedDecl *Param,
  ArrayRef Args,
  unsigned Depth) {
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -5460,6 +5460,13 @@
const PrintingPolicy ,
const TemplateParameterList *TPL = nullptr);
 
+/// Make a best-effort determination of whether the type T can be produced by
+/// substituting Args into the default argument of Param.
+bool isSubstitutedDefaultArgument(ASTContext , TemplateArgument Arg,
+  const NamedDecl *Param,
+  ArrayRef Args,
+  unsigned Depth);
+
 /// The injected class name of a C++ class template or class
 /// template partial specialization.  Used to record that a type was
 /// spelled with a bare identifier rather than as a template-id; the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139985: [clang][AST][NFC] Move isSubstitutedDefaultArgument out of TypePrinter into separate component

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

committed in `98afcbab66505661045dccb85ee9acdbf9410047`
Missed phab link in commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139985

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


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-16 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Missed couple of test cases in libcxx
About to fix those


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

2022-12-14 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-template-parameter.cpp:7
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -gstrict-dwarf -triple x86_64 
%s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 
-disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4

chapuni wrote:
> llvm-dwarfdump fails if x86 is unconfigured.
I suppose we could just stop passing the triple explicitly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139953

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


[PATCH] D139986: [WIP][clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a project: All.
Michael137 updated this revision to Diff 483168.
Michael137 added a comment.
Michael137 updated this revision to Diff 483184.
Michael137 published this revision for review.
Michael137 added a subscriber: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Simplify


Michael137 added a comment.

- Fix another test




Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

@aprantl any idea if this is good/OK? (I guess it probably is - but maybe these 
strings were never meant to ignore/suppress default arguments of any kind? or 
maybe this is an ABI sort of thing where it suppressing some but not others is 
now unchangeable?)



Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

dblaikie wrote:
> @aprantl any idea if this is good/OK? (I guess it probably is - but maybe 
> these strings were never meant to ignore/suppress default arguments of any 
> kind? or maybe this is an ABI sort of thing where it suppressing some but not 
> others is now unchangeable?)
Good point. There was a thread on the cfe mailing list a while ago about the 
last time this broke: 
https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html

This was @rsmith's stance:
```
I think some of the other recent TypePrinter changes might also risk
changing the @encode output. Generally it seems unwise for @encode to be
using the type pretty-printer if it wants to be ABI-stable; I don't think
it's reasonable to expect any guarantees as to the stability of
pretty-printed type names. I think USR generation suffers from similar
problems; it too uses the type pretty-printer to generate
supposedly-ABI-stable keys in at least some cases.
```


This patch handles default integral non-type template parameters.

After this patch the clang TypePrinter will omit default integral
template arguments when the `PrintingPolicy::SuppressDefaultTemplateArgs`
option is specified and sets us up to be able to re-use `TemplateUtils`
from with the DWARF CodeGen component.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139986

Files:
  clang/lib/AST/TemplateUtils.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  clang/test/CodeGenObjCXX/encode.mm
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Misc/diag-template.cpp
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
  clang/test/SemaCXX/co_await-range-for.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/dependent-names.cpp

Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) 

[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

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



Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

Michael137 wrote:
> dblaikie wrote:
> > @aprantl any idea if this is good/OK? (I guess it probably is - but maybe 
> > these strings were never meant to ignore/suppress default arguments of any 
> > kind? or maybe this is an ABI sort of thing where it suppressing some but 
> > not others is now unchangeable?)
> Good point. There was a thread on the cfe mailing list a while ago about the 
> last time this broke: 
> https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html
> 
> This was @rsmith's stance:
> ```
> I think some of the other recent TypePrinter changes might also risk
> changing the @encode output. Generally it seems unwise for @encode to be
> using the type pretty-printer if it wants to be ABI-stable; I don't think
> it's reasonable to expect any guarantees as to the stability of
> pretty-printed type names. I think USR generation suffers from similar
> problems; it too uses the type pretty-printer to generate
> supposedly-ABI-stable keys in at least some cases.
> ```
see https://reviews.llvm.org/D90622


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, dblaikie.
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.

**Summary**

Starting with DWARFv5, DW_AT_default_value can be used to indicate
that a template argument has a default value. With this patch LLVM
will emit the this attribute earlier versions of DWARF, unless
compiling with -gstrict-dwarf.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139953

Files:
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -350,6 +350,10 @@
 
   virtual bool isDwoUnit() const = 0;
   const MCSymbol *getCrossSectionRelativeBaseAddress() const override;
+
+  /// Returns 'true' if the current DwarfVersion is compatible
+  /// with the specified \p Version.
+  bool isCompatibleWithVersion(uint16_t Version) const;
 };
 
 class DwarfTypeUnit final : public DwarfUnit {
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1060,7 +1060,7 @@
 addType(ParamDIE, TP->getType());
   if (!TP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
-  if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (TP->isDefault() && isCompatibleWithVersion(5))
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
 }
 
@@ -1074,7 +1074,7 @@
 addType(ParamDIE, VP->getType());
   if (!VP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
-  if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (VP->isDefault() && isCompatibleWithVersion(5))
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
   if (Metadata *Val = VP->getValue()) {
 if (ConstantInt *CI = mdconst::dyn_extract(Val))
@@ -1852,3 +1852,7 @@
 void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
   DD->getAddressPool().resetUsedFlag(true);
 }
+
+bool DwarfUnit::isCompatibleWithVersion(uint16_t Version) const {
+  return !Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= Version;
+}
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,PRE17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -gstrict-dwarf -triple x86_64 
%s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
@@ -21,6 +22,24 @@
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 
+// DWARF-DUMP: DW_TAG_class_type
+// DWARF-DUMP:   DW_AT_name  ("foo")
+// DWARF-DUMP:   DW_TAG_template_type_parameter
+// DWARF-DUMP-NEXT:DW_AT_type({{.*}} "char")
+// DWARF-DUMP-NEXT:DW_AT_name("T")
+// DWARFv4-NEXT:   DW_AT_default_value   (true)
+// STRICT-NOT: DW_AT_default_value   (true)
+// DWARF-DUMP:   DW_TAG_template_value_parameter
+// DWARF-DUMP-NEXT:DW_AT_type({{.*}} "int")
+// DWARF-DUMP-NEXT:DW_AT_name("i")
+// DWARFv4-NEXT:   DW_AT_default_value   (true)
+// STRICT-NOT: DW_AT_default_value   (true)
+// DWARF-DUMP:   DW_TAG_template_value_parameter
+// DWARF-DUMP-NEXT:DW_AT_type({{.*}} "bool")
+// DWARF-DUMP-NEXT:DW_AT_name("b")
+// DWARFv4-NEXT:   DW_AT_default_value   (true)
+// STRICT-NOT: DW_AT_default_value   (true)
+
 template 
 class foo {
 };


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

[PATCH] D139928: [clang][DebugInfo] Backport emitting DW_AT_default_value for default template arguments

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 482533.
Michael137 added a comment.

- Split clang and llvm changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139928

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


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -3,6 +3,7 @@
 
 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,PRE17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2015,7 +2015,7 @@
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList && CGM.getCodeGenOpts().DwarfVersion >= 5)
+  if (Args.TList)
 if (auto *templateType = dyn_cast_or_null(
 Args.TList->getParam(i)))
   if (templateType->hasDefaultArgument() &&


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -3,6 +3,7 @@
 
 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefixes=CHECK,PRE17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefixes=CHECK,CXX17
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[F1_TYPE:[0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2015,7 +2015,7 @@
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList && CGM.getCodeGenOpts().DwarfVersion >= 5)
+  if (Args.TList)
 if (auto *templateType = dyn_cast_or_null(
 Args.TList->getParam(i)))
   if (templateType->hasDefaultArgument() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139928: [clang][DebugInfo] Backport emitting DW_AT_default_value for default template arguments

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D139928#3992233 , @dblaikie wrote:

> (This should be committed in two parts - the LLVM part first, then the Clang 
> part - since they can be separated, they should be - but happy to review it 
> altogether)

Split the review: https://reviews.llvm.org/D139953

Updated the version check to be a bit more general.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139928

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


[PATCH] D139928: [clang][DebugInfo] Backport emitting DW_AT_default_value for default template arguments

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, dblaikie.
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.

With this patch Clang emits `DW_AT_default_value` to indicate defaulted
template arguments (this usage was introduced in DWARFv5) in earlier
versions of DWARF, unless compiling with `-gstrict-dwarf`.

Changes:

1. Previously the DwarfVersion check in `CGDebugInfo` was inconsistent: For 
non-type template arguments we attached the attribute to the debug metadata in 
DWARFv5 only. Whereas for type template arguments we didn't have such a version 
restriction. With this patch we attach the attribute regardless of DWARF 
version (and instead offload the check to the AsmPrinter).
2. The AsmPrinter will now also check for whether we compiled with 
`-gstrict-dwarf`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139928

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -350,6 +350,10 @@
 
   virtual bool isDwoUnit() const = 0;
   const MCSymbol *getCrossSectionRelativeBaseAddress() const override;
+
+  /// Returns 'true' if 'DW_AT_default_value' should be emitted
+  /// to indicate defaulted template arguments.
+  bool shouldEmitTemplateDefaultAttr() const;
 };
 
 class DwarfTypeUnit final : public DwarfUnit {
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1060,7 +1060,7 @@
 addType(ParamDIE, TP->getType());
   if (!TP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
-  if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (TP->isDefault() && shouldEmitTemplateDefaultAttr())
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
 }
 
@@ -1074,7 +1074,7 @@
 addType(ParamDIE, VP->getType());
   if (!VP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
-  if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (VP->isDefault() && shouldEmitTemplateDefaultAttr())
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
   if (Metadata *Val = VP->getValue()) {
 if (ConstantInt *CI = mdconst::dyn_extract(Val))
@@ -1852,3 +1852,9 @@
 void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
   DD->getAddressPool().resetUsedFlag(true);
 }
+
+bool DwarfUnit::shouldEmitTemplateDefaultAttr() const {
+  assert(Asm != nullptr);
+  assert(DD != nullptr);
+  return !Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 5;
+}
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -3,6 +3,9 @@
 
 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,PRE17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 
-disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -gstrict-dwarf -triple x86_64 
%s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
@@ -20,6 +23,24 @@
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 
+// DWARF-DUMP: DW_TAG_class_type
+// DWARF-DUMP:   DW_AT_name  ("foo")
+// DWARF-DUMP:   DW_TAG_template_type_parameter
+// DWARF-DUMP-NEXT:DW_AT_type({{.*}} "char")
+// DWARF-DUMP-NEXT:DW_AT_name("T")
+// 

[PATCH] D139928: [clang][DebugInfo] Backport emitting DW_AT_default_value for default template arguments

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 482419.
Michael137 added a comment.

- Fix test formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139928

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -350,6 +350,10 @@
 
   virtual bool isDwoUnit() const = 0;
   const MCSymbol *getCrossSectionRelativeBaseAddress() const override;
+
+  /// Returns 'true' if 'DW_AT_default_value' should be emitted
+  /// to indicate defaulted template arguments.
+  bool shouldEmitTemplateDefaultAttr() const;
 };
 
 class DwarfTypeUnit final : public DwarfUnit {
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1060,7 +1060,7 @@
 addType(ParamDIE, TP->getType());
   if (!TP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
-  if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (TP->isDefault() && shouldEmitTemplateDefaultAttr())
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
 }
 
@@ -1074,7 +1074,7 @@
 addType(ParamDIE, VP->getType());
   if (!VP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
-  if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (VP->isDefault() && shouldEmitTemplateDefaultAttr())
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
   if (Metadata *Val = VP->getValue()) {
 if (ConstantInt *CI = mdconst::dyn_extract(Val))
@@ -1852,3 +1852,9 @@
 void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
   DD->getAddressPool().resetUsedFlag(true);
 }
+
+bool DwarfUnit::shouldEmitTemplateDefaultAttr() const {
+  assert(Asm != nullptr);
+  assert(DD != nullptr);
+  return !Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 5;
+}
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -3,6 +3,9 @@
 
 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,PRE17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 
-disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -gstrict-dwarf -triple x86_64 
%s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
@@ -20,6 +23,24 @@
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 
+// DWARF-DUMP: DW_TAG_class_type
+// DWARF-DUMP:   DW_AT_name  ("foo")
+// DWARF-DUMP:   DW_TAG_template_type_parameter
+// DWARF-DUMP-NEXT:DW_AT_type({{.*}} "char")
+// DWARF-DUMP-NEXT:DW_AT_name("T")
+// DWARFv4-NEXT:   DW_AT_default_value   (true)
+// STRICT-NOT: DW_AT_default_value   (true)
+// DWARF-DUMP:   DW_TAG_template_value_parameter
+// DWARF-DUMP-NEXT:DW_AT_type({{.*}} "int")
+// DWARF-DUMP-NEXT:DW_AT_name("i")
+// DWARFv4-NEXT:   DW_AT_default_value   (true)
+// STRICT-NOT: DW_AT_default_value   (true)
+// DWARF-DUMP:   DW_TAG_template_value_parameter
+// DWARF-DUMP-NEXT:DW_AT_type({{.*}} "bool")
+// DWARF-DUMP-NEXT:DW_AT_name("b")
+// DWARFv4-NEXT:   DW_AT_default_value   (true)
+// STRICT-NOT: DW_AT_default_value   (true)
+
 template 
 class foo {
 };
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- 

[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

2022-12-14 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 rGc9861e5718f6: [llvm][DebugInfo] Backport DW_AT_default_value 
for template args (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139953

Files:
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -350,6 +350,10 @@
 
   virtual bool isDwoUnit() const = 0;
   const MCSymbol *getCrossSectionRelativeBaseAddress() const override;
+
+  /// Returns 'true' if the current DwarfVersion is compatible
+  /// with the specified \p Version.
+  bool isCompatibleWithVersion(uint16_t Version) const;
 };
 
 class DwarfTypeUnit final : public DwarfUnit {
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1056,7 +1056,7 @@
 addType(ParamDIE, TP->getType());
   if (!TP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
-  if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (TP->isDefault() && isCompatibleWithVersion(5))
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
 }
 
@@ -1070,7 +1070,7 @@
 addType(ParamDIE, VP->getType());
   if (!VP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
-  if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (VP->isDefault() && isCompatibleWithVersion(5))
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
   if (Metadata *Val = VP->getValue()) {
 if (ConstantInt *CI = mdconst::dyn_extract(Val))
@@ -1845,3 +1845,7 @@
 void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
   DD->getAddressPool().resetUsedFlag(true);
 }
+
+bool DwarfUnit::isCompatibleWithVersion(uint16_t Version) const {
+  return !Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= Version;
+}
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,PRE17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -gstrict-dwarf -triple x86_64 
%s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 
-disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
@@ -21,6 +23,25 @@
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 
+// DWARF-DUMP:   DW_TAG_class_type
+// DWARF-DUMP-LABEL:   DW_AT_name  ("foo")
+// DWARF-DUMP: DW_TAG_template_type_parameter
+// DWARF-DUMP-DAG:   DW_AT_type({{.*}} "char")
+// DWARF-DUMP-DAG:   DW_AT_name("T")
+// DWARFv4-DAG:  DW_AT_default_value   (true)
+// STRICT-NOT:   DW_AT_default_value
+// DWARF-DUMP: DW_TAG_template_value_parameter
+// DWARF-DUMP-DAG:   DW_AT_type({{.*}} "int")
+// DWARF-DUMP-DAG:   DW_AT_name("i")
+// DWARFv4-DAG:  DW_AT_default_value   (true)
+// STRICT-NOT:   DW_AT_default_value   (true)
+// DWARF-DUMP: DW_TAG_template_value_parameter
+// DWARF-DUMP-DAG:   DW_AT_type({{.*}} "bool")
+// DWARF-DUMP-DAG:   DW_AT_name("b")
+// DWARFv4-DAG:  DW_AT_default_value   (true)
+// STRICT-NOT:   DW_AT_default_value
+// DWARF-DUMP:   {{DW_TAG|NULL}}
+
 template 
 class foo {
 };


Index: 

[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

2022-12-14 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

Ack, looking


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139953

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


[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

2022-12-14 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 482995.
Michael137 added a comment.

- Fix label name
- Add check for end of block


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139953

Files:
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -350,6 +350,10 @@
 
   virtual bool isDwoUnit() const = 0;
   const MCSymbol *getCrossSectionRelativeBaseAddress() const override;
+
+  /// Returns 'true' if the current DwarfVersion is compatible
+  /// with the specified \p Version.
+  bool isCompatibleWithVersion(uint16_t Version) const;
 };
 
 class DwarfTypeUnit final : public DwarfUnit {
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1060,7 +1060,7 @@
 addType(ParamDIE, TP->getType());
   if (!TP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
-  if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (TP->isDefault() && isCompatibleWithVersion(5))
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
 }
 
@@ -1074,7 +1074,7 @@
 addType(ParamDIE, VP->getType());
   if (!VP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
-  if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (VP->isDefault() && isCompatibleWithVersion(5))
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
   if (Metadata *Val = VP->getValue()) {
 if (ConstantInt *CI = mdconst::dyn_extract(Val))
@@ -1852,3 +1852,7 @@
 void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
   DD->getAddressPool().resetUsedFlag(true);
 }
+
+bool DwarfUnit::isCompatibleWithVersion(uint16_t Version) const {
+  return !Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= Version;
+}
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,PRE17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -gstrict-dwarf -triple x86_64 
%s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 
-disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
@@ -21,6 +23,25 @@
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 
+// DWARF-DUMP:   DW_TAG_class_type
+// DWARF-DUMP-LABEL:   DW_AT_name  ("foo")
+// DWARF-DUMP: DW_TAG_template_type_parameter
+// DWARF-DUMP-DAG:   DW_AT_type({{.*}} "char")
+// DWARF-DUMP-DAG:   DW_AT_name("T")
+// DWARFv4-DAG:  DW_AT_default_value   (true)
+// STRICT-NOT:   DW_AT_default_value
+// DWARF-DUMP: DW_TAG_template_value_parameter
+// DWARF-DUMP-DAG:   DW_AT_type({{.*}} "int")
+// DWARF-DUMP-DAG:   DW_AT_name("i")
+// DWARFv4-DAG:  DW_AT_default_value   (true)
+// STRICT-NOT:   DW_AT_default_value   (true)
+// DWARF-DUMP: DW_TAG_template_value_parameter
+// DWARF-DUMP-DAG:   DW_AT_type({{.*}} "bool")
+// DWARF-DUMP-DAG:   DW_AT_name("b")
+// DWARFv4-DAG:  DW_AT_default_value   (true)
+// STRICT-NOT:   DW_AT_default_value
+// DWARF-DUMP:   {{DW_TAG|NULL}}
+
 template 
 class foo {
 };


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- 

[PATCH] D140084: [llvm][test] Split DW_AT_default_value check out of clang/test/ Followup to D139953 to fix build failure on machines not configured for x86.

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140084

Files:
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll

Index: llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll
@@ -0,0 +1,98 @@
+; Tests that DW_AT_default_value is correctly emitted for C++ template
+; parameters that are defaulted.
+;
+; ModuleID = 'debug-info-template-parameter.cpp'
+;
+; template 
+; class foo {
+; };
+; 
+; int main() {
+;   foo f1;
+;   foo<> f2;
+;   return 0;
+; }
+;
+; RUN: llc -filetype=obj -dwarf-version=4 %s -o - | llvm-dwarfdump - --debug-info | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
+; RUN: llc -filetype=obj -dwarf-version=4 -strict-dwarf=true %s -o - | llvm-dwarfdump - --debug-info | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
+
+; DWARF-DUMP:   DW_TAG_class_type
+; DWARF-DUMP-LABEL:   DW_AT_name  ("foo")
+; DWARF-DUMP: DW_TAG_template_type_parameter
+; DWARF-DUMP-DAG:   DW_AT_type({{.*}} "char")
+; DWARF-DUMP-DAG:   DW_AT_name("T")
+; DWARFv4-DAG:  DW_AT_default_value   (true)
+; STRICT-NOT:   DW_AT_default_value
+; DWARF-DUMP: DW_TAG_template_value_parameter
+; DWARF-DUMP-DAG:   DW_AT_type({{.*}} "int")
+; DWARF-DUMP-DAG:   DW_AT_name("i")
+; DWARFv4-DAG:  DW_AT_default_value   (true)
+; STRICT-NOT:   DW_AT_default_value   (true)
+; DWARF-DUMP: DW_TAG_template_value_parameter
+; DWARF-DUMP-DAG:   DW_AT_type({{.*}} "bool")
+; DWARF-DUMP-DAG:   DW_AT_name("b")
+; DWARFv4-DAG:  DW_AT_default_value   (true)
+; STRICT-NOT:   DW_AT_default_value
+; DWARF-DUMP:   {{DW_TAG|NULL}}
+
+source_filename = "/tmp/debug-info-template-parameter.cpp"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64"
+
+%class.foo = type { i8 }
+%class.foo.0 = type { i8 }
+
+; Function Attrs: mustprogress noinline norecurse nounwind optnone
+define dso_local noundef i32 @main() #0 !dbg !6 {
+entry:
+  %retval = alloca i32, align 4
+  %f1 = alloca %class.foo, align 1
+  %f2 = alloca %class.foo.0, align 1
+  store i32 0, ptr %retval, align 4
+  call void @llvm.dbg.declare(metadata ptr %f1, metadata !12, metadata !DIExpression()), !dbg !20
+  call void @llvm.dbg.declare(metadata ptr %f2, metadata !21, metadata !DIExpression()), !dbg !29
+  ret i32 0, !dbg !30
+}
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { mustprogress noinline norecurse nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+
+!llvm.dbg.cu = !{!0}
+!llvm.linker.options = !{}
+!llvm.module.flags = !{!2, !3, !4}
+!llvm.ident = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "/tmp/debug-info-template-parameter.cpp", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{!"clang version 16.0.0"}
+!6 = distinct !DISubprogram(name: "main", scope: !7, file: !7, line: 49, type: !8, scopeLine: 49, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !11)
+!7 = !DIFile(filename: "/tmp/debug-info-template-parameter.cpp", directory: "/")
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !{}
+!12 = !DILocalVariable(name: "f1", scope: !6, file: !7, line: 50, type: !13)
+!13 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "foo", file: !7, line: 46, size: 8, flags: DIFlagTypePassByValue, elements: !11, templateParams: !14, identifier: "_ZTS3fooIiLi6ELb0ELi3EE")
+!14 = !{!15, !16, !17, !19}
+!15 = !DITemplateTypeParameter(name: "T", type: !10)
+!16 = !DITemplateValueParameter(name: "i", type: !10, value: i32 6)
+!17 = !DITemplateValueParameter(name: "b", type: !18, value: i1 false)
+!18 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
+!19 = !DITemplateValueParameter(name: "x", type: !10, value: i32 3)
+!20 = !DILocation(line: 50, 

[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

2022-12-14 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-template-parameter.cpp:7
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -gstrict-dwarf -triple x86_64 
%s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 
-disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4

aprantl wrote:
> aprantl wrote:
> > Michael137 wrote:
> > > chapuni wrote:
> > > > llvm-dwarfdump fails if x86 is unconfigured.
> > > I suppose we could just stop passing the triple explicitly
> > I think it would be better to check for the LLVM IR here, and add a second 
> > test that compiles that LLVM IR with llc in llvm/test/DebugInfo/X86
> Generally, no clang fronted tests should depend on any target to be 
> configured.
https://reviews.llvm.org/D140084


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139953

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


[PATCH] D140084: [llvm][test] Split DW_AT_default_value check out of clang/test/

2022-12-14 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 483065.
Michael137 retitled this revision from "[llvm][test] Split DW_AT_default_value 
check out of clang/test/

Followup to D139953 to fix build failure on machines not
configured for x86." to "[llvm][test] Split DW_AT_default_value check out of 
clang/test/".
Michael137 edited the summary of this revision.
Michael137 added a comment.
Herald added a subscriber: pengfei.

- Remove debug command


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140084

Files:
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll

Index: llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll
@@ -0,0 +1,98 @@
+; Tests that DW_AT_default_value is correctly emitted for C++ template
+; parameters that are defaulted.
+;
+; ModuleID = 'debug-info-template-parameter.cpp'
+;
+; template 
+; class foo {
+; };
+; 
+; int main() {
+;   foo f1;
+;   foo<> f2;
+;   return 0;
+; }
+;
+; RUN: llc -filetype=obj -dwarf-version=4 %s -o - | llvm-dwarfdump - --debug-info | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
+; RUN: llc -filetype=obj -dwarf-version=4 -strict-dwarf=true %s -o - | llvm-dwarfdump - --debug-info | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
+
+; DWARF-DUMP:   DW_TAG_class_type
+; DWARF-DUMP-LABEL:   DW_AT_name  ("foo")
+; DWARF-DUMP: DW_TAG_template_type_parameter
+; DWARF-DUMP-DAG:   DW_AT_type({{.*}} "char")
+; DWARF-DUMP-DAG:   DW_AT_name("T")
+; DWARFv4-DAG:  DW_AT_default_value   (true)
+; STRICT-NOT:   DW_AT_default_value
+; DWARF-DUMP: DW_TAG_template_value_parameter
+; DWARF-DUMP-DAG:   DW_AT_type({{.*}} "int")
+; DWARF-DUMP-DAG:   DW_AT_name("i")
+; DWARFv4-DAG:  DW_AT_default_value   (true)
+; STRICT-NOT:   DW_AT_default_value   (true)
+; DWARF-DUMP: DW_TAG_template_value_parameter
+; DWARF-DUMP-DAG:   DW_AT_type({{.*}} "bool")
+; DWARF-DUMP-DAG:   DW_AT_name("b")
+; DWARFv4-DAG:  DW_AT_default_value   (true)
+; STRICT-NOT:   DW_AT_default_value
+; DWARF-DUMP:   {{DW_TAG|NULL}}
+
+source_filename = "/tmp/debug-info-template-parameter.cpp"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64"
+
+%class.foo = type { i8 }
+%class.foo.0 = type { i8 }
+
+; Function Attrs: mustprogress noinline norecurse nounwind optnone
+define dso_local noundef i32 @main() #0 !dbg !6 {
+entry:
+  %retval = alloca i32, align 4
+  %f1 = alloca %class.foo, align 1
+  %f2 = alloca %class.foo.0, align 1
+  store i32 0, ptr %retval, align 4
+  call void @llvm.dbg.declare(metadata ptr %f1, metadata !12, metadata !DIExpression()), !dbg !20
+  call void @llvm.dbg.declare(metadata ptr %f2, metadata !21, metadata !DIExpression()), !dbg !29
+  ret i32 0, !dbg !30
+}
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { mustprogress noinline norecurse nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+
+!llvm.dbg.cu = !{!0}
+!llvm.linker.options = !{}
+!llvm.module.flags = !{!2, !3, !4}
+!llvm.ident = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "/tmp/debug-info-template-parameter.cpp", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{!"clang version 16.0.0"}
+!6 = distinct !DISubprogram(name: "main", scope: !7, file: !7, line: 49, type: !8, scopeLine: 49, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !11)
+!7 = !DIFile(filename: "/tmp/debug-info-template-parameter.cpp", directory: "/")
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !{}
+!12 = !DILocalVariable(name: "f1", scope: !6, file: !7, line: 50, type: !13)
+!13 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "foo", file: !7, line: 46, size: 8, flags: DIFlagTypePassByValue, elements: !11, templateParams: !14, identifier: "_ZTS3fooIiLi6ELb0ELi3EE")
+!14 = !{!15, !16, !17, !19}
+!15 = !DITemplateTypeParameter(name: "T", type: !10)
+!16 = !DITemplateValueParameter(name: "i", type: 

[PATCH] D140084: [llvm][test] Split DW_AT_default_value check out of clang/test/

2022-12-14 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 landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG738bfbce09e7: [llvm][test] Split DW_AT_default_value check 
out of clang/test/ (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140084

Files:
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll

Index: llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll
@@ -0,0 +1,98 @@
+; Tests that DW_AT_default_value is correctly emitted for C++ template
+; parameters that are defaulted.
+;
+; ModuleID = 'debug-info-template-parameter.cpp'
+;
+; template 
+; class foo {
+; };
+; 
+; int main() {
+;   foo f1;
+;   foo<> f2;
+;   return 0;
+; }
+;
+; RUN: llc -filetype=obj -dwarf-version=4 %s -o - | llvm-dwarfdump - --debug-info | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
+; RUN: llc -filetype=obj -dwarf-version=4 -strict-dwarf=true %s -o - | llvm-dwarfdump - --debug-info | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
+
+; DWARF-DUMP:   DW_TAG_class_type
+; DWARF-DUMP-LABEL:   DW_AT_name  ("foo")
+; DWARF-DUMP: DW_TAG_template_type_parameter
+; DWARF-DUMP-DAG:   DW_AT_type({{.*}} "char")
+; DWARF-DUMP-DAG:   DW_AT_name("T")
+; DWARFv4-DAG:  DW_AT_default_value   (true)
+; STRICT-NOT:   DW_AT_default_value
+; DWARF-DUMP: DW_TAG_template_value_parameter
+; DWARF-DUMP-DAG:   DW_AT_type({{.*}} "int")
+; DWARF-DUMP-DAG:   DW_AT_name("i")
+; DWARFv4-DAG:  DW_AT_default_value   (true)
+; STRICT-NOT:   DW_AT_default_value   (true)
+; DWARF-DUMP: DW_TAG_template_value_parameter
+; DWARF-DUMP-DAG:   DW_AT_type({{.*}} "bool")
+; DWARF-DUMP-DAG:   DW_AT_name("b")
+; DWARFv4-DAG:  DW_AT_default_value   (true)
+; STRICT-NOT:   DW_AT_default_value
+; DWARF-DUMP:   {{DW_TAG|NULL}}
+
+source_filename = "/tmp/debug-info-template-parameter.cpp"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64"
+
+%class.foo = type { i8 }
+%class.foo.0 = type { i8 }
+
+; Function Attrs: mustprogress noinline norecurse nounwind optnone
+define dso_local noundef i32 @main() #0 !dbg !6 {
+entry:
+  %retval = alloca i32, align 4
+  %f1 = alloca %class.foo, align 1
+  %f2 = alloca %class.foo.0, align 1
+  store i32 0, ptr %retval, align 4
+  call void @llvm.dbg.declare(metadata ptr %f1, metadata !12, metadata !DIExpression()), !dbg !20
+  call void @llvm.dbg.declare(metadata ptr %f2, metadata !21, metadata !DIExpression()), !dbg !29
+  ret i32 0, !dbg !30
+}
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { mustprogress noinline norecurse nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+
+!llvm.dbg.cu = !{!0}
+!llvm.linker.options = !{}
+!llvm.module.flags = !{!2, !3, !4}
+!llvm.ident = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "/tmp/debug-info-template-parameter.cpp", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{!"clang version 16.0.0"}
+!6 = distinct !DISubprogram(name: "main", scope: !7, file: !7, line: 49, type: !8, scopeLine: 49, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !11)
+!7 = !DIFile(filename: "/tmp/debug-info-template-parameter.cpp", directory: "/")
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !{}
+!12 = !DILocalVariable(name: "f1", scope: !6, file: !7, line: 50, type: !13)
+!13 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "foo", file: !7, line: 46, size: 8, flags: DIFlagTypePassByValue, elements: !11, templateParams: !14, identifier: "_ZTS3fooIiLi6ELb0ELi3EE")
+!14 = !{!15, !16, !17, !19}
+!15 = !DITemplateTypeParameter(name: "T", type: !10)
+!16 = !DITemplateValueParameter(name: "i", type: !10, value: i32 6)
+!17 = !DITemplateValueParameter(name: "b", type: !18, value: i1 false)
+!18 = 

[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-template-parameter.cpp:37
+// STRICT-NOT: DW_AT_default_value   (true)
+// DWARF-DUMP:   DW_TAG_template_value_parameter
+// DWARF-DUMP-NEXT:DW_AT_type({{.*}} "bool")

dblaikie wrote:
> Could consider using `DWARF-DUMP-LABEL` for the TAGs here (& maybe an extra 
> `DWARF-DUMP-LABEL: DW_TAG` at the end) so that the attributes are constrained 
> to be within the same tag? (could use `DWARF-DUMP-DAG` to test attributes in 
> a way that's not order-specific, which would be nice - but I don't know that 
> we do that much in the dwarfdump-driven tests, so not a huge deal)
+1 for the `DAG` directive

Could you elaborate on the `-LABEL` though? IIUC the labels have to match a 
line in the file uniquely, which the `DW_TAG`s wouldn't



Comment at: clang/test/CodeGenCXX/debug-info-template-parameter.cpp:41
+// DWARFv4-NEXT:   DW_AT_default_value   (true)
+// STRICT-NOT: DW_AT_default_value   (true)
+

dblaikie wrote:
> `NOT` checks should be pretty general (so they don't accidentally pass 
> despite minor differences-from-expectation) so maybe this should `STRICT-NOT: 
> DW_AT_default_value`?
Makes sense!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139953

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


[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-template-parameter.cpp:37
+// STRICT-NOT: DW_AT_default_value   (true)
+// DWARF-DUMP:   DW_TAG_template_value_parameter
+// DWARF-DUMP-NEXT:DW_AT_type({{.*}} "bool")

Michael137 wrote:
> dblaikie wrote:
> > Could consider using `DWARF-DUMP-LABEL` for the TAGs here (& maybe an extra 
> > `DWARF-DUMP-LABEL: DW_TAG` at the end) so that the attributes are 
> > constrained to be within the same tag? (could use `DWARF-DUMP-DAG` to test 
> > attributes in a way that's not order-specific, which would be nice - but I 
> > don't know that we do that much in the dwarfdump-driven tests, so not a 
> > huge deal)
> +1 for the `DAG` directive
> 
> Could you elaborate on the `-LABEL` though? IIUC the labels have to match a 
> line in the file uniquely, which the `DW_TAG`s wouldn't
Could label the `DW_AT_name` perhaps? Unless I'm misunderstanding


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139953

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


[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 482664.
Michael137 added a comment.

- Use `CHECK-DAG` for attributes
- Also compile with non-strict DWARFv4
- Widen the `STRICT-NOT` checks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139953

Files:
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -350,6 +350,10 @@
 
   virtual bool isDwoUnit() const = 0;
   const MCSymbol *getCrossSectionRelativeBaseAddress() const override;
+
+  /// Returns 'true' if the current DwarfVersion is compatible
+  /// with the specified \p Version.
+  bool isCompatibleWithVersion(uint16_t Version) const;
 };
 
 class DwarfTypeUnit final : public DwarfUnit {
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1060,7 +1060,7 @@
 addType(ParamDIE, TP->getType());
   if (!TP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
-  if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (TP->isDefault() && isCompatibleWithVersion(5))
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
 }
 
@@ -1074,7 +1074,7 @@
 addType(ParamDIE, VP->getType());
   if (!VP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
-  if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (VP->isDefault() && isCompatibleWithVersion(5))
 addFlag(ParamDIE, dwarf::DW_AT_default_value);
   if (Metadata *Val = VP->getValue()) {
 if (ConstantInt *CI = mdconst::dyn_extract(Val))
@@ -1852,3 +1852,7 @@
 void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
   DD->getAddressPool().resetUsedFlag(true);
 }
+
+bool DwarfUnit::isCompatibleWithVersion(uint16_t Version) const {
+  return !Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= Version;
+}
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,PRE17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s 
-O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s 
--check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -gstrict-dwarf -triple x86_64 
%s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 
-disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | 
llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
@@ -21,6 +23,24 @@
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 
+// DWARF-DUMP:   DW_TAG_class_type
+// DWARF-DUMPABEL: DW_AT_name  ("foo")
+// DWARF-DUMP: DW_TAG_template_type_parameter
+// DWARF-DUMP-DAG:   DW_AT_type({{.*}} "char")
+// DWARF-DUMP-DAG:   DW_AT_name("T")
+// DWARFv4-DAG:  DW_AT_default_value   (true)
+// STRICT-NOT:   DW_AT_default_value
+// DWARF-DUMP: DW_TAG_template_value_parameter
+// DWARF-DUMP-DAG:   DW_AT_type({{.*}} "int")
+// DWARF-DUMP-DAG:   DW_AT_name("i")
+// DWARFv4-DAG:  DW_AT_default_value   (true)
+// STRICT-NOT:   DW_AT_default_value   (true)
+// DWARF-DUMP: DW_TAG_template_value_parameter
+// DWARF-DUMP-DAG:   DW_AT_type({{.*}} "bool")
+// DWARF-DUMP-DAG:   DW_AT_name("b")
+// DWARFv4-DAG:  DW_AT_default_value   (true)
+// STRICT-NOT:   DW_AT_default_value
+
 template 
 class foo {
 };


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- 

[PATCH] D139985: [clang][AST][NFC] Move isSubstitutedDefaultArgument out of TypePrinter into separate component

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



Comment at: clang/include/clang/AST/TemplateUtils.h:19
+namespace clang {
+namespace TemplateUtils {
+/// Make a best-effort determination of whether the type T can be produced by

dblaikie wrote:
> aprantl wrote:
> > It looks like all the other namespaces in Clang are all lowercase?
> Yeah, +1 to the naming.
> 
> & maybe not introducing a new "utils" bucket - they can be a bit of a dumping 
> ground. Could this operation belong elsewhere/in some existing type, or maybe 
> doesn't need a namespace wrapper - could be a free function in the `clang` 
> namespace?)
I suppose this could just be a static function on `clang::TypePrinter`. We use 
it from `CGDebugInfo` already anyway so it wouldn't be an extra dependency. 
Wdyt? @aprantl @dblaikie 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139985

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


[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

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



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2095-2097
+NamedDecl const *ND = Args.TList->getParam(i);
+defaultParameter = TemplateUtils::isSubstitutedDefaultArgument(
+CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());

dblaikie wrote:
> Could we pull this snipped out and do it before the switch - so we don't have 
> to repeat it for each different kind of template parameter type?
yup makes sense!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

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


[PATCH] D139988: [clang][DebugInfo] Re-use clang::TemplateUtils to determine guide DW_AT_default_value for template parameters

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

- Hoist common code out of switch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139988

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


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
-// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
value: i32 6)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i8 0)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i1 false)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}})
 
 // CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F2_TYPE:[0-9]+]]
-// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, 
defaulted: true)
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
defaulted: true, value: i32 3)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
-template 
+template 
+class bar {
+};
+
+template >
 class foo {
 };
 
 int main() {
-  foo f1;
+  foo f1;
   foo<> f2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -26,6 +26,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TemplateUtils.h"
 #include "clang/AST/VTableBuilder.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/FileManager.h"
@@ -1999,35 +2000,23 @@
 const TemplateArgument  = Args.Args[i];
 StringRef Name;
 bool defaultParameter = false;
-if (Args.TList)
+if (Args.TList) {
   Name = Args.TList->getParam(i)->getName();
+
+  NamedDecl const *ND = Args.TList->getParam(i);
+  defaultParameter = TemplateUtils::isSubstitutedDefaultArgument(
+  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
+}
+
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
-
-  if (Args.TList)
-if (auto *templateType =
-
dyn_cast_or_null(Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument() == TA.getAsType();
-
   TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
   TheCU, Name, TTy, defaultParameter));
 
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList)
-if (auto *templateType = dyn_cast_or_null(
-Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument() &&
-  !templateType->getDefaultArgument()->isValueDependent())
-defaultParameter = llvm::APSInt::isSameValue(
-templateType->getDefaultArgument()->EvaluateKnownConstInt(
-CGM.getContext()),
-TA.getAsIntegral());
-
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
   TheCU, Name, TTy, defaultParameter,
   llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral(;


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ 

[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

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

- Remove now redundant `isSubstitutedDefaultArgument` call


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -518,10 +518,10 @@
 /// \param Name Value parameter name.
 /// \param Ty   Parameter type.
 /// \param Val  The fully qualified name of the template.
-DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
-  StringRef Name,
-  DIType *Ty,
-  StringRef Val);
+/// \param IsDefaultParameter is default or not.
+DITemplateValueParameter *
+createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty,
+StringRef Val, bool IsDefault);
 
 /// Create debugging information for a template parameter pack.
 /// \param ScopeScope in which this type is defined.
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -23,17 +23,37 @@
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
+// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B1_TYPE:[0-9]+]]
+// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
+
+// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B2_TYPE:[0-9]+]]
+// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
+
 template 
 class bar {
 };
 
+template 
+class qux {
+};
+
 template >
 class foo {
 };
 
+template  class CT = bar>
+class baz {
+};
+
 int main() {
   foo f1;
   foo<> f2;
+  baz b1;
+  baz<> b2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2092,7 +2092,7 @@
   TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
   OS, getPrintingPolicy());
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-  TheCU, Name, nullptr, OS.str()));
+  TheCU, Name, nullptr, OS.str(), defaultParameter));
   break;
 }
 case TemplateArgument::Pack:


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: 

[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, dblaikie.
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.

After this patch, in the following snippet:

  template  Foo {};
  
  template  class CT = Foo> Bar {};
  
  Bar<> b;

The debug-info entry for the `CT` template parameter will have
a `DW_AT_default_value (true)` attached to it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139989

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp

Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -518,10 +518,10 @@
 /// \param Name Value parameter name.
 /// \param Ty   Parameter type.
 /// \param Val  The fully qualified name of the template.
-DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
-  StringRef Name,
-  DIType *Ty,
-  StringRef Val);
+/// \param IsDefaultParameter is default or not.
+DITemplateValueParameter *
+createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty,
+StringRef Val, bool IsDefault);
 
 /// Create debugging information for a template parameter pack.
 /// \param ScopeScope in which this type is defined.
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -22,17 +22,37 @@
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, defaulted: true, value: i1 true)
 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, defaulted: true)
 
+// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B1_TYPE:[0-9]+]]
+// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
+
+// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B2_TYPE:[0-9]+]]
+// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
+
 template 
 class bar {
 };
 
+template 
+class qux {
+};
+
 template >
 class foo {
 };
 
+template  class CT = bar>
+class baz {
+};
+
 int main() {
   foo f1;
   foo<> f2;
+  baz b1;
+  baz<> b2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2091,12 +2091,18 @@
   TheCU, Name, TTy, defaultParameter, V));
 } break;
 case TemplateArgument::Template: {
+  if (Args.TList) {
+NamedDecl const *ND = Args.TList->getParam(i);
+defaultParameter = TemplateUtils::isSubstitutedDefaultArgument(
+CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
+  }
+
   std::string QualName;
   llvm::raw_string_ostream OS(QualName);
   TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
   OS, getPrintingPolicy());
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-  TheCU, Name, nullptr, OS.str()));
+  TheCU, Name, nullptr, OS.str(), defaultParameter));
   break;
 }
 case TemplateArgument::Pack:
___
cfe-commits 

[PATCH] D139985: [clang][AST][NFC] Move isSubstitutedDefaultArgument out of TypePrinter into separate component

2022-12-13 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A use-case has come up in DWARF CodeGen where we want to determine
whether a particular template argument matches the default template
parameter declaration.

Re-using this TypePrinter component there allows us to avoid duplicating
most of this code and immediately allows us to cover a wider range
of use-cases than the DWARF CodeGen does today.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139985

Files:
  clang/include/clang/AST/TemplateUtils.h
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/TemplateUtils.cpp
  clang/lib/AST/TypePrinter.cpp

Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
+#include "clang/AST/TemplateUtils.h"
 #include "clang/AST/TextNodeDumper.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/AddressSpaces.h"
@@ -1936,140 +1937,6 @@
   return A.getArgument().print(PP, OS, IncludeType);
 }
 
-static bool isSubstitutedTemplateArgument(ASTContext , TemplateArgument Arg,
-  TemplateArgument Pattern,
-  ArrayRef Args,
-  unsigned Depth);
-
-static bool isSubstitutedType(ASTContext , QualType T, QualType Pattern,
-  ArrayRef Args, unsigned Depth) {
-  if (Ctx.hasSameType(T, Pattern))
-return true;
-
-  // A type parameter matches its argument.
-  if (auto *TTPT = Pattern->getAs()) {
-if (TTPT->getDepth() == Depth && TTPT->getIndex() < Args.size() &&
-Args[TTPT->getIndex()].getKind() == TemplateArgument::Type) {
-  QualType SubstArg = Ctx.getQualifiedType(
-  Args[TTPT->getIndex()].getAsType(), Pattern.getQualifiers());
-  return Ctx.hasSameType(SubstArg, T);
-}
-return false;
-  }
-
-  // FIXME: Recurse into array types.
-
-  // All other cases will need the types to be identically qualified.
-  Qualifiers TQual, PatQual;
-  T = Ctx.getUnqualifiedArrayType(T, TQual);
-  Pattern = Ctx.getUnqualifiedArrayType(Pattern, PatQual);
-  if (TQual != PatQual)
-return false;
-
-  // Recurse into pointer-like types.
-  {
-QualType TPointee = T->getPointeeType();
-QualType PPointee = Pattern->getPointeeType();
-if (!TPointee.isNull() && !PPointee.isNull())
-  return T->getTypeClass() == Pattern->getTypeClass() &&
- isSubstitutedType(Ctx, TPointee, PPointee, Args, Depth);
-  }
-
-  // Recurse into template specialization types.
-  if (auto *PTST =
-  Pattern.getCanonicalType()->getAs()) {
-TemplateName Template;
-ArrayRef TemplateArgs;
-if (auto *TTST = T->getAs()) {
-  Template = TTST->getTemplateName();
-  TemplateArgs = TTST->template_arguments();
-} else if (auto *CTSD = dyn_cast_or_null(
-   T->getAsCXXRecordDecl())) {
-  Template = TemplateName(CTSD->getSpecializedTemplate());
-  TemplateArgs = CTSD->getTemplateArgs().asArray();
-} else {
-  return false;
-}
-
-if (!isSubstitutedTemplateArgument(Ctx, Template, PTST->getTemplateName(),
-   Args, Depth))
-  return false;
-if (TemplateArgs.size() != PTST->template_arguments().size())
-  return false;
-for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
-  if (!isSubstitutedTemplateArgument(
-  Ctx, TemplateArgs[I], PTST->template_arguments()[I], Args, Depth))
-return false;
-return true;
-  }
-
-  // FIXME: Handle more cases.
-  return false;
-}
-
-static bool isSubstitutedTemplateArgument(ASTContext , TemplateArgument Arg,
-  TemplateArgument Pattern,
-  ArrayRef Args,
-  unsigned Depth) {
-  Arg = Ctx.getCanonicalTemplateArgument(Arg);
-  Pattern = Ctx.getCanonicalTemplateArgument(Pattern);
-  if (Arg.structurallyEquals(Pattern))
-return true;
-
-  if (Pattern.getKind() == TemplateArgument::Expression) {
-if (auto *DRE =
-dyn_cast(Pattern.getAsExpr()->IgnoreParenImpCasts())) {
-  if (auto *NTTP = dyn_cast(DRE->getDecl()))
-return NTTP->getDepth() == Depth && Args.size() > NTTP->getIndex() &&
-   Args[NTTP->getIndex()].structurallyEquals(Arg);
-}
-  }
-
-  if (Arg.getKind() != Pattern.getKind())
-return false;
-
-  if (Arg.getKind() == TemplateArgument::Type)
-return isSubstitutedType(Ctx, Arg.getAsType(), Pattern.getAsType(), Args,
- Depth);
-
-  if (Arg.getKind() == 

[PATCH] D139988: [clang][DebugInfo] Re-use clang::TemplateUtils to determine guide DW_AT_default_value for template parameters

2022-12-13 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.

DWARFv5 added support for labelling template parameters with
DW_AT_default_value to indicate whether the particular instantiation
defaulted parameter. The current implementation only supports a limited
set of possible cases. Namely for non-value-dependent integral template
parameters and simple type template parameters.

Useful cases that don't work are:

1. Type template parameters where the type is itself a template instantiation 
(e.g., `template>`)
2. Template template parameters

`clang::TempalteUtils` already implement the required logic to determine
whether a template argument is defaulted. This patch re-uses this logic
for DWARF CodeGen.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139988

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


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -6,26 +6,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
-// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
value: i32 6)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i8 0)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i1 false)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}})
 
 // CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F2_TYPE:[0-9]+]]
-// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, 
defaulted: true)
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
defaulted: true, value: i32 3)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
-template 
+template 
+class bar {
+};
+
+template >
 class foo {
 };
 
 int main() {
-  foo f1;
+  foo f1;
   foo<> f2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -26,6 +26,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TemplateUtils.h"
 #include "clang/AST/VTableBuilder.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/FileManager.h"
@@ -2002,12 +2003,11 @@
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
 
-  if (Args.TList)
-if (auto *templateType =
-
dyn_cast_or_null(Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument() == TA.getAsType();
+  if (Args.TList) {
+NamedDecl const *ND = Args.TList->getParam(i);
+defaultParameter = TemplateUtils::isSubstitutedDefaultArgument(
+CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
+  }
 
   TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
   TheCU, Name, TTy, defaultParameter));
@@ -2015,15 +2015,11 @@
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList && CGM.getCodeGenOpts().DwarfVersion >= 5)
-if (auto *templateType = dyn_cast_or_null(
-Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument() &&
-  !templateType->getDefaultArgument()->isValueDependent())
-defaultParameter = llvm::APSInt::isSameValue(
-

[PATCH] D140084: [llvm][test] Split DW_AT_default_value check out of clang/test/

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

In D140084#3997123 , @dblaikie wrote:

> Sorry, should've caught this in review. The clang change needs test coverage 
> in clang, but should verify the emitted it, rather than going all the way 
> down to object code.
>
> The llvm functionality is already tested (since it's just the flag on a 
> template parameter - it's not interesting to test that for different kinds of 
> templates if the flag handling is kind-agnostic anyway)

I couldn't find any test inside `llvm/test` which verifies that 
`DW_AT_default_value` is being emitted correctly. Sure we don't need a test 
like that?

> So instead of this could you adjust the existing clang test to verify IR 
> instead of dwarfdump?

@dblaikie Isn't the clang test already doing that? In this test I mainly wanted 
to check that the `gstrict-dwarf` attribute works as expected. The IR will 
always have the default attribute attached to it, which the `clang/test/` 
already tests.

But if this is redundant I don't mind just removing this test altogether


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140084

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-12-04 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

FYI, looks like this broke the LLDB incremental buildbot. Following tests 
started failing:

  
lldb-api.commands/expression/argument_passing_restrictions.TestArgumentPassingRestrictions.py
  
lldb-api.commands/expression/deleting-implicit-copy-constructor.TestDeletingImplicitCopyConstructor.py
  lldb-api.commands/expression/diagnostics.TestExprDiagnostics.py
  lldb-api.commands/expression/import-std-module/array.TestArrayFromStdModule.py
  
lldb-api.commands/expression/import-std-module/module-build-errors.TestStdModuleBuildErrors.py
  lldb-api.commands/expression/rdar44436068.Test128BitsInteger.py
  lldb-api.commands/expression/weak_symbols.TestWeakSymbols.py
  lldb-api.commands/target/dump-pcm-info.TestDumpPCMInfo.py
  lldb-api.functionalities/data-formatter/compactvectors.TestCompactVectors.py
  
lldb-api.functionalities/tail_call_frames/cross_object.TestCrossObjectTailCalls.py
  lldb-api.functionalities/target_var/no_vars.TestTargetVarNoVars.py
  lldb-api.lang/c/modules.TestCModules.py
  lldb-api.lang/cpp/accelerator-table.TestCPPAccelerator.py
  lldb-api.lang/cpp/modules-import.TestCXXModulesImport.py
  lldb-api.lang/objc/modules.TestObjCModules.py
  lldb-api.lang/objc/modules-auto-import.TestModulesAutoImport.py
  lldb-api.lang/objc/modules-cache.TestClangModulesCache.py
  lldb-api.lang/objc/modules-compile-error.TestModulesCompileError.py
  lldb-api.lang/objc/modules-incomplete.TestIncompleteModules.py
  lldb-api.lang/objc/modules-inline-functions.TestModulesInlineFunctions.py
  lldb-api.lang/objc/modules-non-objc-target.TestObjCModulesNonObjCTarget.py
  lldb-api.lang/objc/modules-objc-property.TestModulesObjCProperty.py
  lldb-api.tools/lldb-server.TestLldbGdbServer.py

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/48872/
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/48873/

Last successful build: 
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/48871/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127284

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-12-04 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D127284#3969308 , @v.g.vassilev 
wrote:

> In D127284#3969249 , @v.g.vassilev 
> wrote:
>
>> In D127284#3969225 , @Michael137 
>> wrote:
>>
>>> FYI, looks like this broke the LLDB incremental buildbot. Following tests 
>>> started failing:
>>>
>>>   
>>> lldb-api.commands/expression/argument_passing_restrictions.TestArgumentPassingRestrictions.py
>>>   
>>> lldb-api.commands/expression/deleting-implicit-copy-constructor.TestDeletingImplicitCopyConstructor.py
>>>   lldb-api.commands/expression/diagnostics.TestExprDiagnostics.py
>>>   
>>> lldb-api.commands/expression/import-std-module/array.TestArrayFromStdModule.py
>>>   
>>> lldb-api.commands/expression/import-std-module/module-build-errors.TestStdModuleBuildErrors.py
>>>   lldb-api.commands/expression/rdar44436068.Test128BitsInteger.py
>>>   lldb-api.commands/expression/weak_symbols.TestWeakSymbols.py
>>>   lldb-api.commands/target/dump-pcm-info.TestDumpPCMInfo.py
>>>   
>>> lldb-api.functionalities/data-formatter/compactvectors.TestCompactVectors.py
>>>   
>>> lldb-api.functionalities/tail_call_frames/cross_object.TestCrossObjectTailCalls.py
>>>   lldb-api.functionalities/target_var/no_vars.TestTargetVarNoVars.py
>>>   lldb-api.lang/c/modules.TestCModules.py
>>>   lldb-api.lang/cpp/accelerator-table.TestCPPAccelerator.py
>>>   lldb-api.lang/cpp/modules-import.TestCXXModulesImport.py
>>>   lldb-api.lang/objc/modules.TestObjCModules.py
>>>   lldb-api.lang/objc/modules-auto-import.TestModulesAutoImport.py
>>>   lldb-api.lang/objc/modules-cache.TestClangModulesCache.py
>>>   lldb-api.lang/objc/modules-compile-error.TestModulesCompileError.py
>>>   lldb-api.lang/objc/modules-incomplete.TestIncompleteModules.py
>>>   lldb-api.lang/objc/modules-inline-functions.TestModulesInlineFunctions.py
>>>   lldb-api.lang/objc/modules-non-objc-target.TestObjCModulesNonObjCTarget.py
>>>   lldb-api.lang/objc/modules-objc-property.TestModulesObjCProperty.py
>>>   lldb-api.tools/lldb-server.TestLldbGdbServer.py
>>>
>>> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/48872/
>>> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/48873/
>>>
>>> Last successful build: 
>>> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/48871/
>>
>> Hi @Michael137, I cannot reproduce these failures on unix. Is there some 
>> special way I need to compile. I will try reproducing them on OSX. Did you 
>> have time to debug where the tests fail?
>
> I cannot reproduce this on osx either.

Hmmm how are you running the tests? It reproduces pretty consistently with the 
patch and doesn't without it. I just run `ninja check-lldb-api`

Let me try with a clean build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127284

___
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 , const llvm::APSInt ,
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) { 

[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] 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  : 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  = 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  : 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  = 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] 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 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 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 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] 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  = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const  = 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 , const llvm::APSInt ,
-   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 ,
+TemplateParameterList const *Params,
+ArrayRef Args) {
+  int i = 0;
+  auto MutArgs = Args.copy(Ctx);
+  for (auto  : 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 , Kind DK, TagKind TK,
-DeclContext *DC, SourceLocation StartLoc,
-SourceLocation IdLoc,
-ClassTemplateDecl *SpecializedTemplate,
-ArrayRef Args,
-ClassTemplateSpecializationDecl *PrevDecl)
+ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(
+ASTContext , 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 ,
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 

[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] 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  = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const  = 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 , const llvm::APSInt ,
-   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 ,
+TemplateParameterList const *Params,
+ArrayRef Args) {
+  int i = 0;
+  auto MutArgs = Args.copy(Ctx);
+  for (auto  : 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 , Kind DK, TagKind TK,
-DeclContext *DC, SourceLocation StartLoc,
-SourceLocation IdLoc,
-ClassTemplateDecl *SpecializedTemplate,
-ArrayRef Args,
-ClassTemplateSpecializationDecl *PrevDecl)
+ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(
+ASTContext , 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 ,
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6739,26 +6739,29 @@
 
 case 

[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  = TPL->getParam(0)->getASTContext();
 llvm::SmallVector OrigArgs;
 for (const TA  : 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  = TPL->getParam(0)->getASTContext();
 llvm::SmallVector OrigArgs;
 for (const TA  : 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  = 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  = 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] Dont 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] 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  = 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  = 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-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  = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const  = 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 , const llvm::APSInt ,
-   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
 //===--===//
 
-ClassTemplateSpecializationDecl::

[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  = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const  = 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 , const llvm::APSInt ,
-   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 

[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: [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  = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const  = 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 , const llvm::APSInt ,
-   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()),

[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  = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const  = 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 , const llvm::APSInt ,
-   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()),
+  /*isNullPtr*/ false, 

[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  = 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  = 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  = 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' evaluates to 

[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 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  = 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  = 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  = 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 

[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 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
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] 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  = AST->getASTContext();
+
+  auto const *CTSD = selectFirst(
+  "id",
+  match(classTemplateSpecializationDecl(hasName("Foo")).bind("id"), Ctx));
+  ASSERT_NE(CTSD, nullptr);
+  auto const  = 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 , const llvm::APSInt ,
-   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 

[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  = 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  = 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  = TPL->getParam(0)->getASTContext();
 llvm::SmallVector OrigArgs;
 for (const TA  : 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  = TPL->getParam(0)->getASTContext();
 llvm::SmallVector OrigArgs;
 for (const TA  : 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] 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  = 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  = 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  = 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
@@ 

[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  = ToSpec->getTemplateArgs();
+  for (auto const  : 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  = ToSpec->getTemplateArgs();
+  for (auto const  : 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 

[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,

[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
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  = ToSpec->getTemplateArgs();
+  for (auto const  : 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  = ToSpec->getTemplateArgs();
+  for (auto const  : 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 = 

[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] 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] 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] 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] 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


  1   2   >