-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang][ASTImporter] Import source location of explicit object parameter instead of copying it #124305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][ASTImporter] Import source location of explicit object parameter instead of copying it #124305
Conversation
@llvm/pr-subscribers-clang Author: Michael Buch (Michael137) ChangesAdds test that confirms that we import the explicit object parameter location for Full diff: https://github.com/llvm/llvm-project/pull/124305.diff 1 Files Affected:
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 791248e7a394f1..187fe651f6f19a 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -3441,6 +3441,7 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportParmVarDecl) {
ASSERT_TRUE(FromVar);
ASSERT_TRUE(FromVar->hasUninstantiatedDefaultArg());
ASSERT_TRUE(FromVar->getUninstantiatedDefaultArg());
+ ASSERT_FALSE(FromVar->isExplicitObjectParameter());
const auto *ToVar = Import(FromVar, Lang_CXX11);
EXPECT_TRUE(ToVar);
@@ -3448,6 +3449,25 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportParmVarDecl) {
EXPECT_TRUE(ToVar->getUninstantiatedDefaultArg());
EXPECT_NE(FromVar->getUninstantiatedDefaultArg(),
ToVar->getUninstantiatedDefaultArg());
+ EXPECT_FALSE(ToVar->isExplicitObjectParameter());
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportParmVarDecl_Explicit) {
+ const auto *Code = R"(
+ struct Wrapper {
+ Wrapper(this Wrapper) {}
+ };
+ )";
+ Decl *FromTU = getTuDecl(Code, Lang_CXX23);
+ auto *FromVar = FirstDeclMatcher<ParmVarDecl>().match(FromTU, parmVarDecl());
+ ASSERT_TRUE(FromVar);
+ ASSERT_TRUE(FromVar->isExplicitObjectParameter());
+
+ const auto *ToVar = Import(FromVar, Lang_CXX23);
+ EXPECT_TRUE(ToVar);
+ EXPECT_TRUE(ToVar->isExplicitObjectParameter());
+ EXPECT_EQ(ToVar->getExplicitObjectParamThisLoc(),
+ FromVar->getExplicitObjectParamThisLoc());
}
TEST_P(ASTImporterOptionSpecificTestBase, ImportOfNonEquivalentField) {
|
…ameter Adds test that confirms that we import the explicit object parameter location for `ParmVarDecl`s. This is how Clang determines whether a parameter `isExplicitObjectParamater`. The LLDB expression evaluator relies on this for calling "explicit object member functions".
fed71d2
to
2fbabc9
Compare
EXPECT_TRUE(ToVar); | ||
EXPECT_TRUE(ToVar->isExplicitObjectParameter()); | ||
EXPECT_EQ(ToVar->getExplicitObjectParamThisLoc(), | ||
FromVar->getExplicitObjectParamThisLoc()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks not correct to copy a SourceLocation
from the "from" into the "to" context. They have a different source manager instance. Function ASTNodeImporter::ImportDefaultArgOfParmVarDecl is the place where this is done. Copy of getExplicitObjectParamThisLoc
should be replaced with normal import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea good catch, i was wondering about that when reading it initially. I'll adjust it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest commit updates code to import the location.
We used to copy the
SourceLocation
instead of importing it, which isn't correct since theSourceManager
's of the source and target ASTContext might differ.Also adds test that confirms that we import the explicit object parameter location for
ParmVarDecl
s. This is how Clang determines whether a parameterisExplicitObjectParamater
. The LLDB expression evaluator relies on this for calling "explicit object member functions".