Author: Raphael Isemann
Date: 2020-11-26T18:01:30+01:00
New Revision: 3f6c856bb5ae4426a586426bca9f1ef2848a2b12

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

LOG: [ASTImporter] Import the default argument of TemplateTypeParmDecl

The test case isn't using the AST matchers for all checks as there doesn't seem 
to be support for
matching TemplateTypeParmDecl default arguments. Otherwise this is simply 
importing the
default arguments.

Also updates several LLDB tests that now as intended omit the default template
arguments of several std templates.

Reviewed By: martong

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

Added: 
    

Modified: 
    clang/lib/AST/ASTImporter.cpp
    clang/unittests/AST/ASTImporterTest.cpp
    
lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/list/TestListFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/queue/TestQueueFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py
    
lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/vector-bool/TestVectorBoolFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
    
lldb/test/API/commands/expression/import-std-module/vector/TestVectorFromStdModule.py

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 835551528e0d..5159682da85f 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -5158,8 +5158,6 @@ 
ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   // context. This context will be fixed when the actual template declaration
   // is created.
 
-  // FIXME: Import default argument  and constraint expression.
-
   ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
   if (!BeginLocOrErr)
     return BeginLocOrErr.takeError();
@@ -5206,6 +5204,14 @@ 
ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
         ToIDC);
   }
 
