Giter Site home page Giter Site logo

LLVM 19: Build failures about cvise HOT 8 CLOSED

marxin avatar marxin commented on September 26, 2024
LLVM 19: Build failures

from cvise.

Comments (8)

nickdesaulniers avatar nickdesaulniers commented on September 26, 2024

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

IWYU also tripped over this.

from cvise.

marxin avatar marxin commented on September 26, 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.

from cvise.

nickdesaulniers avatar nickdesaulniers commented on September 26, 2024

from cvise.

nickdesaulniers avatar nickdesaulniers commented on September 26, 2024

from cvise.

sdkrystian avatar sdkrystian commented on September 26, 2024

@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!

from cvise.

marxin avatar marxin commented on September 26, 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.

from cvise.

sdkrystian avatar sdkrystian commented on September 26, 2024

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.

from cvise.

marxin avatar marxin commented on September 26, 2024

@sdkrystian Thanks for the PR!

from cvise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.