Skip to content

[clang] NFCI: Make ASTContext optional in the AST text dumper again #94522

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

Conversation

mizvekov
Copy link
Contributor

@mizvekov mizvekov commented Jun 5, 2024

Previous patches 3cabbf6 and 1a2f330 broke the assumption that the AST Context was optional for the text node dumper.

While missing an ASTContext makes some helpful information unavailable, the pure dump overloads taking no parameters are quite convenient for quick debugging, so let's make that work again.

Previous patches 3cabbf6 and 1a2f330
broke the assumption that the AST Context was optional for the text node dumper.

While missing an ASTContext makes some helpful information unavailable,
the pure `dump` overloads taking no parameters are quite convenient for
quick debugging, so let's make that work again.
@mizvekov mizvekov requested review from cor3ntin and tbaederr June 5, 2024 19:06
@mizvekov mizvekov self-assigned this Jun 5, 2024
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 5, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 5, 2024

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

Previous patches 3cabbf6 and 1a2f330 broke the assumption that the AST Context was optional for the text node dumper.

While missing an ASTContext makes some helpful information unavailable, the pure dump overloads taking no parameters are quite convenient for quick debugging, so let's make that work again.


Full diff: https://github.com/llvm/llvm-project/pull/94522.diff

2 Files Affected:

  • (modified) clang/lib/AST/TextNodeDumper.cpp (+13-8)
  • (modified) clang/lib/AST/Type.cpp (-1)
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 8bacceea0f22b..1076dcd40a694 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -958,6 +958,9 @@ void TextNodeDumper::dumpTemplateArgument(const TemplateArgument &TA) {
   }
   OS << " '" << Str << "'";
 
+  if (!Context)
+    return;
+
   if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);
       !CanonTA.structurallyEquals(TA)) {
     llvm::SmallString<128> CanonStr;
@@ -1139,15 +1142,17 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN, StringRef Label) {
       }
       OS << " '" << Str << "'";
 
-      if (TemplateName CanonTN = Context->getCanonicalTemplateName(TN);
-          CanonTN != TN) {
-        llvm::SmallString<128> CanonStr;
-        {
-          llvm::raw_svector_ostream SS(CanonStr);
-          CanonTN.print(SS, PrintPolicy);
+      if (Context) {
+        if (TemplateName CanonTN = Context->getCanonicalTemplateName(TN);
+            CanonTN != TN) {
+          llvm::SmallString<128> CanonStr;
+          {
+            llvm::raw_svector_ostream SS(CanonStr);
+            CanonTN.print(SS, PrintPolicy);
+          }
+          if (CanonStr != Str)
+            OS << ":'" << CanonStr << "'";
         }
-        if (CanonStr != Str)
-          OS << ":'" << CanonStr << "'";
       }
     }
     dumpBareTemplateName(TN);
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 2097b29b7e0b6..2cc06a3df9d18 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4444,7 +4444,6 @@ static CachedProperties computeCachedProperties(const Type *T) {
 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
 #include "clang/AST/TypeNodes.inc"
     // Treat instantiation-dependent types as external.
-    if (!T->isInstantiationDependentType()) T->dump();
     assert(T->isInstantiationDependentType());
     return CachedProperties(Linkage::External, false);
 

@mizvekov mizvekov changed the title [clang] NFCI: Make ASTContext optional again [clang] NFCI: Make ASTContext optional in the AST text dumper again Jun 5, 2024
Copy link
Contributor

@tbaederr tbaederr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't say much about this functionally, but it fixes my problems, so LGTM from that side.

@mizvekov mizvekov merged commit fb0c705 into llvm:main Jun 6, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants