[PATCH] D111648: [clangd] TargetFinder: Fix assert-crash on TemplateExpansion args.
Adam Czachorowski via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 12 07:57:45 PDT 2021
adamcz created this revision.
adamcz added a reviewer: nridge.
Herald added subscribers: usaxena95, kadircet, arphaman.
adamcz requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Previously we would call getAsTemplate() when kind == TemplateExpansion,
which triggers an assertion. The call is now replaced with
getAsTemplateOrTemplatePattern(), which is exactly the same as
getAsTemplate(), except it allows calls when kind == TemplateExpansion.
No change in behavior for no-assert builds.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D111648
Files:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -341,6 +341,15 @@
EXPECT_DECLS("TemplateSpecializationTypeLoc", "template <typename> class T");
Flags.clear();
+ Code = R"cpp(
+ template<template<typename> class ...T>
+ class C {
+ C<[[T...]]> foo;
+ };
+ )cpp";
+ EXPECT_DECLS("TemplateArgumentLoc", {"template <typename> class ...T"});
+ Flags.clear();
+
Code = R"cpp(
struct S{};
S X;
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -507,7 +507,8 @@
// DeclRefExpr).
if (Arg.getKind() == TemplateArgument::Template ||
Arg.getKind() == TemplateArgument::TemplateExpansion) {
- if (TemplateDecl *TD = Arg.getAsTemplate().getAsTemplateDecl()) {
+ if (TemplateDecl *TD =
+ Arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl()) {
report(TD, Flags);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111648.379040.patch
Type: text/x-patch
Size: 1211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211012/0c2e3207/attachment.bin>
More information about the cfe-commits
mailing list