+  if (D->hasDefaultArgument()) {
+    Expected<TypeSourceInfo *> ToDefaultArgOrErr =
+        import(D->getDefaultArgumentInfo());
+    if (!ToDefaultArgOrErr)
+      return ToDefaultArgOrErr.takeError();
+    ToD->setDefaultArgument(*ToDefaultArgOrErr);
+  }
+
   return ToD;
 }
 

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 33e4b7226fba..5a93a7348e7a 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -880,6 +880,25 @@ TEST_P(ImportExpr, DependentSizedArrayType) {
                  has(fieldDecl(hasType(dependentSizedArrayType())))))));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateTypeParmDeclNoDefaultArg) {
+  Decl *FromTU = getTuDecl("template<typename T> struct X {};", Lang_CXX03);
+  auto From = FirstDeclMatcher<TemplateTypeParmDecl>().match(
+      FromTU, templateTypeParmDecl(hasName("T")));
+  TemplateTypeParmDecl *To = Import(From, Lang_CXX03);
+  ASSERT_FALSE(To->hasDefaultArgument());
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateTypeParmDeclDefaultArg) {
+  Decl *FromTU =
+      getTuDecl("template<typename T = int> struct X {};", Lang_CXX03);
+  auto From = FirstDeclMatcher<TemplateTypeParmDecl>().match(
+      FromTU, templateTypeParmDecl(hasName("T")));
+  TemplateTypeParmDecl *To = Import(From, Lang_CXX03);
+  ASSERT_TRUE(To->hasDefaultArgument());
+  QualType ToArg = To->getDefaultArgument();
+  ASSERT_EQ(ToArg, QualType(To->getASTContext().IntTy));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportBeginLocOfDeclRefExpr) {
   Decl *FromTU =
       getTuDecl("class A { public: static int X; }; void f() { (void)A::X; }",

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
index 18bd8ae37ff9..0eaa50a12727 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
@@ -22,7 +22,7 @@ def test(self):
 
         self.runCmd("settings set target.import-std-module true")
 
-        deque_type = "std::deque<int, std::allocator<int> >"
+        deque_type = "std::deque<int>"
         size_type = deque_type + "::size_type"
         value_type = "std::__deque_base<int, std::allocator<int> >::value_type"
         iterator = deque_type + "::iterator"

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
index e014f08d8509..5a1f1fc4d6ac 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
@@ -22,7 +22,7 @@ def test(self):
 
         self.runCmd("settings set target.import-std-module true")
 
-        deque_type = "std::deque<Foo, std::allocator<Foo> >"
+        deque_type = "std::deque<Foo>"
         size_type = deque_type + "::size_type"
         value_type = "std::__deque_base<Foo, std::allocator<Foo> >::value_type"
 

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
index 704cbc8168fa..b1f206d72197 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
@@ -22,7 +22,7 @@ def test(self):
 
         self.runCmd("settings set target.import-std-module true")
 
-        list_type = "std::forward_list<Foo, std::allocator<Foo> >"
+        list_type = "std::forward_list<Foo>"
         value_type = list_type + "::value_type"
 
         # FIXME: This has three elements in it but the formatter seems to

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
index 12d9a9930890..9c4bf83cfcb8 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
@@ -22,7 +22,7 @@ def test(self):
 
         self.runCmd("settings set target.import-std-module true")
 
-        list_type = "std::forward_list<int, std::allocator<int> >"
+        list_type = "std::forward_list<int>"
         value_type = list_type + "::value_type"
 
         # FIXME: This has three elements in it but the formatter seems to

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
index fea6caaadf71..94d9ca72b220 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
@@ -23,7 +23,7 @@ def test(self):
 
         self.runCmd("settings set target.import-std-module true")
 
-        list_type = "std::list<Foo, std::allocator<Foo> >"
+        list_type = "std::list<Foo>"
         size_type = list_type + "::size_type"
         value_type = list_type + "::value_type"
 

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/list/TestListFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/list/TestListFromStdModule.py
index 9382c800ec76..0d7d915fcaa5 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/list/TestListFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/list/TestListFromStdModule.py
@@ -22,7 +22,7 @@ def test(self):
 
         self.runCmd("settings set target.import-std-module true")
 
-        list_type = "std::list<int, std::allocator<int> >"
+        list_type = "std::list<int>"
         size_type = list_type + "::size_type"
         value_type = list_type + "::value_type"
 

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/queue/TestQueueFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/queue/TestQueueFromStdModule.py
index 75cc98c15055..06f77ba5a9e7 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/queue/TestQueueFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/queue/TestQueueFromStdModule.py
@@ -22,7 +22,7 @@ def test(self):
 
         self.runCmd("settings set target.import-std-module true")
 
-        queue_type = "std::queue<C, std::deque<C, std::allocator<C> > >"
+        queue_type = "std::queue<C>"
         size_type = queue_type + "::size_type"
         value_type = "std::__deque_base<C, std::allocator<C> >::value_type"
 
@@ -54,9 +54,9 @@ def test(self):
                          result_value="5")
 
         # Test std::queue functionality with a std::list.
-        queue_type = "std::queue<C, std::list<C, std::allocator<C> > >"
+        queue_type = "std::queue<C, std::list<C> >"
         size_type = queue_type + "::size_type"
-        value_type = "std::list<C, std::allocator<C> >::value_type"
+        value_type = "std::list<C>::value_type"
         self.expect_expr(
             "q_list",
             result_type=queue_type,

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
index d9a7e186fa6f..4486768e2909 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
@@ -22,7 +22,7 @@ def test(self):
         self.runCmd("settings set target.import-std-module true")
 
         # Test std::stack functionality with a std::deque.
-        stack_type = "std::stack<C, std::deque<C, std::allocator<C> > >"
+        stack_type = "std::stack<C>"
         size_type = stack_type + "::size_type"
 
         self.expect_expr("s_deque", result_type=stack_type)
@@ -40,7 +40,7 @@ def test(self):
                          result_value="5")
 
         # Test std::stack functionality with a std::vector.
-        stack_type = "std::stack<C, std::vector<C, std::allocator<C> > >"
+        stack_type = "std::stack<C, std::vector<C> >"
         size_type = stack_type + "::size_type"
 
         self.expect_expr("s_vector", result_type=stack_type)
@@ -58,7 +58,7 @@ def test(self):
                          result_value="5")
 
         # Test std::stack functionality with a std::list.
-        stack_type = "std::stack<C, std::list<C, std::allocator<C> > >"
+        stack_type = "std::stack<C, std::list<C> >"
         size_type = stack_type + "::size_type"
         self.expect_expr("s_list", result_type=stack_type)
         self.expect("expr s_list.pop()")

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py
 
