Skip to content
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

LLVM 19: Build failures #142

Closed
marxin opened this issue May 18, 2024 · 8 comments · Fixed by #143
Closed

LLVM 19: Build failures #142

marxin opened this issue May 18, 2024 · 8 comments · Fixed by #143

Comments

@marxin
Copy link
Owner

marxin commented May 18, 2024

The following needs to be ported to the latest LLVM tip:

In file included from /tmp/cvise/clang_delta/ReplaceDerivedClass.cpp:19:
/tmp/cvise/clang_delta/CommonRenameClassRewriteVisitor.h: In member function 'bool clang_delta_common_visitor::CommonRenameClassRewriteVisitor<T>::VisitClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl*)':
/tmp/cvise/clang_delta/CommonRenameClassRewriteVisitor.h:147:39: error: 'class clang::ClassTemplatePartialSpecializationDecl' has no member named 'getTypeAsWritten'
  147 |     const TypeSourceInfo *TyInfo = D->getTypeAsWritten();
      |                                       ^~~~~~~~~~~~~~~~
/tmp/cvise/clang_delta/RemoveNamespace.cpp: In member function 'bool RemoveNamespaceRewriteVisitor::VisitClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl*)':
/tmp/cvise/clang_delta/RemoveNamespace.cpp:442:39: error: 'class clang::ClassTemplatePartialSpecializationDecl' has no member named 'getTypeAsWritten'
  442 |     const TypeSourceInfo *TyInfo = D->getTypeAsWritten();
      |                                       ^~~~~~~~~~~~~~~~

Can @nickdesaulniers or @strimo378 help me, please?

@nickdesaulniers
Copy link
Contributor

nickdesaulniers commented May 19, 2024

Looks like in llvm/llvm-project#91393, getTypeAsWritten was replaced with getTemplateArgsAsWritten.

IWYU also tripped over this.

@marxin
Copy link
Owner Author

marxin commented May 28, 2024

Yep, it was replaced, but I don't see how can we get to the location of the type name as getTemplateArgsAsWritten returns something that describes the template arguments. Please let me know once you have a hint, thanks.

@nickdesaulniers
Copy link
Contributor

nickdesaulniers commented May 29, 2024 via email

@nickdesaulniers
Copy link
Contributor

nickdesaulniers commented May 29, 2024 via email

@sdkrystian
Copy link
Contributor

@marxin @nickdesaulniers the TemplateSpecializationTypeLoc returned by getTypeAsWritten stores the same SourceLocation for its TemplateName as that returned by ClassTemplateSpecializationDecl::getLocation (so you should change the code to use the latter).

Also, I think the existing code contains a subtile bug: it assumes TypeLoc::getBeginLoc returns the location of the name; for explicit instantiations it will actually return the location of the template keyword!

@marxin
Copy link
Owner Author

marxin commented May 29, 2024

Thanks for the suggestions. With the following changes applied:

diff --git a/clang_delta/CommonRenameClassRewriteVisitor.h b/clang_delta/CommonRenameClassRewriteVisitor.h
index f2daeb2..ecbe4f1 100644
--- a/clang_delta/CommonRenameClassRewriteVisitor.h
+++ b/clang_delta/CommonRenameClassRewriteVisitor.h
@@ -144,7 +144,7 @@ bool CommonRenameClassRewriteVisitor<T>::
 
   std::string Name;
   if (getNewName(CXXRD, Name)) {
-    const TypeSourceInfo *TyInfo = D->getTypeAsWritten();
+    const TypeSourceInfo *TyInfo = D->getTemplateArgsAsWritten()->getTemplateArgs()->getTypeSourceInfo();
     if (!TyInfo)
       return true;
     TypeLoc TyLoc = TyInfo->getTypeLoc();
diff --git a/clang_delta/RemoveNamespace.cpp b/clang_delta/RemoveNamespace.cpp
index b31c00e..8650c49 100644
--- a/clang_delta/RemoveNamespace.cpp
+++ b/clang_delta/RemoveNamespace.cpp
@@ -439,7 +439,7 @@ bool RemoveNamespaceRewriteVisitor::VisitClassTemplatePartialSpecializationDecl(
 
   std::string Name;
   if (ConsumerInstance->getNewName(CXXRD, Name)) {
-    const TypeSourceInfo *TyInfo = D->getTypeAsWritten();
+    const TypeSourceInfo *TyInfo = D->getTemplateArgsAsWritten()->getTemplateArgs()->getTypeSourceInfo();
     if (!TyInfo)
       return true;
     TypeLoc TyLoc = TyInfo->getTypeLoc();

I've got the following failing tests:

cls = <class 'test_clang_delta.TestClangDelta'>, testcase = 'rename-class/instantiation.cpp', arguments = '--transformation=rename-class --counter=1', output_file = 'rename-class/instantiation.output'
E       AssertionError: assert 'template <typename T>\nstruct A {};\n\ntemplate struct AAA<int>;\n' == 'template <typename T>\nstruct A {};\n\ntemplate struct A<int>;\n'
E           template <typename T>
E           struct A {};
E           
E         - template struct A<int>;
E         + template struct AAA<int>;
E         ?                 ++

Here it seems the renaming happens only for the original struct, not the later one.

cls = <class 'test_clang_delta.TestClangDelta'>, testcase = 'rename-class/partial_specialization.cpp', arguments = '--transformation=rename-class --counter=1', output_file = 'rename-class/partial_specialization.output'
E       AssertionError: assert 'template <typename T, int N>\nstruct A {\n  T value() const { return N; }\n};\n\ntemplate <typename T>\nstruct S1 <A 3> {\n  T value() const { return 0; }\n};\n\n' == 'template <typename T, int N>\nstruct A {\n  T value() const { return N; }\n};\n\ntemplate <typename T>\nstruct A <T, 3> {\n  T value() const { return 0; }\n};\n\n'
E           template <typename T, int N>
E           struct A {
E             T value() const { return N; }
E           };
E           
E           template <typename T>
E         - struct A <T, 3> {
E         ?         ----
E         + struct S1 <A 3> {
E         ?        ++++
E             T value() const { return 0; }
E           };

And here it seems the location really points to the first template argument (rather than to the S1).

cls = <class 'test_clang_delta.TestClangDelta'>, testcase = 'rename-class/specialization.cpp', arguments = '--transformation=rename-class --counter=1', output_file = 'rename-class/specialization.output'
E       AssertionError: assert 'template <typename T>\nstruct A {};\n\ntemplate<> struct AAA<int> {};\n' == 'template <typename T>\nstruct A {};\n\ntemplate<> struct A<int> {};\n'
E           template <typename T>
E           struct A {};
E           
E         - template<> struct A<int> {};
E         + template<> struct AAA<int> {};
E         ?                   ++

This one is similar to the first failing test-case.

@sdkrystian
Copy link
Contributor

D->getTemplateArgsAsWritten()->getTemplateArgs()->getTypeSourceInfo() returns the TypeSourceInfo for the first template argument if it is a type, or nullptr otherwise (and this will crash if an empty template argument list was used). You want to use Decl::getLocation. I opened a PR that makes the correct changes here.

@marxin
Copy link
Owner Author

marxin commented May 29, 2024

@sdkrystian Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants