[clang] d194d81 - [clang][ASTImporter] Propagate TemplateArgument::IsDefaulted during import
Michael Buch via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 27 08:39:38 PST 2023
Author: Michael Buch
Date: 2023-01-27T16:39:17Z
New Revision: d194d817b0b29c6e244d01cf7b836b9e4bbe2794
URL: https://github.com/llvm/llvm-project/commit/d194d817b0b29c6e244d01cf7b836b9e4bbe2794
DIFF: https://github.com/llvm/llvm-project/commit/d194d817b0b29c6e244d01cf7b836b9e4bbe2794.diff
LOG: [clang][ASTImporter] Propagate TemplateArgument::IsDefaulted during import
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
Differential Revision: https://reviews.llvm.org/D142713
Added:
Modified:
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 6f367ef053d2c..e9bac0d0529d4 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -836,7 +836,8 @@ ASTNodeImporter::import(const TemplateArgument &From) {
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 @@ ASTNodeImporter::import(const TemplateArgument &From) {
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 @@ ASTNodeImporter::import(const TemplateArgument &From) {
if (!ToTemplateOrErr)
return ToTemplateOrErr.takeError();
- return TemplateArgument(*ToTemplateOrErr);
+ return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
}
case TemplateArgument::TemplateExpansion: {
@@ -877,13 +879,13 @@ ASTNodeImporter::import(const TemplateArgument &From) {
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();
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index cd33d5017481c..1080b5acd4b30 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -1158,6 +1158,26 @@ TEST_P(ASTImporterOptionSpecificTestBase, NonTypeTemplateParmDeclDefaultArg) {
ASSERT_EQ(cast<IntegerLiteral>(ToArg)->getValue().getLimitedValue(), 1U);
}
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateArgumentsDefaulted) {
+ Decl *FromTU = getTuDecl(R"(
+ template<typename T> struct X {};
+ template<typename TP = double,
+ int NTTP = 50,
+ template<typename> typename TT = X> struct S {};
+ S<> s;
+ )",
+ Lang_CXX17);
+ auto *FromSpec = FirstDeclMatcher<ClassTemplateSpecializationDecl>().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<class X> struct S{};", Lang_CXX03);
More information about the cfe-commits
mailing list