/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Sema/DeclSpec.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- DeclSpec.cpp - Declaration Specifier Semantic Analysis -----------===// |
2 | | // |
3 | | // 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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file implements semantic analysis for declaration specifiers. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/Sema/DeclSpec.h" |
14 | | #include "clang/AST/ASTContext.h" |
15 | | #include "clang/AST/DeclCXX.h" |
16 | | #include "clang/AST/Expr.h" |
17 | | #include "clang/AST/LocInfoType.h" |
18 | | #include "clang/AST/TypeLoc.h" |
19 | | #include "clang/Basic/LangOptions.h" |
20 | | #include "clang/Basic/SourceManager.h" |
21 | | #include "clang/Basic/TargetInfo.h" |
22 | | #include "clang/Sema/ParsedTemplate.h" |
23 | | #include "clang/Sema/Sema.h" |
24 | | #include "clang/Sema/SemaDiagnostic.h" |
25 | | #include "llvm/ADT/STLExtras.h" |
26 | | #include "llvm/ADT/SmallString.h" |
27 | | #include <cstring> |
28 | | using namespace clang; |
29 | | |
30 | | |
31 | 313k | void UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) { |
32 | 313k | assert(TemplateId && "NULL template-id annotation?"); |
33 | 0 | assert(!TemplateId->isInvalid() && |
34 | 313k | "should not convert invalid template-ids to unqualified-ids"); |
35 | | |
36 | 0 | Kind = UnqualifiedIdKind::IK_TemplateId; |
37 | 313k | this->TemplateId = TemplateId; |
38 | 313k | StartLocation = TemplateId->TemplateNameLoc; |
39 | 313k | EndLocation = TemplateId->RAngleLoc; |
40 | 313k | } |
41 | | |
42 | 33 | void UnqualifiedId::setConstructorTemplateId(TemplateIdAnnotation *TemplateId) { |
43 | 33 | assert(TemplateId && "NULL template-id annotation?"); |
44 | 0 | assert(!TemplateId->isInvalid() && |
45 | 33 | "should not convert invalid template-ids to unqualified-ids"); |
46 | | |
47 | 0 | Kind = UnqualifiedIdKind::IK_ConstructorTemplateId; |
48 | 33 | this->TemplateId = TemplateId; |
49 | 33 | StartLocation = TemplateId->TemplateNameLoc; |
50 | 33 | EndLocation = TemplateId->RAngleLoc; |
51 | 33 | } |
52 | | |
53 | | void CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc, |
54 | 5.78M | TypeLoc TL, SourceLocation ColonColonLoc) { |
55 | 5.78M | Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc); |
56 | 5.78M | if (Range.getBegin().isInvalid()) |
57 | 5.54M | Range.setBegin(TL.getBeginLoc()); |
58 | 5.78M | Range.setEnd(ColonColonLoc); |
59 | | |
60 | 5.78M | assert(Range == Builder.getSourceRange() && |
61 | 5.78M | "NestedNameSpecifierLoc range computation incorrect"); |
62 | 5.78M | } |
63 | | |
64 | | void CXXScopeSpec::Extend(ASTContext &Context, IdentifierInfo *Identifier, |
65 | | SourceLocation IdentifierLoc, |
66 | 26.6k | SourceLocation ColonColonLoc) { |
67 | 26.6k | Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc); |
68 | | |
69 | 26.6k | if (Range.getBegin().isInvalid()) |
70 | 82 | Range.setBegin(IdentifierLoc); |
71 | 26.6k | Range.setEnd(ColonColonLoc); |
72 | | |
73 | 26.6k | assert(Range == Builder.getSourceRange() && |
74 | 26.6k | "NestedNameSpecifierLoc range computation incorrect"); |
75 | 26.6k | } |
76 | | |
77 | | void CXXScopeSpec::Extend(ASTContext &Context, NamespaceDecl *Namespace, |
78 | | SourceLocation NamespaceLoc, |
79 | 1.19M | SourceLocation ColonColonLoc) { |
80 | 1.19M | Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc); |
81 | | |
82 | 1.19M | if (Range.getBegin().isInvalid()) |
83 | 1.19M | Range.setBegin(NamespaceLoc); |
84 | 1.19M | Range.setEnd(ColonColonLoc); |
85 | | |
86 | 1.19M | assert(Range == Builder.getSourceRange() && |
87 | 1.19M | "NestedNameSpecifierLoc range computation incorrect"); |
88 | 1.19M | } |
89 | | |
90 | | void CXXScopeSpec::Extend(ASTContext &Context, NamespaceAliasDecl *Alias, |
91 | | SourceLocation AliasLoc, |
92 | 238 | SourceLocation ColonColonLoc) { |
93 | 238 | Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc); |
94 | | |
95 | 238 | if (Range.getBegin().isInvalid()) |
96 | 229 | Range.setBegin(AliasLoc); |
97 | 238 | Range.setEnd(ColonColonLoc); |
98 | | |
99 | 238 | assert(Range == Builder.getSourceRange() && |
100 | 238 | "NestedNameSpecifierLoc range computation incorrect"); |
101 | 238 | } |
102 | | |
103 | | void CXXScopeSpec::MakeGlobal(ASTContext &Context, |
104 | 292k | SourceLocation ColonColonLoc) { |
105 | 292k | Builder.MakeGlobal(Context, ColonColonLoc); |
106 | | |
107 | 292k | Range = SourceRange(ColonColonLoc); |
108 | | |
109 | 292k | assert(Range == Builder.getSourceRange() && |
110 | 292k | "NestedNameSpecifierLoc range computation incorrect"); |
111 | 292k | } |
112 | | |
113 | | void CXXScopeSpec::MakeSuper(ASTContext &Context, CXXRecordDecl *RD, |
114 | | SourceLocation SuperLoc, |
115 | 58 | SourceLocation ColonColonLoc) { |
116 | 58 | Builder.MakeSuper(Context, RD, SuperLoc, ColonColonLoc); |
117 | | |
118 | 58 | Range.setBegin(SuperLoc); |
119 | 58 | Range.setEnd(ColonColonLoc); |
120 | | |
121 | 58 | assert(Range == Builder.getSourceRange() && |
122 | 58 | "NestedNameSpecifierLoc range computation incorrect"); |
123 | 58 | } |
124 | | |
125 | | void CXXScopeSpec::MakeTrivial(ASTContext &Context, |
126 | 1.98k | NestedNameSpecifier *Qualifier, SourceRange R) { |
127 | 1.98k | Builder.MakeTrivial(Context, Qualifier, R); |
128 | 1.98k | Range = R; |
129 | 1.98k | } |
130 | | |
131 | 12.3M | void CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) { |
132 | 12.3M | if (!Other) { |
133 | 1.84M | Range = SourceRange(); |
134 | 1.84M | Builder.Clear(); |
135 | 1.84M | return; |
136 | 1.84M | } |
137 | | |
138 | 10.5M | Range = Other.getSourceRange(); |
139 | 10.5M | Builder.Adopt(Other); |
140 | 10.5M | assert(Range == Builder.getSourceRange() && |
141 | 10.5M | "NestedNameSpecifierLoc range computation incorrect"); |
142 | 10.5M | } |
143 | | |
144 | 2.60M | SourceLocation CXXScopeSpec::getLastQualifierNameLoc() const { |
145 | 2.60M | if (!Builder.getRepresentation()) |
146 | 536 | return SourceLocation(); |
147 | 2.60M | return Builder.getTemporary().getLocalBeginLoc(); |
148 | 2.60M | } |
149 | | |
150 | | NestedNameSpecifierLoc |
151 | 32.7M | CXXScopeSpec::getWithLocInContext(ASTContext &Context) const { |
152 | 32.7M | if (!Builder.getRepresentation()) |
153 | 24.1M | return NestedNameSpecifierLoc(); |
154 | | |
155 | 8.65M | return Builder.getWithLocInContext(Context); |
156 | 32.7M | } |
157 | | |
158 | | /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. |
159 | | /// "TheDeclarator" is the declarator that this will be added to. |
160 | | DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, |
161 | | bool isAmbiguous, |
162 | | SourceLocation LParenLoc, |
163 | | ParamInfo *Params, |
164 | | unsigned NumParams, |
165 | | SourceLocation EllipsisLoc, |
166 | | SourceLocation RParenLoc, |
167 | | bool RefQualifierIsLvalueRef, |
168 | | SourceLocation RefQualifierLoc, |
169 | | SourceLocation MutableLoc, |
170 | | ExceptionSpecificationType |
171 | | ESpecType, |
172 | | SourceRange ESpecRange, |
173 | | ParsedType *Exceptions, |
174 | | SourceRange *ExceptionRanges, |
175 | | unsigned NumExceptions, |
176 | | Expr *NoexceptExpr, |
177 | | CachedTokens *ExceptionSpecTokens, |
178 | | ArrayRef<NamedDecl*> |
179 | | DeclsInPrototype, |
180 | | SourceLocation LocalRangeBegin, |
181 | | SourceLocation LocalRangeEnd, |
182 | | Declarator &TheDeclarator, |
183 | | TypeResult TrailingReturnType, |
184 | | SourceLocation |
185 | | TrailingReturnTypeLoc, |
186 | 25.3M | DeclSpec *MethodQualifiers) { |
187 | 25.3M | assert(!(MethodQualifiers && MethodQualifiers->getTypeQualifiers() & DeclSpec::TQ_atomic) && |
188 | 25.3M | "function cannot have _Atomic qualifier"); |
189 | | |
190 | 0 | DeclaratorChunk I; |
191 | 25.3M | I.Kind = Function; |
192 | 25.3M | I.Loc = LocalRangeBegin; |
193 | 25.3M | I.EndLoc = LocalRangeEnd; |
194 | 25.3M | new (&I.Fun) FunctionTypeInfo; |
195 | 25.3M | I.Fun.hasPrototype = hasProto; |
196 | 25.3M | I.Fun.isVariadic = EllipsisLoc.isValid(); |
197 | 25.3M | I.Fun.isAmbiguous = isAmbiguous; |
198 | 25.3M | I.Fun.LParenLoc = LParenLoc; |
199 | 25.3M | I.Fun.EllipsisLoc = EllipsisLoc; |
200 | 25.3M | I.Fun.RParenLoc = RParenLoc; |
201 | 25.3M | I.Fun.DeleteParams = false; |
202 | 25.3M | I.Fun.NumParams = NumParams; |
203 | 25.3M | I.Fun.Params = nullptr; |
204 | 25.3M | I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef; |
205 | 25.3M | I.Fun.RefQualifierLoc = RefQualifierLoc; |
206 | 25.3M | I.Fun.MutableLoc = MutableLoc; |
207 | 25.3M | I.Fun.ExceptionSpecType = ESpecType; |
208 | 25.3M | I.Fun.ExceptionSpecLocBeg = ESpecRange.getBegin(); |
209 | 25.3M | I.Fun.ExceptionSpecLocEnd = ESpecRange.getEnd(); |
210 | 25.3M | I.Fun.NumExceptionsOrDecls = 0; |
211 | 25.3M | I.Fun.Exceptions = nullptr; |
212 | 25.3M | I.Fun.NoexceptExpr = nullptr; |
213 | 25.3M | I.Fun.HasTrailingReturnType = TrailingReturnType.isUsable() || |
214 | 25.3M | TrailingReturnType.isInvalid()25.3M ; |
215 | 25.3M | I.Fun.TrailingReturnType = TrailingReturnType.get(); |
216 | 25.3M | I.Fun.TrailingReturnTypeLoc = TrailingReturnTypeLoc; |
217 | 25.3M | I.Fun.MethodQualifiers = nullptr; |
218 | 25.3M | I.Fun.QualAttrFactory = nullptr; |
219 | | |
220 | 25.3M | if (MethodQualifiers && (25.3M MethodQualifiers->getTypeQualifiers()25.3M || |
221 | 25.3M | MethodQualifiers->getAttributes().size()24.9M )) { |
222 | 411k | auto &attrs = MethodQualifiers->getAttributes(); |
223 | 411k | I.Fun.MethodQualifiers = new DeclSpec(attrs.getPool().getFactory()); |
224 | 411k | MethodQualifiers->forEachCVRUQualifier( |
225 | 418k | [&](DeclSpec::TQ TypeQual, StringRef PrintName, SourceLocation SL) { |
226 | 418k | I.Fun.MethodQualifiers->SetTypeQual(TypeQual, SL); |
227 | 418k | }); |
228 | 411k | I.Fun.MethodQualifiers->getAttributes().takeAllFrom(attrs); |
229 | 411k | I.Fun.MethodQualifiers->getAttributePool().takeAllFrom(attrs.getPool()); |
230 | 411k | } |
231 | | |
232 | 25.3M | assert(I.Fun.ExceptionSpecType == ESpecType && "bitfield overflow"); |
233 | | |
234 | | // new[] a parameter array if needed. |
235 | 25.3M | if (NumParams) { |
236 | | // If the 'InlineParams' in Declarator is unused and big enough, put our |
237 | | // parameter list there (in an effort to avoid new/delete traffic). If it |
238 | | // is already used (consider a function returning a function pointer) or too |
239 | | // small (function with too many parameters), go to the heap. |
240 | 24.7M | if (!TheDeclarator.InlineStorageUsed && |
241 | 24.7M | NumParams <= llvm::array_lengthof(TheDeclarator.InlineParams)24.7M ) { |
242 | 24.7M | I.Fun.Params = TheDeclarator.InlineParams; |
243 | 24.7M | new (I.Fun.Params) ParamInfo[NumParams]; |
244 | 24.7M | I.Fun.DeleteParams = false; |
245 | 24.7M | TheDeclarator.InlineStorageUsed = true; |
246 | 24.7M | } else { |
247 | 4.24k | I.Fun.Params = new DeclaratorChunk::ParamInfo[NumParams]; |
248 | 4.24k | I.Fun.DeleteParams = true; |
249 | 4.24k | } |
250 | 90.0M | for (unsigned i = 0; i < NumParams; i++65.3M ) |
251 | 65.3M | I.Fun.Params[i] = std::move(Params[i]); |
252 | 24.7M | } |
253 | | |
254 | | // Check what exception specification information we should actually store. |
255 | 25.3M | switch (ESpecType) { |
256 | 25.2M | default: break; // By default, save nothing. |
257 | 25.2M | case EST_Dynamic: |
258 | | // new[] an exception array if needed |
259 | 301 | if (NumExceptions) { |
260 | 301 | I.Fun.NumExceptionsOrDecls = NumExceptions; |
261 | 301 | I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions]; |
262 | 663 | for (unsigned i = 0; i != NumExceptions; ++i362 ) { |
263 | 362 | I.Fun.Exceptions[i].Ty = Exceptions[i]; |
264 | 362 | I.Fun.Exceptions[i].Range = ExceptionRanges[i]; |
265 | 362 | } |
266 | 301 | } |
267 | 301 | break; |
268 | | |
269 | 25.3k | case EST_DependentNoexcept: |
270 | 25.5k | case EST_NoexceptFalse: |
271 | 25.7k | case EST_NoexceptTrue: |
272 | 25.7k | I.Fun.NoexceptExpr = NoexceptExpr; |
273 | 25.7k | break; |
274 | | |
275 | 52.5k | case EST_Unparsed: |
276 | 52.5k | I.Fun.ExceptionSpecTokens = ExceptionSpecTokens; |
277 | 52.5k | break; |
278 | 25.3M | } |
279 | | |
280 | 25.3M | if (!DeclsInPrototype.empty()) { |
281 | 729 | assert(ESpecType == EST_None && NumExceptions == 0 && |
282 | 729 | "cannot have exception specifiers and decls in prototype"); |
283 | 0 | I.Fun.NumExceptionsOrDecls = DeclsInPrototype.size(); |
284 | | // Copy the array of decls into stable heap storage. |
285 | 729 | I.Fun.DeclsInPrototype = new NamedDecl *[DeclsInPrototype.size()]; |
286 | 1.51k | for (size_t J = 0; J < DeclsInPrototype.size(); ++J790 ) |
287 | 790 | I.Fun.DeclsInPrototype[J] = DeclsInPrototype[J]; |
288 | 729 | } |
289 | | |
290 | 0 | return I; |
291 | 25.3M | } |
292 | | |
293 | | void Declarator::setDecompositionBindings( |
294 | | SourceLocation LSquareLoc, |
295 | | ArrayRef<DecompositionDeclarator::Binding> Bindings, |
296 | 491 | SourceLocation RSquareLoc) { |
297 | 491 | assert(!hasName() && "declarator given multiple names!"); |
298 | | |
299 | 0 | BindingGroup.LSquareLoc = LSquareLoc; |
300 | 491 | BindingGroup.RSquareLoc = RSquareLoc; |
301 | 491 | BindingGroup.NumBindings = Bindings.size(); |
302 | 491 | Range.setEnd(RSquareLoc); |
303 | | |
304 | | // We're now past the identifier. |
305 | 491 | SetIdentifier(nullptr, LSquareLoc); |
306 | 491 | Name.EndLocation = RSquareLoc; |
307 | | |
308 | | // Allocate storage for bindings and stash them away. |
309 | 491 | if (Bindings.size()) { |
310 | 485 | if (!InlineStorageUsed && |
311 | 485 | Bindings.size() <= llvm::array_lengthof(InlineBindings)) { |
312 | 485 | BindingGroup.Bindings = InlineBindings; |
313 | 485 | BindingGroup.DeleteBindings = false; |
314 | 485 | InlineStorageUsed = true; |
315 | 485 | } else { |
316 | 0 | BindingGroup.Bindings = |
317 | 0 | new DecompositionDeclarator::Binding[Bindings.size()]; |
318 | 0 | BindingGroup.DeleteBindings = true; |
319 | 0 | } |
320 | 485 | std::uninitialized_copy(Bindings.begin(), Bindings.end(), |
321 | 485 | BindingGroup.Bindings); |
322 | 485 | } |
323 | 491 | } |
324 | | |
325 | 3.40M | bool Declarator::isDeclarationOfFunction() const { |
326 | 3.42M | for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i12.2k ) { |
327 | 1.58M | switch (DeclTypeInfo[i].Kind) { |
328 | 1.35M | case DeclaratorChunk::Function: |
329 | 1.35M | return true; |
330 | 12.2k | case DeclaratorChunk::Paren: |
331 | 12.2k | continue; |
332 | 103k | case DeclaratorChunk::Pointer: |
333 | 139k | case DeclaratorChunk::Reference: |
334 | 215k | case DeclaratorChunk::Array: |
335 | 216k | case DeclaratorChunk::BlockPointer: |
336 | 219k | case DeclaratorChunk::MemberPointer: |
337 | 219k | case DeclaratorChunk::Pipe: |
338 | 219k | return false; |
339 | 1.58M | } |
340 | 0 | llvm_unreachable("Invalid type chunk"); |
341 | 0 | } |
342 | | |
343 | 1.83M | switch (DS.getTypeSpecType()) { |
344 | 479 | case TST_atomic: |
345 | 1.03k | case TST_auto: |
346 | 1.03k | case TST_auto_type: |
347 | 265k | case TST_bool: |
348 | 274k | case TST_char: |
349 | 274k | case TST_char8: |
350 | 275k | case TST_char16: |
351 | 275k | case TST_char32: |
352 | 275k | case TST_class: |
353 | 275k | case TST_decimal128: |
354 | 275k | case TST_decimal32: |
355 | 275k | case TST_decimal64: |
356 | 283k | case TST_double: |
357 | 283k | case TST_Accum: |
358 | 283k | case TST_Fract: |
359 | 283k | case TST_Float16: |
360 | 283k | case TST_float128: |
361 | 283k | case TST_ibm128: |
362 | 283k | case TST_enum: |
363 | 283k | case TST_error: |
364 | 289k | case TST_float: |
365 | 289k | case TST_half: |
366 | 589k | case TST_int: |
367 | 589k | case TST_int128: |
368 | 590k | case TST_bitint: |
369 | 781k | case TST_struct: |
370 | 781k | case TST_interface: |
371 | 784k | case TST_union: |
372 | 784k | case TST_unknown_anytype: |
373 | 784k | case TST_unspecified: |
374 | 798k | case TST_void: |
375 | 799k | case TST_wchar: |
376 | 799k | case TST_BFloat16: |
377 | 9.58M | #define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t: |
378 | 799k | #include "clang/Basic/OpenCLImageTypes.def" |
379 | 799k | return false; |
380 | | |
381 | 0 | case TST_decltype_auto: |
382 | | // This must have an initializer, so can't be a function declaration, |
383 | | // even if the initializer has function type. |
384 | 0 | return false; |
385 | | |
386 | 4.47k | case TST_decltype: |
387 | 4.49k | case TST_typeofExpr: |
388 | 4.49k | if (Expr *E = DS.getRepAsExpr()) |
389 | 4.49k | return E->getType()->isFunctionType(); |
390 | 0 | return false; |
391 | | |
392 | 535 | case TST_underlyingType: |
393 | 1.03M | case TST_typename: |
394 | 1.03M | case TST_typeofType: { |
395 | 1.03M | QualType QT = DS.getRepAsType().get(); |
396 | 1.03M | if (QT.isNull()) |
397 | 0 | return false; |
398 | | |
399 | 1.03M | if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT)) |
400 | 181k | QT = LIT->getType(); |
401 | | |
402 | 1.03M | if (QT.isNull()) |
403 | 0 | return false; |
404 | | |
405 | 1.03M | return QT->isFunctionType(); |
406 | 1.03M | } |
407 | 1.83M | } |
408 | | |
409 | 0 | llvm_unreachable("Invalid TypeSpecType!"); |
410 | 0 | } |
411 | | |
412 | 2.64M | bool Declarator::isStaticMember() { |
413 | 2.64M | assert(getContext() == DeclaratorContext::Member); |
414 | 2.64M | return getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static || |
415 | 2.64M | (2.33M getName().Kind == UnqualifiedIdKind::IK_OperatorFunctionId2.33M && |
416 | 2.33M | CXXMethodDecl::isStaticOverloadedOperator( |
417 | 497k | getName().OperatorFunctionId.Operator)); |
418 | 2.64M | } |
419 | | |
420 | 1.32M | bool Declarator::isCtorOrDtor() { |
421 | 1.32M | return (getName().getKind() == UnqualifiedIdKind::IK_ConstructorName) || |
422 | 1.32M | (getName().getKind() == UnqualifiedIdKind::IK_DestructorName)1.01M ; |
423 | 1.32M | } |
424 | | |
425 | | void DeclSpec::forEachCVRUQualifier( |
426 | 411k | llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) { |
427 | 411k | if (TypeQualifiers & TQ_const) |
428 | 389k | Handle(TQ_const, "const", TQ_constLoc); |
429 | 411k | if (TypeQualifiers & TQ_volatile) |
430 | 29.6k | Handle(TQ_volatile, "volatile", TQ_volatileLoc); |
431 | 411k | if (TypeQualifiers & TQ_restrict) |
432 | 39 | Handle(TQ_restrict, "restrict", TQ_restrictLoc); |
433 | 411k | if (TypeQualifiers & TQ_unaligned) |
434 | 16 | Handle(TQ_unaligned, "unaligned", TQ_unalignedLoc); |
435 | 411k | } |
436 | | |
437 | | void DeclSpec::forEachQualifier( |
438 | 67 | llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle) { |
439 | 67 | forEachCVRUQualifier(Handle); |
440 | | // FIXME: Add code below to iterate through the attributes and call Handle. |
441 | 67 | } |
442 | | |
443 | 43.6M | bool DeclSpec::hasTagDefinition() const { |
444 | 43.6M | if (!TypeSpecOwned) |
445 | 41.1M | return false; |
446 | 2.45M | return cast<TagDecl>(getRepAsDecl())->isCompleteDefinition(); |
447 | 43.6M | } |
448 | | |
449 | | /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this |
450 | | /// declaration specifier includes. |
451 | | /// |
452 | 81.0M | unsigned DeclSpec::getParsedSpecifiers() const { |
453 | 81.0M | unsigned Res = 0; |
454 | 81.0M | if (StorageClassSpec != SCS_unspecified || |
455 | 81.0M | ThreadStorageClassSpec != TSCS_unspecified80.8M ) |
456 | 235k | Res |= PQ_StorageClassSpecifier; |
457 | | |
458 | 81.0M | if (TypeQualifiers != TQ_unspecified) |
459 | 3.79M | Res |= PQ_TypeQualifier; |
460 | | |
461 | 81.0M | if (hasTypeSpecifier()) |
462 | 80.0M | Res |= PQ_TypeSpecifier; |
463 | | |
464 | 81.0M | if (FS_inline_specified || FS_virtual_specified81.0M || hasExplicitSpecifier()81.0M || |
465 | 81.0M | FS_noreturn_specified81.0M || FS_forceinline_specified81.0M ) |
466 | 5.45k | Res |= PQ_FunctionSpecifier; |
467 | 81.0M | return Res; |
468 | 81.0M | } |
469 | | |
470 | | template <class T> static bool BadSpecifier(T TNew, T TPrev, |
471 | | const char *&PrevSpec, |
472 | | unsigned &DiagID, |
473 | 68 | bool IsExtension = true) { |
474 | 68 | PrevSpec = DeclSpec::getSpecifierName(TPrev); |
475 | 68 | if (TNew != TPrev) |
476 | 15 | DiagID = diag::err_invalid_decl_spec_combination; |
477 | 53 | else |
478 | 53 | DiagID = IsExtension ? diag::ext_warn_duplicate_declspec44 : |
479 | 53 | diag::warn_duplicate_declspec9 ; |
480 | 68 | return true; |
481 | 68 | } DeclSpec.cpp:bool BadSpecifier<clang::DeclSpec::SCS>(clang::DeclSpec::SCS, clang::DeclSpec::SCS, char const*&, unsigned int&, bool) Line | Count | Source | 473 | 13 | bool IsExtension = true) { | 474 | 13 | PrevSpec = DeclSpec::getSpecifierName(TPrev); | 475 | 13 | if (TNew != TPrev) | 476 | 6 | DiagID = diag::err_invalid_decl_spec_combination; | 477 | 7 | else | 478 | 7 | DiagID = IsExtension ? diag::ext_warn_duplicate_declspec : | 479 | 7 | diag::warn_duplicate_declspec0 ; | 480 | 13 | return true; | 481 | 13 | } |
Unexecuted instantiation: DeclSpec.cpp:bool BadSpecifier<clang::ThreadStorageClassSpecifier>(clang::ThreadStorageClassSpecifier, clang::ThreadStorageClassSpecifier, char const*&, unsigned int&, bool) Unexecuted instantiation: DeclSpec.cpp:bool BadSpecifier<clang::TypeSpecifierWidth>(clang::TypeSpecifierWidth, clang::TypeSpecifierWidth, char const*&, unsigned int&, bool) Unexecuted instantiation: DeclSpec.cpp:bool BadSpecifier<clang::DeclSpec::TSC>(clang::DeclSpec::TSC, clang::DeclSpec::TSC, char const*&, unsigned int&, bool) Unexecuted instantiation: DeclSpec.cpp:bool BadSpecifier<clang::TypeSpecifierSign>(clang::TypeSpecifierSign, clang::TypeSpecifierSign, char const*&, unsigned int&, bool) DeclSpec.cpp:bool BadSpecifier<clang::DeclSpec::TQ>(clang::DeclSpec::TQ, clang::DeclSpec::TQ, char const*&, unsigned int&, bool) Line | Count | Source | 473 | 40 | bool IsExtension = true) { | 474 | 40 | PrevSpec = DeclSpec::getSpecifierName(TPrev); | 475 | 40 | if (TNew != TPrev) | 476 | 0 | DiagID = diag::err_invalid_decl_spec_combination; | 477 | 40 | else | 478 | 40 | DiagID = IsExtension ? diag::ext_warn_duplicate_declspec31 : | 479 | 40 | diag::warn_duplicate_declspec9 ; | 480 | 40 | return true; | 481 | 40 | } |
DeclSpec.cpp:bool BadSpecifier<clang::ConstexprSpecKind>(clang::ConstexprSpecKind, clang::ConstexprSpecKind, char const*&, unsigned int&, bool) Line | Count | Source | 473 | 15 | bool IsExtension = true) { | 474 | 15 | PrevSpec = DeclSpec::getSpecifierName(TPrev); | 475 | 15 | if (TNew != TPrev) | 476 | 9 | DiagID = diag::err_invalid_decl_spec_combination; | 477 | 6 | else | 478 | 6 | DiagID = IsExtension ? diag::ext_warn_duplicate_declspec : | 479 | 6 | diag::warn_duplicate_declspec0 ; | 480 | 15 | return true; | 481 | 15 | } |
|
482 | | |
483 | 89 | const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) { |
484 | 89 | switch (S) { |
485 | 6 | case DeclSpec::SCS_unspecified: return "unspecified"; |
486 | 6 | case DeclSpec::SCS_typedef: return "typedef"; |
487 | 10 | case DeclSpec::SCS_extern: return "extern"; |
488 | 30 | case DeclSpec::SCS_static: return "static"; |
489 | 17 | case DeclSpec::SCS_auto: return "auto"; |
490 | 12 | case DeclSpec::SCS_register: return "register"; |
491 | 0 | case DeclSpec::SCS_private_extern: return "__private_extern__"; |
492 | 8 | case DeclSpec::SCS_mutable: return "mutable"; |
493 | 89 | } |
494 | 0 | llvm_unreachable("Unknown typespec!"); |
495 | 0 | } |
496 | | |
497 | 68 | const char *DeclSpec::getSpecifierName(DeclSpec::TSCS S) { |
498 | 68 | switch (S) { |
499 | 0 | case DeclSpec::TSCS_unspecified: return "unspecified"; |
500 | 17 | case DeclSpec::TSCS___thread: return "__thread"; |
501 | 18 | case DeclSpec::TSCS_thread_local: return "thread_local"; |
502 | 33 | case DeclSpec::TSCS__Thread_local: return "_Thread_local"; |
503 | 68 | } |
504 | 0 | llvm_unreachable("Unknown typespec!"); |
505 | 0 | } |
506 | | |
507 | 35 | const char *DeclSpec::getSpecifierName(TypeSpecifierWidth W) { |
508 | 35 | switch (W) { |
509 | 11 | case TypeSpecifierWidth::Unspecified: |
510 | 11 | return "unspecified"; |
511 | 0 | case TypeSpecifierWidth::Short: |
512 | 0 | return "short"; |
513 | 24 | case TypeSpecifierWidth::Long: |
514 | 24 | return "long"; |
515 | 0 | case TypeSpecifierWidth::LongLong: |
516 | 0 | return "long long"; |
517 | 35 | } |
518 | 0 | llvm_unreachable("Unknown typespec!"); |
519 | 0 | } |
520 | | |
521 | 11 | const char *DeclSpec::getSpecifierName(TSC C) { |
522 | 11 | switch (C) { |
523 | 11 | case TSC_unspecified: return "unspecified"; |
524 | 0 | case TSC_imaginary: return "imaginary"; |
525 | 0 | case TSC_complex: return "complex"; |
526 | 11 | } |
527 | 0 | llvm_unreachable("Unknown typespec!"); |
528 | 0 | } |
529 | | |
530 | 95 | const char *DeclSpec::getSpecifierName(TypeSpecifierSign S) { |
531 | 95 | switch (S) { |
532 | 11 | case TypeSpecifierSign::Unspecified: |
533 | 11 | return "unspecified"; |
534 | 48 | case TypeSpecifierSign::Signed: |
535 | 48 | return "signed"; |
536 | 36 | case TypeSpecifierSign::Unsigned: |
537 | 36 | return "unsigned"; |
538 | 95 | } |
539 | 0 | llvm_unreachable("Unknown typespec!"); |
540 | 0 | } |
541 | | |
542 | | const char *DeclSpec::getSpecifierName(DeclSpec::TST T, |
543 | 1.88k | const PrintingPolicy &Policy) { |
544 | 1.88k | switch (T) { |
545 | 1.36k | case DeclSpec::TST_unspecified: return "unspecified"; |
546 | 0 | case DeclSpec::TST_void: return "void"; |
547 | 4 | case DeclSpec::TST_char: return "char"; |
548 | 6 | case DeclSpec::TST_wchar: return Policy.MSWChar ? "__wchar_t"0 : "wchar_t"; |
549 | 0 | case DeclSpec::TST_char8: return "char8_t"; |
550 | 0 | case DeclSpec::TST_char16: return "char16_t"; |
551 | 0 | case DeclSpec::TST_char32: return "char32_t"; |
552 | 78 | case DeclSpec::TST_int: return "int"; |
553 | 6 | case DeclSpec::TST_int128: return "__int128"; |
554 | 2 | case DeclSpec::TST_bitint: return "_BitInt"; |
555 | 1 | case DeclSpec::TST_half: return "half"; |
556 | 27 | case DeclSpec::TST_float: return "float"; |
557 | 35 | case DeclSpec::TST_double: return "double"; |
558 | 22 | case DeclSpec::TST_accum: return "_Accum"; |
559 | 22 | case DeclSpec::TST_fract: return "_Fract"; |
560 | 0 | case DeclSpec::TST_float16: return "_Float16"; |
561 | 0 | case DeclSpec::TST_float128: return "__float128"; |
562 | 0 | case DeclSpec::TST_ibm128: return "__ibm128"; |
563 | 6 | case DeclSpec::TST_bool: return Policy.Bool ? "bool"2 : "_Bool"4 ; |
564 | 0 | case DeclSpec::TST_decimal32: return "_Decimal32"; |
565 | 0 | case DeclSpec::TST_decimal64: return "_Decimal64"; |
566 | 0 | case DeclSpec::TST_decimal128: return "_Decimal128"; |
567 | 1 | case DeclSpec::TST_enum: return "enum"; |
568 | 120 | case DeclSpec::TST_class: return "class"; |
569 | 9 | case DeclSpec::TST_union: return "union"; |
570 | 165 | case DeclSpec::TST_struct: return "struct"; |
571 | 0 | case DeclSpec::TST_interface: return "__interface"; |
572 | 11 | case DeclSpec::TST_typename: return "type-name"; |
573 | 1 | case DeclSpec::TST_typeofType: |
574 | 1 | case DeclSpec::TST_typeofExpr: return "typeof"; |
575 | 0 | case DeclSpec::TST_auto: return "auto"; |
576 | 0 | case DeclSpec::TST_auto_type: return "__auto_type"; |
577 | 2 | case DeclSpec::TST_decltype: return "(decltype)"; |
578 | 2 | case DeclSpec::TST_decltype_auto: return "decltype(auto)"; |
579 | 0 | case DeclSpec::TST_underlyingType: return "__underlying_type"; |
580 | 0 | case DeclSpec::TST_unknown_anytype: return "__unknown_anytype"; |
581 | 0 | case DeclSpec::TST_atomic: return "_Atomic"; |
582 | 0 | case DeclSpec::TST_BFloat16: return "__bf16"; |
583 | 0 | #define GENERIC_IMAGE_TYPE(ImgType, Id) \ |
584 | 0 | case DeclSpec::TST_##ImgType##_t: \ |
585 | 0 | return #ImgType "_t"; |
586 | 0 | #include "clang/Basic/OpenCLImageTypes.def" |
587 | 0 | case DeclSpec::TST_error: return "(error)"; |
588 | 1.88k | } |
589 | 0 | llvm_unreachable("Unknown typespec!"); |
590 | 0 | } |
591 | | |
592 | 19 | const char *DeclSpec::getSpecifierName(ConstexprSpecKind C) { |
593 | 19 | switch (C) { |
594 | 0 | case ConstexprSpecKind::Unspecified: |
595 | 0 | return "unspecified"; |
596 | 11 | case ConstexprSpecKind::Constexpr: |
597 | 11 | return "constexpr"; |
598 | 4 | case ConstexprSpecKind::Consteval: |
599 | 4 | return "consteval"; |
600 | 4 | case ConstexprSpecKind::Constinit: |
601 | 4 | return "constinit"; |
602 | 19 | } |
603 | 0 | llvm_unreachable("Unknown ConstexprSpecKind"); |
604 | 0 | } |
605 | | |
606 | 119 | const char *DeclSpec::getSpecifierName(TQ T) { |
607 | 119 | switch (T) { |
608 | 0 | case DeclSpec::TQ_unspecified: return "unspecified"; |
609 | 98 | case DeclSpec::TQ_const: return "const"; |
610 | 1 | case DeclSpec::TQ_restrict: return "restrict"; |
611 | 13 | case DeclSpec::TQ_volatile: return "volatile"; |
612 | 7 | case DeclSpec::TQ_atomic: return "_Atomic"; |
613 | 0 | case DeclSpec::TQ_unaligned: return "__unaligned"; |
614 | 119 | } |
615 | 0 | llvm_unreachable("Unknown typespec!"); |
616 | 0 | } |
617 | | |
618 | | bool DeclSpec::SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, |
619 | | const char *&PrevSpec, |
620 | | unsigned &DiagID, |
621 | 24.8M | const PrintingPolicy &Policy) { |
622 | | // OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class |
623 | | // specifiers are not supported. |
624 | | // It seems sensible to prohibit private_extern too |
625 | | // The cl_clang_storage_class_specifiers extension enables support for |
626 | | // these storage-class specifiers. |
627 | | // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class |
628 | | // specifiers are not supported." |
629 | 24.8M | if (S.getLangOpts().OpenCL && |
630 | 24.8M | !S.getOpenCLOptions().isAvailableOption( |
631 | 6.12k | "cl_clang_storage_class_specifiers", S.getLangOpts())) { |
632 | 6.11k | switch (SC) { |
633 | 194 | case SCS_extern: |
634 | 194 | case SCS_private_extern: |
635 | 441 | case SCS_static: |
636 | 441 | if (S.getLangOpts().getOpenCLCompatibleVersion() < 120) { |
637 | 2 | DiagID = diag::err_opencl_unknown_type_specifier; |
638 | 2 | PrevSpec = getSpecifierName(SC); |
639 | 2 | return true; |
640 | 2 | } |
641 | 439 | break; |
642 | 439 | case SCS_auto: |
643 | 13 | case SCS_register: |
644 | 13 | DiagID = diag::err_opencl_unknown_type_specifier; |
645 | 13 | PrevSpec = getSpecifierName(SC); |
646 | 13 | return true; |
647 | 5.66k | default: |
648 | 5.66k | break; |
649 | 6.11k | } |
650 | 6.11k | } |
651 | | |
652 | 24.8M | if (StorageClassSpec != SCS_unspecified) { |
653 | | // Maybe this is an attempt to use C++11 'auto' outside of C++11 mode. |
654 | 20 | bool isInvalid = true; |
655 | 20 | if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus14 ) { |
656 | 9 | if (SC == SCS_auto) |
657 | 6 | return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID, Policy); |
658 | 3 | if (StorageClassSpec == SCS_auto) { |
659 | 1 | isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc, |
660 | 1 | PrevSpec, DiagID, Policy); |
661 | 1 | assert(!isInvalid && "auto SCS -> TST recovery failed"); |
662 | 1 | } |
663 | 3 | } |
664 | | |
665 | | // Changing storage class is allowed only if the previous one |
666 | | // was the 'extern' that is part of a linkage specification and |
667 | | // the new storage class is 'typedef'. |
668 | 14 | if (isInvalid && |
669 | 14 | !(13 SCS_extern_in_linkage_spec13 && |
670 | 13 | StorageClassSpec == SCS_extern0 && |
671 | 13 | SC == SCS_typedef0 )) |
672 | 13 | return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID); |
673 | 14 | } |
674 | 24.8M | StorageClassSpec = SC; |
675 | 24.8M | StorageClassSpecLoc = Loc; |
676 | 24.8M | assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield"); |
677 | 0 | return false; |
678 | 24.8M | } |
679 | | |
680 | | bool DeclSpec::SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, |
681 | | const char *&PrevSpec, |
682 | 1.03k | unsigned &DiagID) { |
683 | 1.03k | if (ThreadStorageClassSpec != TSCS_unspecified) |
684 | 0 | return BadSpecifier(TSC, (TSCS)ThreadStorageClassSpec, PrevSpec, DiagID); |
685 | | |
686 | 1.03k | ThreadStorageClassSpec = TSC; |
687 | 1.03k | ThreadStorageClassSpecLoc = Loc; |
688 | 1.03k | return false; |
689 | 1.03k | } |
690 | | |
691 | | /// These methods set the specified attribute of the DeclSpec, but return true |
692 | | /// and ignore the request if invalid (e.g. "extern" then "auto" is |
693 | | /// specified). |
694 | | bool DeclSpec::SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, |
695 | | const char *&PrevSpec, unsigned &DiagID, |
696 | 1.14M | const PrintingPolicy &Policy) { |
697 | | // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that |
698 | | // for 'long long' we will keep the source location of the first 'long'. |
699 | 1.14M | if (getTypeSpecWidth() == TypeSpecifierWidth::Unspecified) |
700 | 948k | TSWRange.setBegin(Loc); |
701 | | // Allow turning long -> long long. |
702 | 197k | else if (W != TypeSpecifierWidth::LongLong || |
703 | 197k | getTypeSpecWidth() != TypeSpecifierWidth::Long) |
704 | 0 | return BadSpecifier(W, getTypeSpecWidth(), PrevSpec, DiagID); |
705 | 1.14M | TypeSpecWidth = static_cast<unsigned>(W); |
706 | | // Remember location of the last 'long' |
707 | 1.14M | TSWRange.setEnd(Loc); |
708 | 1.14M | return false; |
709 | 1.14M | } |
710 | | |
711 | | bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc, |
712 | | const char *&PrevSpec, |
713 | 8.32k | unsigned &DiagID) { |
714 | 8.32k | if (TypeSpecComplex != TSC_unspecified) |
715 | 0 | return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID); |
716 | 8.32k | TypeSpecComplex = C; |
717 | 8.32k | TSCLoc = Loc; |
718 | 8.32k | return false; |
719 | 8.32k | } |
720 | | |
721 | | bool DeclSpec::SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, |
722 | 798k | const char *&PrevSpec, unsigned &DiagID) { |
723 | 798k | if (getTypeSpecSign() != TypeSpecifierSign::Unspecified) |
724 | 0 | return BadSpecifier(S, getTypeSpecSign(), PrevSpec, DiagID); |
725 | 798k | TypeSpecSign = static_cast<unsigned>(S); |
726 | 798k | TSSLoc = Loc; |
727 | 798k | return false; |
728 | 798k | } |
729 | | |
730 | | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
731 | | const char *&PrevSpec, |
732 | | unsigned &DiagID, |
733 | | ParsedType Rep, |
734 | 100M | const PrintingPolicy &Policy) { |
735 | 100M | return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Policy); |
736 | 100M | } |
737 | | |
738 | | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, |
739 | | SourceLocation TagNameLoc, |
740 | | const char *&PrevSpec, |
741 | | unsigned &DiagID, |
742 | | ParsedType Rep, |
743 | 100M | const PrintingPolicy &Policy) { |
744 | 100M | assert(isTypeRep(T) && "T does not store a type"); |
745 | 0 | assert(Rep && "no type provided!"); |
746 | 100M | if (TypeSpecType == TST_error) |
747 | 0 | return false; |
748 | 100M | if (TypeSpecType != TST_unspecified) { |
749 | 4 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy); |
750 | 4 | DiagID = diag::err_invalid_decl_spec_combination; |
751 | 4 | return true; |
752 | 4 | } |
753 | 100M | TypeSpecType = T; |
754 | 100M | TypeRep = Rep; |
755 | 100M | TSTLoc = TagKwLoc; |
756 | 100M | TSTNameLoc = TagNameLoc; |
757 | 100M | TypeSpecOwned = false; |
758 | 100M | return false; |
759 | 100M | } |
760 | | |
761 | | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
762 | | const char *&PrevSpec, |
763 | | unsigned &DiagID, |
764 | | Expr *Rep, |
765 | 101k | const PrintingPolicy &Policy) { |
766 | 101k | assert(isExprRep(T) && "T does not store an expr"); |
767 | 0 | assert(Rep && "no expression provided!"); |
768 | 101k | if (TypeSpecType == TST_error) |
769 | 0 | return false; |
770 | 101k | if (TypeSpecType != TST_unspecified) { |
771 | 0 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy); |
772 | 0 | DiagID = diag::err_invalid_decl_spec_combination; |
773 | 0 | return true; |
774 | 0 | } |
775 | 101k | TypeSpecType = T; |
776 | 101k | ExprRep = Rep; |
777 | 101k | TSTLoc = Loc; |
778 | 101k | TSTNameLoc = Loc; |
779 | 101k | TypeSpecOwned = false; |
780 | 101k | return false; |
781 | 101k | } |
782 | | |
783 | | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
784 | | const char *&PrevSpec, |
785 | | unsigned &DiagID, |
786 | | Decl *Rep, bool Owned, |
787 | 0 | const PrintingPolicy &Policy) { |
788 | 0 | return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned, Policy); |
789 | 0 | } |
790 | | |
791 | | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, |
792 | | SourceLocation TagNameLoc, |
793 | | const char *&PrevSpec, |
794 | | unsigned &DiagID, |
795 | | Decl *Rep, bool Owned, |
796 | 2.82M | const PrintingPolicy &Policy) { |
797 | 2.82M | assert(isDeclRep(T) && "T does not store a decl"); |
798 | | // Unlike the other cases, we don't assert that we actually get a decl. |
799 | | |
800 | 2.82M | if (TypeSpecType == TST_error) |
801 | 0 | return false; |
802 | 2.82M | if (TypeSpecType != TST_unspecified) { |
803 | 3 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy); |
804 | 3 | DiagID = diag::err_invalid_decl_spec_combination; |
805 | 3 | return true; |
806 | 3 | } |
807 | 2.82M | TypeSpecType = T; |
808 | 2.82M | DeclRep = Rep; |
809 | 2.82M | TSTLoc = TagKwLoc; |
810 | 2.82M | TSTNameLoc = TagNameLoc; |
811 | 2.82M | TypeSpecOwned = Owned && Rep != nullptr1.32M ; |
812 | 2.82M | return false; |
813 | 2.82M | } |
814 | | |
815 | | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, |
816 | | unsigned &DiagID, TemplateIdAnnotation *Rep, |
817 | 202 | const PrintingPolicy &Policy) { |
818 | 202 | assert(T == TST_auto || T == TST_decltype_auto); |
819 | 0 | ConstrainedAuto = true; |
820 | 202 | TemplateIdRep = Rep; |
821 | 202 | return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Policy); |
822 | 202 | } |
823 | | |
824 | | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
825 | | const char *&PrevSpec, |
826 | | unsigned &DiagID, |
827 | 8.92M | const PrintingPolicy &Policy) { |
828 | 8.92M | assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) && |
829 | 8.92M | "rep required for these type-spec kinds!"); |
830 | 8.92M | if (TypeSpecType == TST_error) |
831 | 12 | return false; |
832 | 8.92M | if (TypeSpecType != TST_unspecified) { |
833 | 73 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy); |
834 | 73 | DiagID = diag::err_invalid_decl_spec_combination; |
835 | 73 | return true; |
836 | 73 | } |
837 | 8.92M | TSTLoc = Loc; |
838 | 8.92M | TSTNameLoc = Loc; |
839 | 8.92M | if (TypeAltiVecVector && (T == TST_bool)86.6k && !TypeAltiVecBool14.5k ) { |
840 | 14.5k | TypeAltiVecBool = true; |
841 | 14.5k | return false; |
842 | 14.5k | } |
843 | 8.91M | TypeSpecType = T; |
844 | 8.91M | TypeSpecOwned = false; |
845 | 8.91M | return false; |
846 | 8.92M | } |
847 | | |
848 | | bool DeclSpec::SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, |
849 | 561 | unsigned &DiagID) { |
850 | | // Cannot set twice |
851 | 561 | if (TypeSpecSat) { |
852 | 1 | DiagID = diag::warn_duplicate_declspec; |
853 | 1 | PrevSpec = "_Sat"; |
854 | 1 | return true; |
855 | 1 | } |
856 | 560 | TypeSpecSat = true; |
857 | 560 | TSSatLoc = Loc; |
858 | 560 | return false; |
859 | 561 | } |
860 | | |
861 | | bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, |
862 | | const char *&PrevSpec, unsigned &DiagID, |
863 | 104k | const PrintingPolicy &Policy) { |
864 | 104k | if (TypeSpecType == TST_error) |
865 | 0 | return false; |
866 | 104k | if (TypeSpecType != TST_unspecified) { |
867 | 0 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy); |
868 | 0 | DiagID = diag::err_invalid_vector_decl_spec_combination; |
869 | 0 | return true; |
870 | 0 | } |
871 | 104k | TypeAltiVecVector = isAltiVecVector; |
872 | 104k | AltiVecLoc = Loc; |
873 | 104k | return false; |
874 | 104k | } |
875 | | |
876 | | bool DeclSpec::SetTypePipe(bool isPipe, SourceLocation Loc, |
877 | | const char *&PrevSpec, unsigned &DiagID, |
878 | 255 | const PrintingPolicy &Policy) { |
879 | 255 | if (TypeSpecType == TST_error) |
880 | 0 | return false; |
881 | 255 | if (TypeSpecType != TST_unspecified) { |
882 | 6 | PrevSpec = DeclSpec::getSpecifierName((TST)TypeSpecType, Policy); |
883 | 6 | DiagID = diag::err_invalid_decl_spec_combination; |
884 | 6 | return true; |
885 | 6 | } |
886 | | |
887 | 249 | if (isPipe) { |
888 | 249 | TypeSpecPipe = static_cast<unsigned>(TypeSpecifiersPipe::Pipe); |
889 | 249 | } |
890 | 249 | return false; |
891 | 255 | } |
892 | | |
893 | | bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, |
894 | | const char *&PrevSpec, unsigned &DiagID, |
895 | 2.57k | const PrintingPolicy &Policy) { |
896 | 2.57k | if (TypeSpecType == TST_error) |
897 | 0 | return false; |
898 | 2.57k | if (!TypeAltiVecVector || TypeAltiVecPixel || |
899 | 2.57k | (TypeSpecType != TST_unspecified)) { |
900 | 0 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy); |
901 | 0 | DiagID = diag::err_invalid_pixel_decl_spec_combination; |
902 | 0 | return true; |
903 | 0 | } |
904 | 2.57k | TypeAltiVecPixel = isAltiVecPixel; |
905 | 2.57k | TSTLoc = Loc; |
906 | 2.57k | TSTNameLoc = Loc; |
907 | 2.57k | return false; |
908 | 2.57k | } |
909 | | |
910 | | bool DeclSpec::SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, |
911 | | const char *&PrevSpec, unsigned &DiagID, |
912 | 4.25k | const PrintingPolicy &Policy) { |
913 | 4.25k | if (TypeSpecType == TST_error) |
914 | 0 | return false; |
915 | 4.25k | if (!TypeAltiVecVector || TypeAltiVecBool || |
916 | 4.25k | (TypeSpecType != TST_unspecified)) { |
917 | 0 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy); |
918 | 0 | DiagID = diag::err_invalid_vector_bool_decl_spec; |
919 | 0 | return true; |
920 | 0 | } |
921 | 4.25k | TypeAltiVecBool = isAltiVecBool; |
922 | 4.25k | TSTLoc = Loc; |
923 | 4.25k | TSTNameLoc = Loc; |
924 | 4.25k | return false; |
925 | 4.25k | } |
926 | | |
927 | 3.09k | bool DeclSpec::SetTypeSpecError() { |
928 | 3.09k | TypeSpecType = TST_error; |
929 | 3.09k | TypeSpecOwned = false; |
930 | 3.09k | TSTLoc = SourceLocation(); |
931 | 3.09k | TSTNameLoc = SourceLocation(); |
932 | 3.09k | return false; |
933 | 3.09k | } |
934 | | |
935 | | bool DeclSpec::SetBitIntType(SourceLocation KWLoc, Expr *BitsExpr, |
936 | | const char *&PrevSpec, unsigned &DiagID, |
937 | 1.05k | const PrintingPolicy &Policy) { |
938 | 1.05k | assert(BitsExpr && "no expression provided!"); |
939 | 1.05k | if (TypeSpecType == TST_error) |
940 | 0 | return false; |
941 | | |
942 | 1.05k | if (TypeSpecType != TST_unspecified) { |
943 | 0 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy); |
944 | 0 | DiagID = diag::err_invalid_decl_spec_combination; |
945 | 0 | return true; |
946 | 0 | } |
947 | | |
948 | 1.05k | TypeSpecType = TST_bitint; |
949 | 1.05k | ExprRep = BitsExpr; |
950 | 1.05k | TSTLoc = KWLoc; |
951 | 1.05k | TSTNameLoc = KWLoc; |
952 | 1.05k | TypeSpecOwned = false; |
953 | 1.05k | return false; |
954 | 1.05k | } |
955 | | |
956 | | bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, |
957 | 5.60M | unsigned &DiagID, const LangOptions &Lang) { |
958 | | // Duplicates are permitted in C99 onwards, but are not permitted in C89 or |
959 | | // C++. However, since this is likely not what the user intended, we will |
960 | | // always warn. We do not need to set the qualifier's location since we |
961 | | // already have it. |
962 | 5.60M | if (TypeQualifiers & T) { |
963 | 40 | bool IsExtension = true; |
964 | 40 | if (Lang.C99) |
965 | 9 | IsExtension = false; |
966 | 40 | return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension); |
967 | 40 | } |
968 | | |
969 | 5.60M | return SetTypeQual(T, Loc); |
970 | 5.60M | } |
971 | | |
972 | 6.03M | bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc) { |
973 | 6.03M | TypeQualifiers |= T; |
974 | | |
975 | 6.03M | switch (T) { |
976 | 0 | case TQ_unspecified: break; |
977 | 5.79M | case TQ_const: TQ_constLoc = Loc; return false; |
978 | 71.0k | case TQ_restrict: TQ_restrictLoc = Loc; return false; |
979 | 166k | case TQ_volatile: TQ_volatileLoc = Loc; return false; |
980 | 185 | case TQ_unaligned: TQ_unalignedLoc = Loc; return false; |
981 | 178 | case TQ_atomic: TQ_atomicLoc = Loc; return false; |
982 | 6.03M | } |
983 | | |
984 | 0 | llvm_unreachable("Unknown type qualifier!"); |
985 | 0 | } |
986 | | |
987 | | bool DeclSpec::setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, |
988 | 20.7M | unsigned &DiagID) { |
989 | | // 'inline inline' is ok. However, since this is likely not what the user |
990 | | // intended, we will always warn, similar to duplicates of type qualifiers. |
991 | 20.7M | if (FS_inline_specified) { |
992 | 1 | DiagID = diag::warn_duplicate_declspec; |
993 | 1 | PrevSpec = "inline"; |
994 | 1 | return true; |
995 | 1 | } |
996 | 20.7M | FS_inline_specified = true; |
997 | 20.7M | FS_inlineLoc = Loc; |
998 | 20.7M | return false; |
999 | 20.7M | } |
1000 | | |
1001 | | bool DeclSpec::setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, |
1002 | 23 | unsigned &DiagID) { |
1003 | 23 | if (FS_forceinline_specified) { |
1004 | 1 | DiagID = diag::warn_duplicate_declspec; |
1005 | 1 | PrevSpec = "__forceinline"; |
1006 | 1 | return true; |
1007 | 1 | } |
1008 | 22 | FS_forceinline_specified = true; |
1009 | 22 | FS_forceinlineLoc = Loc; |
1010 | 22 | return false; |
1011 | 23 | } |
1012 | | |
1013 | | bool DeclSpec::setFunctionSpecVirtual(SourceLocation Loc, |
1014 | | const char *&PrevSpec, |
1015 | 56.0k | unsigned &DiagID) { |
1016 | | // 'virtual virtual' is ok, but warn as this is likely not what the user |
1017 | | // intended. |
1018 | 56.0k | if (FS_virtual_specified) { |
1019 | 1 | DiagID = diag::warn_duplicate_declspec; |
1020 | 1 | PrevSpec = "virtual"; |
1021 | 1 | return true; |
1022 | 1 | } |
1023 | 56.0k | FS_virtual_specified = true; |
1024 | 56.0k | FS_virtualLoc = Loc; |
1025 | 56.0k | return false; |
1026 | 56.0k | } |
1027 | | |
1028 | | bool DeclSpec::setFunctionSpecExplicit(SourceLocation Loc, |
1029 | | const char *&PrevSpec, unsigned &DiagID, |
1030 | | ExplicitSpecifier ExplicitSpec, |
1031 | 88.8k | SourceLocation CloseParenLoc) { |
1032 | | // 'explicit explicit' is ok, but warn as this is likely not what the user |
1033 | | // intended. |
1034 | 88.8k | if (hasExplicitSpecifier()) { |
1035 | 4 | DiagID = (ExplicitSpec.getExpr() || FS_explicit_specifier.getExpr()) |
1036 | 4 | ? diag::err_duplicate_declspec2 |
1037 | 4 | : diag::ext_warn_duplicate_declspec2 ; |
1038 | 4 | PrevSpec = "explicit"; |
1039 | 4 | return true; |
1040 | 4 | } |
1041 | 88.8k | FS_explicit_specifier = ExplicitSpec; |
1042 | 88.8k | FS_explicitLoc = Loc; |
1043 | 88.8k | FS_explicitCloseParenLoc = CloseParenLoc; |
1044 | 88.8k | return false; |
1045 | 88.8k | } |
1046 | | |
1047 | | bool DeclSpec::setFunctionSpecNoreturn(SourceLocation Loc, |
1048 | | const char *&PrevSpec, |
1049 | 84 | unsigned &DiagID) { |
1050 | | // '_Noreturn _Noreturn' is ok, but warn as this is likely not what the user |
1051 | | // intended. |
1052 | 84 | if (FS_noreturn_specified) { |
1053 | 1 | DiagID = diag::warn_duplicate_declspec; |
1054 | 1 | PrevSpec = "_Noreturn"; |
1055 | 1 | return true; |
1056 | 1 | } |
1057 | 83 | FS_noreturn_specified = true; |
1058 | 83 | FS_noreturnLoc = Loc; |
1059 | 83 | return false; |
1060 | 84 | } |
1061 | | |
1062 | | bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, |
1063 | 77.6k | unsigned &DiagID) { |
1064 | 77.6k | if (Friend_specified) { |
1065 | 8 | PrevSpec = "friend"; |
1066 | | // Keep the later location, so that we can later diagnose ill-formed |
1067 | | // declarations like 'friend class X friend;'. Per [class.friend]p3, |
1068 | | // 'friend' must be the first token in a friend declaration that is |
1069 | | // not a function declaration. |
1070 | 8 | FriendLoc = Loc; |
1071 | 8 | DiagID = diag::warn_duplicate_declspec; |
1072 | 8 | return true; |
1073 | 8 | } |
1074 | | |
1075 | 77.6k | Friend_specified = true; |
1076 | 77.6k | FriendLoc = Loc; |
1077 | 77.6k | return false; |
1078 | 77.6k | } |
1079 | | |
1080 | | bool DeclSpec::setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, |
1081 | 52 | unsigned &DiagID) { |
1082 | 52 | if (isModulePrivateSpecified()) { |
1083 | 0 | PrevSpec = "__module_private__"; |
1084 | 0 | DiagID = diag::ext_warn_duplicate_declspec; |
1085 | 0 | return true; |
1086 | 0 | } |
1087 | | |
1088 | 52 | ModulePrivateLoc = Loc; |
1089 | 52 | return false; |
1090 | 52 | } |
1091 | | |
1092 | | bool DeclSpec::SetConstexprSpec(ConstexprSpecKind ConstexprKind, |
1093 | | SourceLocation Loc, const char *&PrevSpec, |
1094 | 395k | unsigned &DiagID) { |
1095 | 395k | if (getConstexprSpecifier() != ConstexprSpecKind::Unspecified) |
1096 | 15 | return BadSpecifier(ConstexprKind, getConstexprSpecifier(), PrevSpec, |
1097 | 15 | DiagID); |
1098 | 395k | ConstexprSpecifier = static_cast<unsigned>(ConstexprKind); |
1099 | 395k | ConstexprLoc = Loc; |
1100 | 395k | return false; |
1101 | 395k | } |
1102 | | |
1103 | 134M | void DeclSpec::SaveWrittenBuiltinSpecs() { |
1104 | 134M | writtenBS.Sign = static_cast<int>(getTypeSpecSign()); |
1105 | 134M | writtenBS.Width = static_cast<int>(getTypeSpecWidth()); |
1106 | 134M | writtenBS.Type = getTypeSpecType(); |
1107 | | // Search the list of attributes for the presence of a mode attribute. |
1108 | 134M | writtenBS.ModeAttr = getAttributes().hasAttribute(ParsedAttr::AT_Mode); |
1109 | 134M | } |
1110 | | |
1111 | | /// Finish - This does final analysis of the declspec, rejecting things like |
1112 | | /// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or |
1113 | | /// diag::NUM_DIAGNOSTICS if there is no error. After calling this method, |
1114 | | /// DeclSpec is guaranteed self-consistent, even if an error occurred. |
1115 | 134M | void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) { |
1116 | | // Before possibly changing their values, save specs as written. |
1117 | 134M | SaveWrittenBuiltinSpecs(); |
1118 | | |
1119 | | // Check the type specifier components first. No checking for an invalid |
1120 | | // type. |
1121 | 134M | if (TypeSpecType == TST_error) |
1122 | 2.89k | return; |
1123 | | |
1124 | | // If decltype(auto) is used, no other type specifiers are permitted. |
1125 | 134M | if (TypeSpecType == TST_decltype_auto && |
1126 | 134M | (723 getTypeSpecWidth() != TypeSpecifierWidth::Unspecified723 || |
1127 | 723 | TypeSpecComplex != TSC_unspecified || |
1128 | 723 | getTypeSpecSign() != TypeSpecifierSign::Unspecified || |
1129 | 723 | TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool || |
1130 | 723 | TypeQualifiers)) { |
1131 | 5 | const unsigned NumLocs = 9; |
1132 | 5 | SourceLocation ExtraLocs[NumLocs] = { |
1133 | 5 | TSWRange.getBegin(), TSCLoc, TSSLoc, |
1134 | 5 | AltiVecLoc, TQ_constLoc, TQ_restrictLoc, |
1135 | 5 | TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc}; |
1136 | 5 | FixItHint Hints[NumLocs]; |
1137 | 5 | SourceLocation FirstLoc; |
1138 | 50 | for (unsigned I = 0; I != NumLocs; ++I45 ) { |
1139 | 45 | if (ExtraLocs[I].isValid()) { |
1140 | 5 | if (FirstLoc.isInvalid() || |
1141 | 5 | S.getSourceManager().isBeforeInTranslationUnit(ExtraLocs[I], |
1142 | 0 | FirstLoc)) |
1143 | 5 | FirstLoc = ExtraLocs[I]; |
1144 | 5 | Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]); |
1145 | 5 | } |
1146 | 45 | } |
1147 | 5 | TypeSpecWidth = static_cast<unsigned>(TypeSpecifierWidth::Unspecified); |
1148 | 5 | TypeSpecComplex = TSC_unspecified; |
1149 | 5 | TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unspecified); |
1150 | 5 | TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false; |
1151 | 5 | TypeQualifiers = 0; |
1152 | 5 | S.Diag(TSTLoc, diag::err_decltype_auto_cannot_be_combined) |
1153 | 5 | << Hints[0] << Hints[1] << Hints[2] << Hints[3] |
1154 | 5 | << Hints[4] << Hints[5] << Hints[6] << Hints[7]; |
1155 | 5 | } |
1156 | | |
1157 | | // Validate and finalize AltiVec vector declspec. |
1158 | 134M | if (TypeAltiVecVector) { |
1159 | | // No vector long long without VSX (or ZVector). |
1160 | 104k | if ((getTypeSpecWidth() == TypeSpecifierWidth::LongLong) && |
1161 | 104k | !S.Context.getTargetInfo().hasFeature("vsx")2.98k && |
1162 | 104k | !S.getLangOpts().ZVector84 ) |
1163 | 63 | S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_long_decl_spec); |
1164 | | |
1165 | | // No vector __int128 prior to Power8. |
1166 | 104k | if ((TypeSpecType == TST_int128) && |
1167 | 104k | !S.Context.getTargetInfo().hasFeature("power8-vector")76 ) |
1168 | 30 | S.Diag(TSTLoc, diag::err_invalid_vector_int128_decl_spec); |
1169 | | |
1170 | 104k | if (TypeAltiVecBool) { |
1171 | | // Sign specifiers are not allowed with vector bool. (PIM 2.1) |
1172 | 18.8k | if (getTypeSpecSign() != TypeSpecifierSign::Unspecified) { |
1173 | 84 | S.Diag(TSSLoc, diag::err_invalid_vector_bool_decl_spec) |
1174 | 84 | << getSpecifierName(getTypeSpecSign()); |
1175 | 84 | } |
1176 | | // Only char/int are valid with vector bool prior to Power10. |
1177 | | // Power10 adds instructions that produce vector bool data |
1178 | | // for quadwords as well so allow vector bool __int128. |
1179 | 18.8k | if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char)12.0k && |
1180 | 18.8k | (TypeSpecType != TST_int)6.36k && (TypeSpecType != TST_int128)116 ) || |
1181 | 18.8k | TypeAltiVecPixel18.7k ) { |
1182 | 72 | S.Diag(TSTLoc, diag::err_invalid_vector_bool_decl_spec) |
1183 | 72 | << (TypeAltiVecPixel ? "__pixel"24 : |
1184 | 72 | getSpecifierName((TST)TypeSpecType, Policy)48 ); |
1185 | 72 | } |
1186 | | // vector bool __int128 requires Power10. |
1187 | 18.8k | if ((TypeSpecType == TST_int128) && |
1188 | 18.8k | (!S.Context.getTargetInfo().hasFeature("power10-vector"))68 ) |
1189 | 60 | S.Diag(TSTLoc, diag::err_invalid_vector_bool_int128_decl_spec); |
1190 | | |
1191 | | // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1) |
1192 | 18.8k | if ((getTypeSpecWidth() != TypeSpecifierWidth::Unspecified) && |
1193 | 18.8k | (getTypeSpecWidth() != TypeSpecifierWidth::Short)6.72k && |
1194 | 18.8k | (getTypeSpecWidth() != TypeSpecifierWidth::LongLong)856 ) |
1195 | 24 | S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec) |
1196 | 24 | << getSpecifierName(getTypeSpecWidth()); |
1197 | | |
1198 | | // Elements of vector bool are interpreted as unsigned. (PIM 2.1) |
1199 | 18.8k | if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int)13.1k || |
1200 | 18.8k | (TypeSpecType == TST_int128)6.87k || |
1201 | 18.8k | (getTypeSpecWidth() != TypeSpecifierWidth::Unspecified)6.80k ) |
1202 | 18.7k | TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unsigned); |
1203 | 85.2k | } else if (TypeSpecType == TST_double) { |
1204 | | // vector long double and vector long long double are never allowed. |
1205 | | // vector double is OK for Power7 and later, and ZVector. |
1206 | 977 | if (getTypeSpecWidth() == TypeSpecifierWidth::Long || |
1207 | 977 | getTypeSpecWidth() == TypeSpecifierWidth::LongLong925 ) |
1208 | 52 | S.Diag(TSWRange.getBegin(), |
1209 | 52 | diag::err_invalid_vector_long_double_decl_spec); |
1210 | 925 | else if (!S.Context.getTargetInfo().hasFeature("vsx") && |
1211 | 925 | !S.getLangOpts().ZVector24 ) |
1212 | 18 | S.Diag(TSTLoc, diag::err_invalid_vector_double_decl_spec); |
1213 | 84.2k | } else if (TypeSpecType == TST_float) { |
1214 | | // vector float is unsupported for ZVector unless we have the |
1215 | | // vector-enhancements facility 1 (ISA revision 12). |
1216 | 6.63k | if (S.getLangOpts().ZVector && |
1217 | 6.63k | !S.Context.getTargetInfo().hasFeature("arch12")9 ) |
1218 | 2 | S.Diag(TSTLoc, diag::err_invalid_vector_float_decl_spec); |
1219 | 77.6k | } else if (getTypeSpecWidth() == TypeSpecifierWidth::Long) { |
1220 | | // Vector long is unsupported for ZVector, or without VSX, and deprecated |
1221 | | // for AltiVec. |
1222 | | // It has also been historically deprecated on AIX (as an alias for |
1223 | | // "vector int" in both 32-bit and 64-bit modes). It was then made |
1224 | | // unsupported in the Clang-based XL compiler since the deprecated type |
1225 | | // has a number of conflicting semantics and continuing to support it |
1226 | | // is a disservice to users. |
1227 | 150 | if (S.getLangOpts().ZVector || |
1228 | 150 | !S.Context.getTargetInfo().hasFeature("vsx")148 || |
1229 | 150 | S.Context.getTargetInfo().getTriple().isOSAIX()40 ) |
1230 | 110 | S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_decl_spec); |
1231 | 40 | else |
1232 | 40 | S.Diag(TSWRange.getBegin(), |
1233 | 40 | diag::warn_vector_long_decl_spec_combination) |
1234 | 40 | << getSpecifierName((TST)TypeSpecType, Policy); |
1235 | 150 | } |
1236 | | |
1237 | 104k | if (TypeAltiVecPixel) { |
1238 | | //TODO: perform validation |
1239 | 2.57k | TypeSpecType = TST_int; |
1240 | 2.57k | TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unsigned); |
1241 | 2.57k | TypeSpecWidth = static_cast<unsigned>(TypeSpecifierWidth::Short); |
1242 | 2.57k | TypeSpecOwned = false; |
1243 | 2.57k | } |
1244 | 104k | } |
1245 | | |
1246 | 134M | bool IsFixedPointType = |
1247 | 134M | TypeSpecType == TST_accum || TypeSpecType == TST_fract134M ; |
1248 | | |
1249 | | // signed/unsigned are only valid with int/char/wchar_t/_Accum. |
1250 | 134M | if (getTypeSpecSign() != TypeSpecifierSign::Unspecified) { |
1251 | 819k | if (TypeSpecType == TST_unspecified) |
1252 | 344k | TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. |
1253 | 475k | else if (TypeSpecType != TST_int && TypeSpecType != TST_int128191k && |
1254 | 475k | TypeSpecType != TST_char191k && TypeSpecType != TST_wchar856 && |
1255 | 475k | !IsFixedPointType850 && TypeSpecType != TST_bitint116 ) { |
1256 | 4 | S.Diag(TSSLoc, diag::err_invalid_sign_spec) |
1257 | 4 | << getSpecifierName((TST)TypeSpecType, Policy); |
1258 | | // signed double -> double. |
1259 | 4 | TypeSpecSign = static_cast<unsigned>(TypeSpecifierSign::Unspecified); |
1260 | 4 | } |
1261 | 819k | } |
1262 | | |
1263 | | // Validate the width of the type. |
1264 | 134M | switch (getTypeSpecWidth()) { |
1265 | 133M | case TypeSpecifierWidth::Unspecified: |
1266 | 133M | break; |
1267 | 253k | case TypeSpecifierWidth::Short: // short int |
1268 | 455k | case TypeSpecifierWidth::LongLong: // long long int |
1269 | 455k | if (TypeSpecType == TST_unspecified) |
1270 | 233k | TypeSpecType = TST_int; // short -> short int, long long -> long long int. |
1271 | 221k | else if (!(TypeSpecType == TST_int || |
1272 | 221k | (697 IsFixedPointType697 && |
1273 | 697 | getTypeSpecWidth() != TypeSpecifierWidth::LongLong694 ))) { |
1274 | 11 | S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec) |
1275 | 11 | << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy); |
1276 | 11 | TypeSpecType = TST_int; |
1277 | 11 | TypeSpecSat = false; |
1278 | 11 | TypeSpecOwned = false; |
1279 | 11 | } |
1280 | 455k | break; |
1281 | 495k | case TypeSpecifierWidth::Long: // long double, long int |
1282 | 495k | if (TypeSpecType == TST_unspecified) |
1283 | 144k | TypeSpecType = TST_int; // long -> long int. |
1284 | 351k | else if (TypeSpecType != TST_int && TypeSpecType != TST_double188k && |
1285 | 351k | !IsFixedPointType362 ) { |
1286 | 8 | S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec) |
1287 | 8 | << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy); |
1288 | 8 | TypeSpecType = TST_int; |
1289 | 8 | TypeSpecSat = false; |
1290 | 8 | TypeSpecOwned = false; |
1291 | 8 | } |
1292 | 495k | break; |
1293 | 134M | } |
1294 | | |
1295 | | // TODO: if the implementation does not implement _Complex or _Imaginary, |
1296 | | // disallow their use. Need information about the backend. |
1297 | 134M | if (TypeSpecComplex != TSC_unspecified) { |
1298 | 8.32k | if (TypeSpecType == TST_unspecified) { |
1299 | 6 | S.Diag(TSCLoc, diag::ext_plain_complex) |
1300 | 6 | << FixItHint::CreateInsertion( |
1301 | 6 | S.getLocForEndOfToken(getTypeSpecComplexLoc()), |
1302 | 6 | " double"); |
1303 | 6 | TypeSpecType = TST_double; // _Complex -> _Complex double. |
1304 | 8.32k | } else if (TypeSpecType == TST_int || TypeSpecType == TST_char7.99k || |
1305 | 8.32k | TypeSpecType == TST_bitint7.92k ) { |
1306 | | // Note that this intentionally doesn't include _Complex _Bool. |
1307 | 409 | if (!S.getLangOpts().CPlusPlus) |
1308 | 300 | S.Diag(TSTLoc, diag::ext_integer_complex); |
1309 | 7.91k | } else if (TypeSpecType != TST_float && TypeSpecType != TST_double5.07k && |
1310 | 7.91k | TypeSpecType != TST_float128122 && TypeSpecType != TST_float16119 && |
1311 | 7.91k | TypeSpecType != TST_ibm12838 ) { |
1312 | | // FIXME: __fp16? |
1313 | 37 | S.Diag(TSCLoc, diag::err_invalid_complex_spec) |
1314 | 37 | << getSpecifierName((TST)TypeSpecType, Policy); |
1315 | 37 | TypeSpecComplex = TSC_unspecified; |
1316 | 37 | } |
1317 | 8.32k | } |
1318 | | |
1319 | | // C11 6.7.1/3, C++11 [dcl.stc]p1, GNU TLS: __thread, thread_local and |
1320 | | // _Thread_local can only appear with the 'static' and 'extern' storage class |
1321 | | // specifiers. We also allow __private_extern__ as an extension. |
1322 | 134M | if (ThreadStorageClassSpec != TSCS_unspecified) { |
1323 | 1.03k | switch (StorageClassSpec) { |
1324 | 642 | case SCS_unspecified: |
1325 | 707 | case SCS_extern: |
1326 | 721 | case SCS_private_extern: |
1327 | 1.00k | case SCS_static: |
1328 | 1.00k | break; |
1329 | 31 | default: |
1330 | 31 | if (S.getSourceManager().isBeforeInTranslationUnit( |
1331 | 31 | getThreadStorageClassSpecLoc(), getStorageClassSpecLoc())) |
1332 | 19 | S.Diag(getStorageClassSpecLoc(), |
1333 | 19 | diag::err_invalid_decl_spec_combination) |
1334 | 19 | << DeclSpec::getSpecifierName(getThreadStorageClassSpec()) |
1335 | 19 | << SourceRange(getThreadStorageClassSpecLoc()); |
1336 | 12 | else |
1337 | 12 | S.Diag(getThreadStorageClassSpecLoc(), |
1338 | 12 | diag::err_invalid_decl_spec_combination) |
1339 | 12 | << DeclSpec::getSpecifierName(getStorageClassSpec()) |
1340 | 12 | << SourceRange(getStorageClassSpecLoc()); |
1341 | | // Discard the thread storage class specifier to recover. |
1342 | 31 | ThreadStorageClassSpec = TSCS_unspecified; |
1343 | 31 | ThreadStorageClassSpecLoc = SourceLocation(); |
1344 | 1.03k | } |
1345 | 1.03k | } |
1346 | | |
1347 | | // If no type specifier was provided and we're parsing a language where |
1348 | | // the type specifier is not optional, but we got 'auto' as a storage |
1349 | | // class specifier, then assume this is an attempt to use C++0x's 'auto' |
1350 | | // type specifier. |
1351 | 134M | if (S.getLangOpts().CPlusPlus && |
1352 | 134M | TypeSpecType == TST_unspecified66.8M && StorageClassSpec == SCS_auto16.7M ) { |
1353 | 98 | TypeSpecType = TST_auto; |
1354 | 98 | StorageClassSpec = SCS_unspecified; |
1355 | 98 | TSTLoc = TSTNameLoc = StorageClassSpecLoc; |
1356 | 98 | StorageClassSpecLoc = SourceLocation(); |
1357 | 98 | } |
1358 | | // Diagnose if we've recovered from an ill-formed 'auto' storage class |
1359 | | // specifier in a pre-C++11 dialect of C++. |
1360 | 134M | if (!S.getLangOpts().CPlusPlus11 && TypeSpecType == TST_auto67.4M ) |
1361 | 106 | S.Diag(TSTLoc, diag::ext_auto_type_specifier); |
1362 | 134M | if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus1166.8M && |
1363 | 134M | StorageClassSpec == SCS_auto223k ) |
1364 | 21 | S.Diag(StorageClassSpecLoc, diag::warn_auto_storage_class) |
1365 | 21 | << FixItHint::CreateRemoval(StorageClassSpecLoc); |
1366 | 134M | if (TypeSpecType == TST_char8) |
1367 | 183 | S.Diag(TSTLoc, diag::warn_cxx17_compat_unicode_type); |
1368 | 134M | else if (TypeSpecType == TST_char16 || TypeSpecType == TST_char32134M ) |
1369 | 16.0k | S.Diag(TSTLoc, diag::warn_cxx98_compat_unicode_type) |
1370 | 16.0k | << (TypeSpecType == TST_char16 ? "char16_t"8.00k : "char32_t"8.01k ); |
1371 | 134M | if (getConstexprSpecifier() == ConstexprSpecKind::Constexpr) |
1372 | 395k | S.Diag(ConstexprLoc, diag::warn_cxx98_compat_constexpr); |
1373 | 133M | else if (getConstexprSpecifier() == ConstexprSpecKind::Consteval) |
1374 | 193 | S.Diag(ConstexprLoc, diag::warn_cxx20_compat_consteval); |
1375 | 133M | else if (getConstexprSpecifier() == ConstexprSpecKind::Constinit) |
1376 | 82 | S.Diag(ConstexprLoc, diag::warn_cxx20_compat_constinit); |
1377 | | // C++ [class.friend]p6: |
1378 | | // No storage-class-specifier shall appear in the decl-specifier-seq |
1379 | | // of a friend declaration. |
1380 | 134M | if (isFriendSpecified() && |
1381 | 134M | (77.6k getStorageClassSpec()77.6k || getThreadStorageClassSpec()77.5k )) { |
1382 | 18 | SmallString<32> SpecName; |
1383 | 18 | SourceLocation SCLoc; |
1384 | 18 | FixItHint StorageHint, ThreadHint; |
1385 | | |
1386 | 18 | if (DeclSpec::SCS SC = getStorageClassSpec()) { |
1387 | 13 | SpecName = getSpecifierName(SC); |
1388 | 13 | SCLoc = getStorageClassSpecLoc(); |
1389 | 13 | StorageHint = FixItHint::CreateRemoval(SCLoc); |
1390 | 13 | } |
1391 | | |
1392 | 18 | if (DeclSpec::TSCS TSC = getThreadStorageClassSpec()) { |
1393 | 7 | if (!SpecName.empty()) SpecName += " "2 ; |
1394 | 7 | SpecName += getSpecifierName(TSC); |
1395 | 7 | SCLoc = getThreadStorageClassSpecLoc(); |
1396 | 7 | ThreadHint = FixItHint::CreateRemoval(SCLoc); |
1397 | 7 | } |
1398 | | |
1399 | 18 | S.Diag(SCLoc, diag::err_friend_decl_spec) |
1400 | 18 | << SpecName << StorageHint << ThreadHint; |
1401 | | |
1402 | 18 | ClearStorageClassSpecs(); |
1403 | 18 | } |
1404 | | |
1405 | | // C++11 [dcl.fct.spec]p5: |
1406 | | // The virtual specifier shall be used only in the initial |
1407 | | // declaration of a non-static class member function; |
1408 | | // C++11 [dcl.fct.spec]p6: |
1409 | | // The explicit specifier shall be used only in the declaration of |
1410 | | // a constructor or conversion function within its class |
1411 | | // definition; |
1412 | 134M | if (isFriendSpecified() && (77.6k isVirtualSpecified()77.6k || hasExplicitSpecifier()77.6k )) { |
1413 | 14 | StringRef Keyword; |
1414 | 14 | FixItHint Hint; |
1415 | 14 | SourceLocation SCLoc; |
1416 | | |
1417 | 14 | if (isVirtualSpecified()) { |
1418 | 7 | Keyword = "virtual"; |
1419 | 7 | SCLoc = getVirtualSpecLoc(); |
1420 | 7 | Hint = FixItHint::CreateRemoval(SCLoc); |
1421 | 7 | } else { |
1422 | 7 | Keyword = "explicit"; |
1423 | 7 | SCLoc = getExplicitSpecLoc(); |
1424 | 7 | Hint = FixItHint::CreateRemoval(getExplicitSpecRange()); |
1425 | 7 | } |
1426 | | |
1427 | 14 | S.Diag(SCLoc, diag::err_friend_decl_spec) |
1428 | 14 | << Keyword << Hint; |
1429 | | |
1430 | 14 | FS_virtual_specified = false; |
1431 | 14 | FS_explicit_specifier = ExplicitSpecifier(); |
1432 | 14 | FS_virtualLoc = FS_explicitLoc = SourceLocation(); |
1433 | 14 | } |
1434 | | |
1435 | 134M | assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType)); |
1436 | | |
1437 | | // Okay, now we can infer the real type. |
1438 | | |
1439 | | // TODO: return "auto function" and other bad things based on the real type. |
1440 | | |
1441 | | // 'data definition has no type or storage class'? |
1442 | 134M | } |
1443 | | |
1444 | 1.47M | bool DeclSpec::isMissingDeclaratorOk() { |
1445 | 1.47M | TST tst = getTypeSpecType(); |
1446 | 1.47M | return isDeclRep(tst) && getRepAsDecl() != nullptr1.47M && |
1447 | 1.47M | StorageClassSpec != DeclSpec::SCS_typedef1.47M ; |
1448 | 1.47M | } |
1449 | | |
1450 | | void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc, |
1451 | | OverloadedOperatorKind Op, |
1452 | 449k | SourceLocation SymbolLocations[3]) { |
1453 | 449k | Kind = UnqualifiedIdKind::IK_OperatorFunctionId; |
1454 | 449k | StartLocation = OperatorLoc; |
1455 | 449k | EndLocation = OperatorLoc; |
1456 | 449k | new (&OperatorFunctionId) struct OFI; |
1457 | 449k | OperatorFunctionId.Operator = Op; |
1458 | 1.79M | for (unsigned I = 0; I != 3; ++I1.34M ) { |
1459 | 1.34M | OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I]; |
1460 | | |
1461 | 1.34M | if (SymbolLocations[I].isValid()) |
1462 | 578k | EndLocation = SymbolLocations[I]; |
1463 | 1.34M | } |
1464 | 449k | } |
1465 | | |
1466 | | bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc, |
1467 | 642 | const char *&PrevSpec) { |
1468 | 642 | if (!FirstLocation.isValid()) |
1469 | 620 | FirstLocation = Loc; |
1470 | 642 | LastLocation = Loc; |
1471 | 642 | LastSpecifier = VS; |
1472 | | |
1473 | 642 | if (Specifiers & VS) { |
1474 | 4 | PrevSpec = getSpecifierName(VS); |
1475 | 4 | return true; |
1476 | 4 | } |
1477 | | |
1478 | 638 | Specifiers |= VS; |
1479 | | |
1480 | 638 | switch (VS) { |
1481 | 0 | default: llvm_unreachable("Unknown specifier!"); |
1482 | 536 | case VS_Override: VS_overrideLoc = Loc; break; |
1483 | 2 | case VS_GNU_Final: |
1484 | 8 | case VS_Sealed: |
1485 | 90 | case VS_Final: VS_finalLoc = Loc; break; |
1486 | 12 | case VS_Abstract: VS_abstractLoc = Loc; break; |
1487 | 638 | } |
1488 | | |
1489 | 638 | return false; |
1490 | 638 | } |
1491 | | |
1492 | 842 | const char *VirtSpecifiers::getSpecifierName(Specifier VS) { |
1493 | 842 | switch (VS) { |
1494 | 0 | default: llvm_unreachable("Unknown specifier"); |
1495 | 549 | case VS_Override: return "override"; |
1496 | 284 | case VS_Final: return "final"; |
1497 | 0 | case VS_GNU_Final: return "__final"; |
1498 | 6 | case VS_Sealed: return "sealed"; |
1499 | 3 | case VS_Abstract: return "abstract"; |
1500 | 842 | } |
1501 | 842 | } |