[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/92854 This is an enabler for a future patch. >From 29f6855012c917040a84b5f1bfc3f6652c82f668 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Mon, 20 May 2024 16:30:46 -0300 Subject: [PATCH] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument This is an enabler for a future patch. --- .../ForwardingReferenceOverloadCheck.cpp | 4 +- .../bugprone/IncorrectEnableIfCheck.cpp | 5 +- .../modernize/UseConstraintsCheck.cpp | 8 ++- clang-tools-extra/clangd/Hover.cpp| 8 ++- clang/include/clang/AST/ASTNodeTraverser.h| 2 +- clang/include/clang/AST/DeclTemplate.h| 17 ++--- clang/include/clang/AST/RecursiveASTVisitor.h | 2 +- clang/include/clang/Sema/Sema.h | 4 +- clang/lib/AST/ASTContext.cpp | 3 +- clang/lib/AST/ASTImporter.cpp | 6 +- clang/lib/AST/DeclPrinter.cpp | 3 +- clang/lib/AST/DeclTemplate.cpp| 17 +++-- clang/lib/AST/JSONNodeDumper.cpp | 2 +- clang/lib/AST/ODRDiagsEmitter.cpp | 12 ++-- clang/lib/AST/ODRHash.cpp | 2 +- clang/lib/AST/TypePrinter.cpp | 4 +- clang/lib/ExtractAPI/DeclarationFragments.cpp | 8 +-- clang/lib/Index/IndexDecl.cpp | 3 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 48 +++-- clang/lib/Sema/SemaTemplate.cpp | 69 ++- clang/lib/Sema/SemaTemplateDeduction.cpp | 10 +-- clang/lib/Sema/SemaTemplateInstantiate.cpp| 11 +-- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 ++- clang/lib/Serialization/ASTReaderDecl.cpp | 3 +- clang/lib/Serialization/ASTWriterDecl.cpp | 2 +- clang/tools/libclang/CIndex.cpp | 7 +- clang/unittests/AST/ASTImporterTest.cpp | 2 +- 27 files changed, 144 insertions(+), 127 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp index 36687a8e761e8..c87b3ea7e2616 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp @@ -54,7 +54,9 @@ AST_MATCHER(QualType, isEnableIf) { AST_MATCHER_P(TemplateTypeParmDecl, hasDefaultArgument, clang::ast_matchers::internal::Matcher, TypeMatcher) { return Node.hasDefaultArgument() && - TypeMatcher.matches(Node.getDefaultArgument(), Finder, Builder); + TypeMatcher.matches( + Node.getDefaultArgument().getArgument().getAsType(), Finder, + Builder); } AST_MATCHER(TemplateDecl, hasAssociatedConstraints) { return Node.hasAssociatedConstraints(); diff --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp index 09aaf3e31d5dd..75f1107904fce 100644 --- a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp @@ -19,10 +19,11 @@ namespace { AST_MATCHER_P(TemplateTypeParmDecl, hasUnnamedDefaultArgument, ast_matchers::internal::Matcher, InnerMatcher) { if (Node.getIdentifier() != nullptr || !Node.hasDefaultArgument() || - Node.getDefaultArgumentInfo() == nullptr) + Node.getDefaultArgument().getArgument().isNull()) return false; - TypeLoc DefaultArgTypeLoc = Node.getDefaultArgumentInfo()->getTypeLoc(); + TypeLoc DefaultArgTypeLoc = + Node.getDefaultArgument().getTypeSourceInfo()->getTypeLoc(); return InnerMatcher.matches(DefaultArgTypeLoc, Finder, Builder); } diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp index 7a021fe14436a..ea4d99586c711 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp @@ -177,9 +177,11 @@ matchTrailingTemplateParam(const FunctionTemplateDecl *FunctionTemplate) { dyn_cast(LastParam)) { if (LastTemplateParam->hasDefaultArgument() && LastTemplateParam->getIdentifier() == nullptr) { - return {matchEnableIfSpecialization( - LastTemplateParam->getDefaultArgumentInfo()->getTypeLoc()), - LastTemplateParam}; + return { + matchEnableIfSpecialization(LastTemplateParam->getDefaultArgument() + .getTypeSourceInfo() + ->getTypeLoc()), + LastTemplateParam}; } } return {}; diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index 51124ab371b2a..de103e011c708 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/c
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
llvmbot wrote: @llvm/pr-subscribers-clang-modules @llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clangd Author: Matheus Izvekov (mizvekov) Changes This is an enabler for a future patch. --- Patch is 33.99 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/92854.diff 27 Files Affected: - (modified) clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp (+3-1) - (modified) clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp (+3-2) - (modified) clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp (+5-3) - (modified) clang-tools-extra/clangd/Hover.cpp (+6-2) - (modified) clang/include/clang/AST/ASTNodeTraverser.h (+1-1) - (modified) clang/include/clang/AST/DeclTemplate.h (+6-11) - (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+1-1) - (modified) clang/include/clang/Sema/Sema.h (+3-1) - (modified) clang/lib/AST/ASTContext.cpp (+2-1) - (modified) clang/lib/AST/ASTImporter.cpp (+3-3) - (modified) clang/lib/AST/DeclPrinter.cpp (+2-1) - (modified) clang/lib/AST/DeclTemplate.cpp (+12-5) - (modified) clang/lib/AST/JSONNodeDumper.cpp (+1-1) - (modified) clang/lib/AST/ODRDiagsEmitter.cpp (+7-5) - (modified) clang/lib/AST/ODRHash.cpp (+1-1) - (modified) clang/lib/AST/TypePrinter.cpp (+2-2) - (modified) clang/lib/ExtractAPI/DeclarationFragments.cpp (+4-4) - (modified) clang/lib/Index/IndexDecl.cpp (+2-1) - (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+28-20) - (modified) clang/lib/Sema/SemaTemplate.cpp (+35-34) - (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+3-7) - (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+3-8) - (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+4-5) - (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+2-1) - (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+1-1) - (modified) clang/tools/libclang/CIndex.cpp (+3-4) - (modified) clang/unittests/AST/ASTImporterTest.cpp (+1-1) ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp index 36687a8e761e8..c87b3ea7e2616 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp @@ -54,7 +54,9 @@ AST_MATCHER(QualType, isEnableIf) { AST_MATCHER_P(TemplateTypeParmDecl, hasDefaultArgument, clang::ast_matchers::internal::Matcher, TypeMatcher) { return Node.hasDefaultArgument() && - TypeMatcher.matches(Node.getDefaultArgument(), Finder, Builder); + TypeMatcher.matches( + Node.getDefaultArgument().getArgument().getAsType(), Finder, + Builder); } AST_MATCHER(TemplateDecl, hasAssociatedConstraints) { return Node.hasAssociatedConstraints(); diff --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp index 09aaf3e31d5dd..75f1107904fce 100644 --- a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp @@ -19,10 +19,11 @@ namespace { AST_MATCHER_P(TemplateTypeParmDecl, hasUnnamedDefaultArgument, ast_matchers::internal::Matcher, InnerMatcher) { if (Node.getIdentifier() != nullptr || !Node.hasDefaultArgument() || - Node.getDefaultArgumentInfo() == nullptr) + Node.getDefaultArgument().getArgument().isNull()) return false; - TypeLoc DefaultArgTypeLoc = Node.getDefaultArgumentInfo()->getTypeLoc(); + TypeLoc DefaultArgTypeLoc = + Node.getDefaultArgument().getTypeSourceInfo()->getTypeLoc(); return InnerMatcher.matches(DefaultArgTypeLoc, Finder, Builder); } diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp index 7a021fe14436a..ea4d99586c711 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp @@ -177,9 +177,11 @@ matchTrailingTemplateParam(const FunctionTemplateDecl *FunctionTemplate) { dyn_cast(LastParam)) { if (LastTemplateParam->hasDefaultArgument() && LastTemplateParam->getIdentifier() == nullptr) { - return {matchEnableIfSpecialization( - LastTemplateParam->getDefaultArgumentInfo()->getTypeLoc()), - LastTemplateParam}; + return { + matchEnableIfSpecialization(LastTemplateParam->getDefaultArgument() + .getTypeSourceInfo() + ->getTypeLoc()), + LastTemplateParam}; } } return {}; diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index 51124ab371b2a..de103e011c708 100644 --- a/clang-to
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
@@ -10082,7 +10082,9 @@ class Sema final : public SemaBase { bool SubstTemplateArgument(const TemplateArgumentLoc &Input, const MultiLevelTemplateArgumentList &TemplateArgs, - TemplateArgumentLoc &Output); + TemplateArgumentLoc &Output, + SourceLocation Loc = {}, + const DeclarationName &Entity = {}); Endilll wrote: Changes to both declaration and implementation of `SubstTemplateArgument` doesn't seem related. https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/Endilll commented: It looks like you have two sets of changes here: 1) the ones related to `TemplateTypeParmDecl::getDefaultArgument()` 2) the ones related to `Sema::SubstTemplateArgument()` You don't seem to touch the latter in PR description. It would be nice if you can explain why you do both sets of changes in one PR, or split the PR in two. https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
@@ -10082,7 +10082,9 @@ class Sema final : public SemaBase { bool SubstTemplateArgument(const TemplateArgumentLoc &Input, const MultiLevelTemplateArgumentList &TemplateArgs, - TemplateArgumentLoc &Output); + TemplateArgumentLoc &Output, + SourceLocation Loc = {}, + const DeclarationName &Entity = {}); mizvekov wrote: There are a few places we used SubsType, because we only had a type, now we use SubstTemplateArgument. SubstTemplateArgument was missing arguments for setting Instantiation location and entity names. Adding those is needed so we don't regress in diagnostics. https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
@@ -10082,7 +10082,9 @@ class Sema final : public SemaBase { bool SubstTemplateArgument(const TemplateArgumentLoc &Input, const MultiLevelTemplateArgumentList &TemplateArgs, - TemplateArgumentLoc &Output); + TemplateArgumentLoc &Output, + SourceLocation Loc = {}, + const DeclarationName &Entity = {}); Endilll wrote: Can you add this to the description? https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/Endilll commented: LGTM, but you should wait for someone with more knowledge of our templates. https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
https://github.com/erichkeane approved this pull request. I don't quite get the justification for this, but also don't see any downside for it, so I think this is acceptable. https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (PR #92854)
mizvekov wrote: > I don't quite get the justification for this, but also don't see any downside > for it, so I think this is acceptable. It's unfortunate GitHub does not show a PR stack like phab did. This is needed for another patch you already reviewed: https://github.com/llvm/llvm-project/pull/92855 It allows forming default arguments for packs as part of TTP template argument deduction, based on the same principles already implemented in https://github.com/llvm/llvm-project/pull/89807 https://github.com/llvm/llvm-project/pull/92854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits