blob: bf583b02f96b8d8753e1876643ab4e61d3de2e04 [file] [log] [blame]
Guy Benyei11169dd2012-12-18 14:30:41 +00001//===--- ASTCommon.cpp - Common stuff for ASTReader/ASTWriter----*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Guy Benyei11169dd2012-12-18 14:30:41 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file defines common functions that both ASTReader and ASTWriter use.
10//
11//===----------------------------------------------------------------------===//
12
13#include "ASTCommon.h"
Richard Smithd08aeb62014-08-28 01:33:39 +000014#include "clang/AST/DeclCXX.h"
Douglas Gregor9f782892013-01-21 15:25:38 +000015#include "clang/AST/DeclObjC.h"
Guy Benyei11169dd2012-12-18 14:30:41 +000016#include "clang/Basic/IdentifierTable.h"
17#include "clang/Serialization/ASTDeserializationListener.h"
Jonas Devlieghere560ce2c2018-02-26 15:16:42 +000018#include "llvm/Support/DJB.h"
Guy Benyei11169dd2012-12-18 14:30:41 +000019
20using namespace clang;
21
22// Give ASTDeserializationListener's VTable a home.
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +000023ASTDeserializationListener::~ASTDeserializationListener() { }
Guy Benyei11169dd2012-12-18 14:30:41 +000024
25serialization::TypeIdx
26serialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
27 unsigned ID = 0;
28 switch (BT->getKind()) {
Alexey Baderbdf7c842015-09-15 12:18:29 +000029 case BuiltinType::Void:
30 ID = PREDEF_TYPE_VOID_ID;
31 break;
32 case BuiltinType::Bool:
33 ID = PREDEF_TYPE_BOOL_ID;
34 break;
35 case BuiltinType::Char_U:
36 ID = PREDEF_TYPE_CHAR_U_ID;
37 break;
38 case BuiltinType::UChar:
39 ID = PREDEF_TYPE_UCHAR_ID;
40 break;
41 case BuiltinType::UShort:
42 ID = PREDEF_TYPE_USHORT_ID;
43 break;
44 case BuiltinType::UInt:
45 ID = PREDEF_TYPE_UINT_ID;
46 break;
47 case BuiltinType::ULong:
48 ID = PREDEF_TYPE_ULONG_ID;
49 break;
50 case BuiltinType::ULongLong:
51 ID = PREDEF_TYPE_ULONGLONG_ID;
52 break;
53 case BuiltinType::UInt128:
54 ID = PREDEF_TYPE_UINT128_ID;
55 break;
56 case BuiltinType::Char_S:
57 ID = PREDEF_TYPE_CHAR_S_ID;
58 break;
59 case BuiltinType::SChar:
60 ID = PREDEF_TYPE_SCHAR_ID;
61 break;
Guy Benyei11169dd2012-12-18 14:30:41 +000062 case BuiltinType::WChar_S:
Alexey Baderbdf7c842015-09-15 12:18:29 +000063 case BuiltinType::WChar_U:
64 ID = PREDEF_TYPE_WCHAR_ID;
65 break;
66 case BuiltinType::Short:
67 ID = PREDEF_TYPE_SHORT_ID;
68 break;
69 case BuiltinType::Int:
70 ID = PREDEF_TYPE_INT_ID;
71 break;
72 case BuiltinType::Long:
73 ID = PREDEF_TYPE_LONG_ID;
74 break;
75 case BuiltinType::LongLong:
76 ID = PREDEF_TYPE_LONGLONG_ID;
77 break;
78 case BuiltinType::Int128:
79 ID = PREDEF_TYPE_INT128_ID;
80 break;
81 case BuiltinType::Half:
82 ID = PREDEF_TYPE_HALF_ID;
83 break;
84 case BuiltinType::Float:
85 ID = PREDEF_TYPE_FLOAT_ID;
86 break;
87 case BuiltinType::Double:
88 ID = PREDEF_TYPE_DOUBLE_ID;
89 break;
90 case BuiltinType::LongDouble:
91 ID = PREDEF_TYPE_LONGDOUBLE_ID;
92 break;
Leonard Chanf921d852018-06-04 16:07:52 +000093 case BuiltinType::ShortAccum:
94 ID = PREDEF_TYPE_SHORT_ACCUM_ID;
95 break;
96 case BuiltinType::Accum:
97 ID = PREDEF_TYPE_ACCUM_ID;
98 break;
99 case BuiltinType::LongAccum:
100 ID = PREDEF_TYPE_LONG_ACCUM_ID;
101 break;
102 case BuiltinType::UShortAccum:
103 ID = PREDEF_TYPE_USHORT_ACCUM_ID;
104 break;
105 case BuiltinType::UAccum:
106 ID = PREDEF_TYPE_UACCUM_ID;
107 break;
108 case BuiltinType::ULongAccum:
109 ID = PREDEF_TYPE_ULONG_ACCUM_ID;
110 break;
Leonard Chanab80f3c2018-06-14 14:53:51 +0000111 case BuiltinType::ShortFract:
112 ID = PREDEF_TYPE_SHORT_FRACT_ID;
113 break;
114 case BuiltinType::Fract:
115 ID = PREDEF_TYPE_FRACT_ID;
116 break;
117 case BuiltinType::LongFract:
118 ID = PREDEF_TYPE_LONG_FRACT_ID;
119 break;
120 case BuiltinType::UShortFract:
121 ID = PREDEF_TYPE_USHORT_FRACT_ID;
122 break;
123 case BuiltinType::UFract:
124 ID = PREDEF_TYPE_UFRACT_ID;
125 break;
126 case BuiltinType::ULongFract:
127 ID = PREDEF_TYPE_ULONG_FRACT_ID;
128 break;
129 case BuiltinType::SatShortAccum:
130 ID = PREDEF_TYPE_SAT_SHORT_ACCUM_ID;
131 break;
132 case BuiltinType::SatAccum:
133 ID = PREDEF_TYPE_SAT_ACCUM_ID;
134 break;
135 case BuiltinType::SatLongAccum:
136 ID = PREDEF_TYPE_SAT_LONG_ACCUM_ID;
137 break;
138 case BuiltinType::SatUShortAccum:
139 ID = PREDEF_TYPE_SAT_USHORT_ACCUM_ID;
140 break;
141 case BuiltinType::SatUAccum:
142 ID = PREDEF_TYPE_SAT_UACCUM_ID;
143 break;
144 case BuiltinType::SatULongAccum:
145 ID = PREDEF_TYPE_SAT_ULONG_ACCUM_ID;
146 break;
147 case BuiltinType::SatShortFract:
148 ID = PREDEF_TYPE_SAT_SHORT_FRACT_ID;
149 break;
150 case BuiltinType::SatFract:
151 ID = PREDEF_TYPE_SAT_FRACT_ID;
152 break;
153 case BuiltinType::SatLongFract:
154 ID = PREDEF_TYPE_SAT_LONG_FRACT_ID;
155 break;
156 case BuiltinType::SatUShortFract:
157 ID = PREDEF_TYPE_SAT_USHORT_FRACT_ID;
158 break;
159 case BuiltinType::SatUFract:
160 ID = PREDEF_TYPE_SAT_UFRACT_ID;
161 break;
162 case BuiltinType::SatULongFract:
163 ID = PREDEF_TYPE_SAT_ULONG_FRACT_ID;
164 break;
Sjoerd Meijercc623ad2017-09-08 15:15:00 +0000165 case BuiltinType::Float16:
166 ID = PREDEF_TYPE_FLOAT16_ID;
167 break;
Nemanja Ivanovicbb1ea2d2016-05-09 08:52:33 +0000168 case BuiltinType::Float128:
169 ID = PREDEF_TYPE_FLOAT128_ID;
170 break;
Alexey Baderbdf7c842015-09-15 12:18:29 +0000171 case BuiltinType::NullPtr:
172 ID = PREDEF_TYPE_NULLPTR_ID;
173 break;
Richard Smith3a8244d2018-05-01 05:02:45 +0000174 case BuiltinType::Char8:
175 ID = PREDEF_TYPE_CHAR8_ID;
176 break;
Alexey Baderbdf7c842015-09-15 12:18:29 +0000177 case BuiltinType::Char16:
178 ID = PREDEF_TYPE_CHAR16_ID;
179 break;
180 case BuiltinType::Char32:
181 ID = PREDEF_TYPE_CHAR32_ID;
182 break;
183 case BuiltinType::Overload:
184 ID = PREDEF_TYPE_OVERLOAD_ID;
185 break;
186 case BuiltinType::BoundMember:
187 ID = PREDEF_TYPE_BOUND_MEMBER;
188 break;
189 case BuiltinType::PseudoObject:
190 ID = PREDEF_TYPE_PSEUDO_OBJECT;
191 break;
192 case BuiltinType::Dependent:
193 ID = PREDEF_TYPE_DEPENDENT_ID;
194 break;
195 case BuiltinType::UnknownAny:
196 ID = PREDEF_TYPE_UNKNOWN_ANY;
197 break;
Guy Benyei11169dd2012-12-18 14:30:41 +0000198 case BuiltinType::ARCUnbridgedCast:
Alexey Baderbdf7c842015-09-15 12:18:29 +0000199 ID = PREDEF_TYPE_ARC_UNBRIDGED_CAST;
200 break;
201 case BuiltinType::ObjCId:
202 ID = PREDEF_TYPE_OBJC_ID;
203 break;
204 case BuiltinType::ObjCClass:
205 ID = PREDEF_TYPE_OBJC_CLASS;
206 break;
207 case BuiltinType::ObjCSel:
208 ID = PREDEF_TYPE_OBJC_SEL;
209 break;
Alexey Bader954ba212016-04-08 13:40:33 +0000210#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
211 case BuiltinType::Id: \
212 ID = PREDEF_TYPE_##Id##_ID; \
Alexey Baderbdf7c842015-09-15 12:18:29 +0000213 break;
Alexey Baderb62f1442016-04-13 08:33:41 +0000214#include "clang/Basic/OpenCLImageTypes.def"
Andrew Savonichev3fee3512018-11-08 11:25:41 +0000215#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
216 case BuiltinType::Id: \
217 ID = PREDEF_TYPE_##Id##_ID; \
218 break;
219#include "clang/Basic/OpenCLExtensionTypes.def"
Alexey Baderbdf7c842015-09-15 12:18:29 +0000220 case BuiltinType::OCLSampler:
221 ID = PREDEF_TYPE_SAMPLER_ID;
222 break;
223 case BuiltinType::OCLEvent:
224 ID = PREDEF_TYPE_EVENT_ID;
225 break;
Alexey Bader9c8453f2015-09-15 11:18:52 +0000226 case BuiltinType::OCLClkEvent:
227 ID = PREDEF_TYPE_CLK_EVENT_ID;
228 break;
229 case BuiltinType::OCLQueue:
230 ID = PREDEF_TYPE_QUEUE_ID;
231 break;
Alexey Bader9c8453f2015-09-15 11:18:52 +0000232 case BuiltinType::OCLReserveID:
233 ID = PREDEF_TYPE_RESERVE_ID_ID;
234 break;
Richard Sandifordeb485fb2019-08-09 08:52:54 +0000235#define SVE_TYPE(Name, Id, SingletonId) \
236 case BuiltinType::Id: \
237 ID = PREDEF_TYPE_##Id##_ID; \
238 break;
239#include "clang/Basic/AArch64SVEACLETypes.def"
Guy Benyei11169dd2012-12-18 14:30:41 +0000240 case BuiltinType::BuiltinFn:
Alexey Baderbdf7c842015-09-15 12:18:29 +0000241 ID = PREDEF_TYPE_BUILTIN_FN;
242 break;
Florian Hahn8f3f88d2020-06-01 19:42:03 +0100243 case BuiltinType::IncompleteMatrixIdx:
244 ID = PREDEF_TYPE_INCOMPLETE_MATRIX_IDX;
245 break;
Alexey Baderbdf7c842015-09-15 12:18:29 +0000246 case BuiltinType::OMPArraySection:
247 ID = PREDEF_TYPE_OMP_ARRAY_SECTION;
248 break;
Alexey Bataev7ac9efb2020-02-05 09:33:05 -0500249 case BuiltinType::OMPArrayShaping:
250 ID = PREDEF_TYPE_OMP_ARRAY_SHAPING;
251 break;
Alexey Bataev13a15042020-04-01 15:06:38 -0400252 case BuiltinType::OMPIterator:
253 ID = PREDEF_TYPE_OMP_ITERATOR;
254 break;
Ties Stuijecd682b2020-06-05 00:20:02 +0100255 case BuiltinType::BFloat16:
256 ID = PREDEF_TYPE_BFLOAT16_ID;
257 break;
Guy Benyei11169dd2012-12-18 14:30:41 +0000258 }
259
260 return TypeIdx(ID);
261}
262
263unsigned serialization::ComputeHash(Selector Sel) {
264 unsigned N = Sel.getNumArgs();
265 if (N == 0)
266 ++N;
267 unsigned R = 5381;
268 for (unsigned I = 0; I != N; ++I)
269 if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I))
Jonas Devlieghere560ce2c2018-02-26 15:16:42 +0000270 R = llvm::djbHash(II->getName(), R);
Guy Benyei11169dd2012-12-18 14:30:41 +0000271 return R;
272}
Douglas Gregor9f782892013-01-21 15:25:38 +0000273
Douglas Gregor7a6e2002013-01-22 17:08:30 +0000274const DeclContext *
275serialization::getDefinitiveDeclContext(const DeclContext *DC) {
Douglas Gregor9f782892013-01-21 15:25:38 +0000276 switch (DC->getDeclKind()) {
277 // These entities may have multiple definitions.
278 case Decl::TranslationUnit:
Richard Smithf19e1272015-03-07 00:04:49 +0000279 case Decl::ExternCContext:
Douglas Gregor9f782892013-01-21 15:25:38 +0000280 case Decl::Namespace:
281 case Decl::LinkageSpec:
Richard Smith8df390f2016-09-08 23:14:54 +0000282 case Decl::Export:
Craig Toppera13603a2014-05-22 05:54:18 +0000283 return nullptr;
Douglas Gregor9f782892013-01-21 15:25:38 +0000284
285 // C/C++ tag types can only be defined in one place.
286 case Decl::Enum:
287 case Decl::Record:
288 if (const TagDecl *Def = cast<TagDecl>(DC)->getDefinition())
289 return Def;
Craig Toppera13603a2014-05-22 05:54:18 +0000290 return nullptr;
Douglas Gregor9f782892013-01-21 15:25:38 +0000291
292 // FIXME: These can be defined in one place... except special member
293 // functions and out-of-line definitions.
294 case Decl::CXXRecord:
295 case Decl::ClassTemplateSpecialization:
296 case Decl::ClassTemplatePartialSpecialization:
Craig Toppera13603a2014-05-22 05:54:18 +0000297 return nullptr;
Douglas Gregor9f782892013-01-21 15:25:38 +0000298
299 // Each function, method, and block declaration is its own DeclContext.
300 case Decl::Function:
301 case Decl::CXXMethod:
302 case Decl::CXXConstructor:
303 case Decl::CXXDestructor:
304 case Decl::CXXConversion:
305 case Decl::ObjCMethod:
306 case Decl::Block:
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000307 case Decl::Captured:
Douglas Gregor9f782892013-01-21 15:25:38 +0000308 // Objective C categories, category implementations, and class
309 // implementations can only be defined in one place.
310 case Decl::ObjCCategory:
311 case Decl::ObjCCategoryImpl:
312 case Decl::ObjCImplementation:
Douglas Gregor7a6e2002013-01-22 17:08:30 +0000313 return DC;
Douglas Gregor9f782892013-01-21 15:25:38 +0000314
315 case Decl::ObjCProtocol:
316 if (const ObjCProtocolDecl *Def
317 = cast<ObjCProtocolDecl>(DC)->getDefinition())
318 return Def;
Craig Toppera13603a2014-05-22 05:54:18 +0000319 return nullptr;
Douglas Gregor9f782892013-01-21 15:25:38 +0000320
321 // FIXME: These are defined in one place, but properties in class extensions
322 // end up being back-patched into the main interface. See
323 // Sema::HandlePropertyInClassExtension for the offending code.
324 case Decl::ObjCInterface:
Craig Toppera13603a2014-05-22 05:54:18 +0000325 return nullptr;
326
Douglas Gregor9f782892013-01-21 15:25:38 +0000327 default:
328 llvm_unreachable("Unhandled DeclContext in AST reader");
329 }
Jonas Devlieghere560ce2c2018-02-26 15:16:42 +0000330
Douglas Gregor7a6e2002013-01-22 17:08:30 +0000331 llvm_unreachable("Unhandled decl kind");
Douglas Gregorfe732d52013-01-21 16:16:40 +0000332}
Douglas Gregor9f782892013-01-21 15:25:38 +0000333
Douglas Gregorfe732d52013-01-21 16:16:40 +0000334bool serialization::isRedeclarableDeclKind(unsigned Kind) {
335 switch (static_cast<Decl::Kind>(Kind)) {
Richard Smithf19e1272015-03-07 00:04:49 +0000336 case Decl::TranslationUnit:
337 case Decl::ExternCContext:
338 // Special case of a "merged" declaration.
339 return true;
340
Douglas Gregorfe732d52013-01-21 16:16:40 +0000341 case Decl::Namespace:
Richard Smithf4634362014-09-03 23:11:22 +0000342 case Decl::NamespaceAlias:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000343 case Decl::Typedef:
344 case Decl::TypeAlias:
345 case Decl::Enum:
346 case Decl::Record:
347 case Decl::CXXRecord:
348 case Decl::ClassTemplateSpecialization:
349 case Decl::ClassTemplatePartialSpecialization:
Larisse Voufo39a1e502013-08-06 01:03:05 +0000350 case Decl::VarTemplateSpecialization:
351 case Decl::VarTemplatePartialSpecialization:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000352 case Decl::Function:
Richard Smithbc491202017-02-17 20:05:37 +0000353 case Decl::CXXDeductionGuide:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000354 case Decl::CXXMethod:
355 case Decl::CXXConstructor:
356 case Decl::CXXDestructor:
357 case Decl::CXXConversion:
Richard Smithfd8634a2013-10-23 02:17:46 +0000358 case Decl::UsingShadow:
Richard Smith5179eb72016-06-28 19:03:57 +0000359 case Decl::ConstructorUsingShadow:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000360 case Decl::Var:
361 case Decl::FunctionTemplate:
362 case Decl::ClassTemplate:
Larisse Voufo39a1e502013-08-06 01:03:05 +0000363 case Decl::VarTemplate:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000364 case Decl::TypeAliasTemplate:
365 case Decl::ObjCProtocol:
366 case Decl::ObjCInterface:
Michael Han84324352013-02-22 17:15:32 +0000367 case Decl::Empty:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000368 return true;
369
370 // Never redeclarable.
371 case Decl::UsingDirective:
372 case Decl::Label:
373 case Decl::UnresolvedUsingTypename:
374 case Decl::TemplateTypeParm:
375 case Decl::EnumConstant:
376 case Decl::UnresolvedUsingValue:
377 case Decl::IndirectField:
378 case Decl::Field:
John McCall5e77d762013-04-16 07:28:30 +0000379 case Decl::MSProperty:
Richard Smithbab6df82020-04-11 22:15:29 -0700380 case Decl::MSGuid:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000381 case Decl::ObjCIvar:
382 case Decl::ObjCAtDefsField:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000383 case Decl::NonTypeTemplateParm:
384 case Decl::TemplateTemplateParm:
385 case Decl::Using:
Richard Smith151c4562016-12-20 21:35:28 +0000386 case Decl::UsingPack:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000387 case Decl::ObjCMethod:
388 case Decl::ObjCCategory:
389 case Decl::ObjCCategoryImpl:
390 case Decl::ObjCImplementation:
391 case Decl::ObjCProperty:
392 case Decl::ObjCCompatibleAlias:
393 case Decl::LinkageSpec:
Richard Smith8df390f2016-09-08 23:14:54 +0000394 case Decl::Export:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000395 case Decl::ObjCPropertyImpl:
Nico Weber66220292016-03-02 17:28:48 +0000396 case Decl::PragmaComment:
Nico Webercbbaeb12016-03-02 19:28:54 +0000397 case Decl::PragmaDetectMismatch:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000398 case Decl::FileScopeAsm:
399 case Decl::AccessSpec:
400 case Decl::Friend:
401 case Decl::FriendTemplate:
402 case Decl::StaticAssert:
403 case Decl::Block:
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000404 case Decl::Captured:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000405 case Decl::ClassScopeFunctionSpecialization:
406 case Decl::Import:
Alexey Bataeva769e072013-03-22 06:34:35 +0000407 case Decl::OMPThreadPrivate:
Alexey Bataev25ed0c02019-03-07 17:54:44 +0000408 case Decl::OMPAllocate:
Kelvin Li1408f912018-09-26 04:28:39 +0000409 case Decl::OMPRequires:
Alexey Bataev4244be22016-02-11 05:35:55 +0000410 case Decl::OMPCapturedExpr:
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000411 case Decl::OMPDeclareReduction:
Michael Kruse251e1482019-02-01 20:25:04 +0000412 case Decl::OMPDeclareMapper:
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000413 case Decl::BuiltinTemplate:
Richard Smithbdb84f32016-07-22 23:36:59 +0000414 case Decl::Decomposition:
415 case Decl::Binding:
Saar Razd7aae332019-07-10 21:25:49 +0000416 case Decl::Concept:
Tykerb0561b32019-11-17 11:41:55 +0100417 case Decl::LifetimeExtendedTemporary:
Saar Raza0f50d72020-01-18 09:11:43 +0200418 case Decl::RequiresExprBody:
Douglas Gregorfe732d52013-01-21 16:16:40 +0000419 return false;
Richard Smithf4634362014-09-03 23:11:22 +0000420
421 // These indirectly derive from Redeclarable<T> but are not actually
422 // redeclarable.
423 case Decl::ImplicitParam:
424 case Decl::ParmVar:
Douglas Gregor85f3f952015-07-07 03:57:15 +0000425 case Decl::ObjCTypeParam:
Richard Smithf4634362014-09-03 23:11:22 +0000426 return false;
Douglas Gregorfe732d52013-01-21 16:16:40 +0000427 }
428
429 llvm_unreachable("Unhandled declaration kind");
Douglas Gregor9f782892013-01-21 15:25:38 +0000430}
Richard Smithd08aeb62014-08-28 01:33:39 +0000431
432bool serialization::needsAnonymousDeclarationNumber(const NamedDecl *D) {
Richard Smith2b560572015-02-07 03:11:11 +0000433 // Friend declarations in dependent contexts aren't anonymous in the usual
434 // sense, but they cannot be found by name lookup in their semantic context
435 // (or indeed in any context), so we treat them as anonymous.
436 //
437 // This doesn't apply to friend tag decls; Sema makes those available to name
438 // lookup in the surrounding context.
439 if (D->getFriendObjectKind() &&
440 D->getLexicalDeclContext()->isDependentContext() && !isa<TagDecl>(D)) {
441 // For function templates and class templates, the template is numbered and
442 // not its pattern.
443 if (auto *FD = dyn_cast<FunctionDecl>(D))
444 return !FD->getDescribedFunctionTemplate();
445 if (auto *RD = dyn_cast<CXXRecordDecl>(D))
446 return !RD->getDescribedClassTemplate();
447 return true;
448 }
449
Richard Smith600adef2018-07-04 02:25:38 +0000450 // At block scope, we number everything that we need to deduplicate, since we
451 // can't just use name matching to keep things lined up.
452 // FIXME: This is only necessary for an inline function or a template or
453 // similar.
454 if (D->getLexicalDeclContext()->isFunctionOrMethod()) {
455 if (auto *VD = dyn_cast<VarDecl>(D))
456 return VD->isStaticLocal();
457 // FIXME: What about CapturedDecls (and declarations nested within them)?
458 return isa<TagDecl>(D) || isa<BlockDecl>(D);
459 }
460
461 // Otherwise, we only care about anonymous class members / block-scope decls.
462 // FIXME: We need to handle lambdas and blocks within inline / templated
463 // variables too.
Daniel Jasper4a6d5b72017-10-11 07:47:54 +0000464 if (D->getDeclName() || !isa<CXXRecordDecl>(D->getLexicalDeclContext()))
Richard Smithd08aeb62014-08-28 01:33:39 +0000465 return false;
466 return isa<TagDecl>(D) || isa<FieldDecl>(D);
467}