b/lldb/test/API/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py
index 9f698af7e1b4..abc9c1931489 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py
@@ -25,7 +25,7 @@ def test(self):
 
         self.expect_expr(
             "s",
-            result_type="std::unique_ptr<Foo, std::default_delete<Foo> >",
+            result_type="std::unique_ptr<Foo>",
             result_children=[ValueCheck(children=[ValueCheck(value="3")])])
         self.expect_expr("s->a", result_type="int", result_value="3")
         self.expect_expr("s->a = 5", result_type="int", result_value="5")

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
index a3761ade04e3..878315b8eafd 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
@@ -25,7 +25,7 @@ def test(self):
 
         self.expect_expr(
             "s",
-            result_type="std::unique_ptr<int, std::default_delete<int> >",
+            result_type="std::unique_ptr<int>",
             result_summary="3",
             result_children=[ValueCheck(name="__value_")])
         self.expect_expr("*s", result_type="int", result_value="3")

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/vector-bool/TestVectorBoolFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-bool/TestVectorBoolFromStdModule.py
index 0f0279e4c017..79e7478e485e 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-bool/TestVectorBoolFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-bool/TestVectorBoolFromStdModule.py
@@ -20,7 +20,7 @@ def test(self):
                                           "// Set break point at this line.",
                                           lldb.SBFileSpec("main.cpp"))
 
-        vector_type = "std::vector<bool, std::allocator<bool> >"
+        vector_type = "std::vector<bool>"
         size_type = vector_type + "::size_type"
 
         self.runCmd("settings set target.import-std-module true")

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
index 6537178e03e6..d53a9bfb5901 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -23,7 +23,7 @@ def test(self):
 
         self.runCmd("settings set target.import-std-module true")
 
-        vector_type = "std::vector<Foo, std::allocator<Foo> >"
+        vector_type = "std::vector<Foo>"
         size_type = vector_type + "::size_type"
         value_type = vector_type + "::value_type"
         iterator = vector_type + "::iterator"

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
index bb1d736689ca..e0b511c91bd0 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
@@ -20,13 +20,9 @@ def test(self):
                                           "// Set break point at this line.",
                                           lldb.SBFileSpec("main.cpp"))
 
-        vector_type = "std::vector<int, std::allocator<int> >"
-        vector_of_vector_type = "std::vector<" + vector_type + \
-            ", std::allocator<std::vector<int, std::allocator<int> > > >"
-        size_type = (
-            "std::vector<std::vector<int, std::allocator<int> >, " +
-            "std::allocator<std::vector<int, std::allocator<int> > >" +
-            " >::size_type")
+        vector_type = "std::vector<int>"
+        vector_of_vector_type = "std::vector<" + vector_type + " >"
+        size_type = vector_of_vector_type + "::size_type"
         value_type = "std::__vector_base<int, std::allocator<int> 
>::value_type"
 
         self.runCmd("settings set target.import-std-module true")
@@ -35,13 +31,13 @@ def test(self):
             "a",
             result_type=vector_of_vector_type,
             result_children=[
-                ValueCheck(type="std::vector<int, std::allocator<int> >",
+                ValueCheck(type="std::vector<int>",
                            children=[
                                ValueCheck(value='1'),
                                ValueCheck(value='2'),
                                ValueCheck(value='3'),
                            ]),
-                ValueCheck(type="std::vector<int, std::allocator<int> >",
+                ValueCheck(type="std::vector<int>",
                            children=[
                                ValueCheck(value='3'),
                                ValueCheck(value='2'),

diff  --git 
a/lldb/test/API/commands/expression/import-std-module/vector/TestVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector/TestVectorFromStdModule.py
index c9e1c94eb415..9a186e7a2243 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector/TestVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector/TestVectorFromStdModule.py
@@ -22,7 +22,7 @@ def test(self):
 
         self.runCmd("settings set target.import-std-module true")
 
-        vector_type = "std::vector<int, std::allocator<int> >"
+        vector_type = "std::vector<int>"
         size_type = vector_type + "::size_type"
         value_type = "std::__vector_base<int, std::allocator<int> 
>::value_type"
         iterator = vector_type + "::iterator"


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

Reply via email to