| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #include "TypeLocBuilder.h" |
| 14 | #include "clang/AST/ASTConsumer.h" |
| 15 | #include "clang/AST/ASTContext.h" |
| 16 | #include "clang/AST/ASTMutationListener.h" |
| 17 | #include "clang/AST/ASTStructuralEquivalence.h" |
| 18 | #include "clang/AST/CXXInheritance.h" |
| 19 | #include "clang/AST/DeclObjC.h" |
| 20 | #include "clang/AST/DeclTemplate.h" |
| 21 | #include "clang/AST/Expr.h" |
| 22 | #include "clang/AST/TypeLoc.h" |
| 23 | #include "clang/AST/TypeLocVisitor.h" |
| 24 | #include "clang/Basic/PartialDiagnostic.h" |
| 25 | #include "clang/Basic/TargetInfo.h" |
| 26 | #include "clang/Lex/Preprocessor.h" |
| 27 | #include "clang/Sema/DeclSpec.h" |
| 28 | #include "clang/Sema/DelayedDiagnostic.h" |
| 29 | #include "clang/Sema/Lookup.h" |
| 30 | #include "clang/Sema/ScopeInfo.h" |
| 31 | #include "clang/Sema/SemaInternal.h" |
| 32 | #include "clang/Sema/Template.h" |
| 33 | #include "clang/Sema/TemplateInstCallback.h" |
| 34 | #include "llvm/ADT/SmallPtrSet.h" |
| 35 | #include "llvm/ADT/SmallString.h" |
| 36 | #include "llvm/ADT/StringSwitch.h" |
| 37 | #include "llvm/Support/ErrorHandling.h" |
| 38 | |
| 39 | using namespace clang; |
| 40 | |
| 41 | enum TypeDiagSelector { |
| 42 | TDS_Function, |
| 43 | TDS_Pointer, |
| 44 | TDS_ObjCObjOrBlock |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | |
| 49 | static bool isOmittedBlockReturnType(const Declarator &D) { |
| 50 | if (D.getContext() != DeclaratorContext::BlockLiteralContext || |
| 51 | D.getDeclSpec().hasTypeSpecifier()) |
| 52 | return false; |
| 53 | |
| 54 | if (D.getNumTypeObjects() == 0) |
| 55 | return true; |
| 56 | |
| 57 | if (D.getNumTypeObjects() == 1 && |
| 58 | D.getTypeObject(0).Kind == DeclaratorChunk::Function) |
| 59 | return true; |
| 60 | |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | |
| 66 | static void diagnoseBadTypeAttribute(Sema &S, const ParsedAttr &attr, |
| 67 | QualType type) { |
| 68 | TypeDiagSelector WhichType; |
| 69 | bool useExpansionLoc = true; |
| 70 | switch (attr.getKind()) { |
| 71 | case ParsedAttr::AT_ObjCGC: |
| 72 | WhichType = TDS_Pointer; |
| 73 | break; |
| 74 | case ParsedAttr::AT_ObjCOwnership: |
| 75 | WhichType = TDS_ObjCObjOrBlock; |
| 76 | break; |
| 77 | default: |
| 78 | |
| 79 | WhichType = TDS_Function; |
| 80 | useExpansionLoc = false; |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | SourceLocation loc = attr.getLoc(); |
| 85 | StringRef name = attr.getName()->getName(); |
| 86 | |
| 87 | |
| 88 | IdentifierInfo *II = attr.isArgIdent(0) ? attr.getArgAsIdent(0)->Ident |
| 89 | : nullptr; |
| 90 | if (useExpansionLoc && loc.isMacroID() && II) { |
| 91 | if (II->isStr("strong")) { |
| 92 | if (S.findMacroSpelling(loc, "__strong")) name = "__strong"; |
| 93 | } else if (II->isStr("weak")) { |
| 94 | if (S.findMacroSpelling(loc, "__weak")) name = "__weak"; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | S.Diag(loc, diag::warn_type_attribute_wrong_type) << name << WhichType |
| 99 | << type; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | |
| 104 | #define OBJC_POINTER_TYPE_ATTRS_CASELIST \ |
| 105 | case ParsedAttr::AT_ObjCGC: \ |
| 106 | case ParsedAttr::AT_ObjCOwnership |
| 107 | |
| 108 | |
| 109 | #define CALLING_CONV_ATTRS_CASELIST \ |
| 110 | case ParsedAttr::AT_CDecl: \ |
| 111 | case ParsedAttr::AT_FastCall: \ |
| 112 | case ParsedAttr::AT_StdCall: \ |
| 113 | case ParsedAttr::AT_ThisCall: \ |
| 114 | case ParsedAttr::AT_RegCall: \ |
| 115 | case ParsedAttr::AT_Pascal: \ |
| 116 | case ParsedAttr::AT_SwiftCall: \ |
| 117 | case ParsedAttr::AT_VectorCall: \ |
| 118 | case ParsedAttr::AT_AArch64VectorPcs: \ |
| 119 | case ParsedAttr::AT_MSABI: \ |
| 120 | case ParsedAttr::AT_SysVABI: \ |
| 121 | case ParsedAttr::AT_Pcs: \ |
| 122 | case ParsedAttr::AT_IntelOclBicc: \ |
| 123 | case ParsedAttr::AT_PreserveMost: \ |
| 124 | case ParsedAttr::AT_PreserveAll |
| 125 | |
| 126 | |
| 127 | #define FUNCTION_TYPE_ATTRS_CASELIST \ |
| 128 | case ParsedAttr::AT_NSReturnsRetained: \ |
| 129 | case ParsedAttr::AT_NoReturn: \ |
| 130 | case ParsedAttr::AT_Regparm: \ |
| 131 | case ParsedAttr::AT_AnyX86NoCallerSavedRegisters: \ |
| 132 | case ParsedAttr::AT_AnyX86NoCfCheck: \ |
| 133 | CALLING_CONV_ATTRS_CASELIST |
| 134 | |
| 135 | |
| 136 | #define MS_TYPE_ATTRS_CASELIST \ |
| 137 | case ParsedAttr::AT_Ptr32: \ |
| 138 | case ParsedAttr::AT_Ptr64: \ |
| 139 | case ParsedAttr::AT_SPtr: \ |
| 140 | case ParsedAttr::AT_UPtr |
| 141 | |
| 142 | |
| 143 | #define NULLABILITY_TYPE_ATTRS_CASELIST \ |
| 144 | case ParsedAttr::AT_TypeNonNull: \ |
| 145 | case ParsedAttr::AT_TypeNullable: \ |
| 146 | case ParsedAttr::AT_TypeNullUnspecified |
| 147 | |
| 148 | namespace { |
| 149 | |
| 150 | |
| 151 | class TypeProcessingState { |
| 152 | Sema &sema; |
| 153 | |
| 154 | |
| 155 | Declarator &declarator; |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | unsigned chunkIndex; |
| 161 | |
| 162 | |
| 163 | bool trivial; |
| 164 | |
| 165 | |
| 166 | bool hasSavedAttrs; |
| 167 | |
| 168 | |
| 169 | SmallVector<ParsedAttr *, 2> savedAttrs; |
| 170 | |
| 171 | |
| 172 | |
| 173 | SmallVector<ParsedAttr *, 2> ignoredTypeAttrs; |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | using TypeAttrPair = std::pair<const AttributedType*, const Attr*>; |
| 182 | SmallVector<TypeAttrPair, 8> AttrsForTypes; |
| 183 | bool AttrsForTypesSorted = true; |
| 184 | |
| 185 | |
| 186 | |
| 187 | bool parsedNoDeref; |
| 188 | |
| 189 | public: |
| 190 | TypeProcessingState(Sema &sema, Declarator &declarator) |
| 191 | : sema(sema), declarator(declarator), |
| 192 | chunkIndex(declarator.getNumTypeObjects()), trivial(true), |
| 193 | hasSavedAttrs(false), parsedNoDeref(false) {} |
| 194 | |
| 195 | Sema &getSema() const { |
| 196 | return sema; |
| 197 | } |
| 198 | |
| 199 | Declarator &getDeclarator() const { |
| 200 | return declarator; |
| 201 | } |
| 202 | |
| 203 | bool isProcessingDeclSpec() const { |
| 204 | return chunkIndex == declarator.getNumTypeObjects(); |
| 205 | } |
| 206 | |
| 207 | unsigned getCurrentChunkIndex() const { |
| 208 | return chunkIndex; |
| 209 | } |
| 210 | |
| 211 | void setCurrentChunkIndex(unsigned idx) { |
| 212 | assert(idx <= declarator.getNumTypeObjects()); |
| 213 | chunkIndex = idx; |
| 214 | } |
| 215 | |
| 216 | ParsedAttributesView &getCurrentAttributes() const { |
| 217 | if (isProcessingDeclSpec()) |
| 218 | return getMutableDeclSpec().getAttributes(); |
| 219 | return declarator.getTypeObject(chunkIndex).getAttrs(); |
| 220 | } |
| 221 | |
| 222 | |
| 223 | void saveDeclSpecAttrs() { |
| 224 | |
| 225 | if (hasSavedAttrs) return; |
| 226 | |
| 227 | DeclSpec &spec = getMutableDeclSpec(); |
| 228 | for (ParsedAttr &AL : spec.getAttributes()) |
| 229 | savedAttrs.push_back(&AL); |
| 230 | trivial &= savedAttrs.empty(); |
| 231 | hasSavedAttrs = true; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | |
| 236 | void addIgnoredTypeAttr(ParsedAttr &attr) { |
| 237 | ignoredTypeAttrs.push_back(&attr); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | |
| 242 | void diagnoseIgnoredTypeAttrs(QualType type) const { |
| 243 | for (auto *Attr : ignoredTypeAttrs) |
| 244 | diagnoseBadTypeAttribute(getSema(), *Attr, type); |
| 245 | } |
| 246 | |
| 247 | |
| 248 | |
| 249 | QualType getAttributedType(Attr *A, QualType ModifiedType, |
| 250 | QualType EquivType) { |
| 251 | QualType T = |
| 252 | sema.Context.getAttributedType(A->getKind(), ModifiedType, EquivType); |
| 253 | AttrsForTypes.push_back({cast<AttributedType>(T.getTypePtr()), A}); |
| 254 | AttrsForTypesSorted = false; |
| 255 | return T; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | const Attr *takeAttrForAttributedType(const AttributedType *AT) { |
| 260 | if (!AttrsForTypesSorted) { |
| 261 | std::stable_sort(AttrsForTypes.begin(), AttrsForTypes.end(), |
| 262 | [](const TypeAttrPair &A, const TypeAttrPair &B) { |
| 263 | return A.first < B.first; |
| 264 | }); |
| 265 | AttrsForTypesSorted = true; |
| 266 | } |
| 267 | |
| 268 | |
| 269 | |
| 270 | for (auto It = std::partition_point( |
| 271 | AttrsForTypes.begin(), AttrsForTypes.end(), |
| 272 | [=](const TypeAttrPair &A) { return A.first < AT; }); |
| 273 | It != AttrsForTypes.end() && It->first == AT; ++It) { |
| 274 | if (It->second) { |
| 275 | const Attr *Result = It->second; |
| 276 | It->second = nullptr; |
| 277 | return Result; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | llvm_unreachable("no Attr* for AttributedType*"); |
| 282 | } |
| 283 | |
| 284 | void setParsedNoDeref(bool parsed) { parsedNoDeref = parsed; } |
| 285 | |
| 286 | bool didParseNoDeref() const { return parsedNoDeref; } |
| 287 | |
| 288 | ~TypeProcessingState() { |
| 289 | if (trivial) return; |
| 290 | |
| 291 | restoreDeclSpecAttrs(); |
| 292 | } |
| 293 | |
| 294 | private: |
| 295 | DeclSpec &getMutableDeclSpec() const { |
| 296 | return const_cast<DeclSpec&>(declarator.getDeclSpec()); |
| 297 | } |
| 298 | |
| 299 | void restoreDeclSpecAttrs() { |
| 300 | assert(hasSavedAttrs); |
| 301 | |
| 302 | getMutableDeclSpec().getAttributes().clearListOnly(); |
| 303 | for (ParsedAttr *AL : savedAttrs) |
| 304 | getMutableDeclSpec().getAttributes().addAtEnd(AL); |
| 305 | } |
| 306 | }; |
| 307 | } |
| 308 | |
| 309 | static void moveAttrFromListToList(ParsedAttr &attr, |
| 310 | ParsedAttributesView &fromList, |
| 311 | ParsedAttributesView &toList) { |
| 312 | fromList.remove(&attr); |
| 313 | toList.addAtEnd(&attr); |
| 314 | } |
| 315 | |
| 316 | |
| 317 | enum TypeAttrLocation { |
| 318 | |
| 319 | TAL_DeclSpec, |
| 320 | |
| 321 | TAL_DeclChunk, |
| 322 | |
| 323 | TAL_DeclName |
| 324 | }; |
| 325 | |
| 326 | static void processTypeAttrs(TypeProcessingState &state, QualType &type, |
| 327 | TypeAttrLocation TAL, ParsedAttributesView &attrs); |
| 328 | |
| 329 | static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr, |
| 330 | QualType &type); |
| 331 | |
| 332 | static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &state, |
| 333 | ParsedAttr &attr, QualType &type); |
| 334 | |
| 335 | static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr, |
| 336 | QualType &type); |
| 337 | |
| 338 | static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, |
| 339 | ParsedAttr &attr, QualType &type); |
| 340 | |
| 341 | static bool handleObjCPointerTypeAttr(TypeProcessingState &state, |
| 342 | ParsedAttr &attr, QualType &type) { |
| 343 | if (attr.getKind() == ParsedAttr::AT_ObjCGC) |
| 344 | return handleObjCGCTypeAttr(state, attr, type); |
| 345 | assert(attr.getKind() == ParsedAttr::AT_ObjCOwnership); |
| 346 | return handleObjCOwnershipTypeAttr(state, attr, type); |
| 347 | } |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | static DeclaratorChunk *maybeMovePastReturnType(Declarator &declarator, |
| 359 | unsigned i, |
| 360 | bool onlyBlockPointers) { |
| 361 | assert(i <= declarator.getNumTypeObjects()); |
| 362 | |
| 363 | DeclaratorChunk *result = nullptr; |
| 364 | |
| 365 | |
| 366 | for (; i != 0; --i) { |
| 367 | DeclaratorChunk &fnChunk = declarator.getTypeObject(i-1); |
| 368 | switch (fnChunk.Kind) { |
| 369 | case DeclaratorChunk::Paren: |
| 370 | continue; |
| 371 | |
| 372 | |
| 373 | case DeclaratorChunk::Pointer: |
| 374 | case DeclaratorChunk::BlockPointer: |
| 375 | case DeclaratorChunk::Array: |
| 376 | case DeclaratorChunk::Reference: |
| 377 | case DeclaratorChunk::MemberPointer: |
| 378 | case DeclaratorChunk::Pipe: |
| 379 | return result; |
| 380 | |
| 381 | |
| 382 | |
| 383 | case DeclaratorChunk::Function: |
| 384 | for (--i; i != 0; --i) { |
| 385 | DeclaratorChunk &ptrChunk = declarator.getTypeObject(i-1); |
| 386 | switch (ptrChunk.Kind) { |
| 387 | case DeclaratorChunk::Paren: |
| 388 | case DeclaratorChunk::Array: |
| 389 | case DeclaratorChunk::Function: |
| 390 | case DeclaratorChunk::Reference: |
| 391 | case DeclaratorChunk::Pipe: |
| 392 | continue; |
| 393 | |
| 394 | case DeclaratorChunk::MemberPointer: |
| 395 | case DeclaratorChunk::Pointer: |
| 396 | if (onlyBlockPointers) |
| 397 | continue; |
| 398 | |
| 399 | LLVM_FALLTHROUGH; |
| 400 | |
| 401 | case DeclaratorChunk::BlockPointer: |
| 402 | result = &ptrChunk; |
| 403 | goto continue_outer; |
| 404 | } |
| 405 | llvm_unreachable("bad declarator chunk kind"); |
| 406 | } |
| 407 | |
| 408 | |
| 409 | return result; |
| 410 | } |
| 411 | llvm_unreachable("bad declarator chunk kind"); |
| 412 | |
| 413 | |
| 414 | continue_outer: ; |
| 415 | } |
| 416 | |
| 417 | |
| 418 | return result; |
| 419 | } |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | static void distributeObjCPointerTypeAttr(TypeProcessingState &state, |
| 427 | ParsedAttr &attr, QualType type) { |
| 428 | Declarator &declarator = state.getDeclarator(); |
| 429 | |
| 430 | |
| 431 | for (unsigned i = state.getCurrentChunkIndex(); i != 0; --i) { |
| 432 | DeclaratorChunk &chunk = declarator.getTypeObject(i-1); |
| 433 | switch (chunk.Kind) { |
| 434 | case DeclaratorChunk::Pointer: |
| 435 | case DeclaratorChunk::BlockPointer: { |
| 436 | |
| 437 | |
| 438 | DeclaratorChunk *destChunk = nullptr; |
| 439 | if (state.isProcessingDeclSpec() && |
| 440 | attr.getKind() == ParsedAttr::AT_ObjCOwnership) |
| 441 | destChunk = maybeMovePastReturnType(declarator, i - 1, |
| 442 | ); |
| 443 | if (!destChunk) destChunk = &chunk; |
| 444 | |
| 445 | moveAttrFromListToList(attr, state.getCurrentAttributes(), |
| 446 | destChunk->getAttrs()); |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | case DeclaratorChunk::Paren: |
| 451 | case DeclaratorChunk::Array: |
| 452 | continue; |
| 453 | |
| 454 | |
| 455 | case DeclaratorChunk::Function: |
| 456 | if (state.isProcessingDeclSpec() && |
| 457 | attr.getKind() == ParsedAttr::AT_ObjCOwnership) { |
| 458 | if (DeclaratorChunk *dest = maybeMovePastReturnType( |
| 459 | declarator, i, |
| 460 | )) { |
| 461 | moveAttrFromListToList(attr, state.getCurrentAttributes(), |
| 462 | dest->getAttrs()); |
| 463 | return; |
| 464 | } |
| 465 | } |
| 466 | goto error; |
| 467 | |
| 468 | |
| 469 | case DeclaratorChunk::Reference: |
| 470 | case DeclaratorChunk::MemberPointer: |
| 471 | case DeclaratorChunk::Pipe: |
| 472 | goto error; |
| 473 | } |
| 474 | } |
| 475 | error: |
| 476 | |
| 477 | diagnoseBadTypeAttribute(state.getSema(), attr, type); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | |
| 482 | static void distributeObjCPointerTypeAttrFromDeclarator( |
| 483 | TypeProcessingState &state, ParsedAttr &attr, QualType &declSpecType) { |
| 484 | Declarator &declarator = state.getDeclarator(); |
| 485 | |
| 486 | |
| 487 | |
| 488 | unsigned innermost = -1U; |
| 489 | bool considerDeclSpec = true; |
| 490 | for (unsigned i = 0, e = declarator.getNumTypeObjects(); i != e; ++i) { |
| 491 | DeclaratorChunk &chunk = declarator.getTypeObject(i); |
| 492 | switch (chunk.Kind) { |
| 493 | case DeclaratorChunk::Pointer: |
| 494 | case DeclaratorChunk::BlockPointer: |
| 495 | innermost = i; |
| 496 | continue; |
| 497 | |
| 498 | case DeclaratorChunk::Reference: |
| 499 | case DeclaratorChunk::MemberPointer: |
| 500 | case DeclaratorChunk::Paren: |
| 501 | case DeclaratorChunk::Array: |
| 502 | case DeclaratorChunk::Pipe: |
| 503 | continue; |
| 504 | |
| 505 | case DeclaratorChunk::Function: |
| 506 | considerDeclSpec = false; |
| 507 | goto done; |
| 508 | } |
| 509 | } |
| 510 | done: |
| 511 | |
| 512 | |
| 513 | |
| 514 | if (considerDeclSpec) { |
| 515 | if (handleObjCPointerTypeAttr(state, attr, declSpecType)) { |
| 516 | |
| 517 | |
| 518 | |
| 519 | state.saveDeclSpecAttrs(); |
| 520 | moveAttrFromListToList(attr, declarator.getAttributes(), |
| 521 | declarator.getMutableDeclSpec().getAttributes()); |
| 522 | return; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | |
| 527 | |
| 528 | if (innermost != -1U) { |
| 529 | moveAttrFromListToList(attr, declarator.getAttributes(), |
| 530 | declarator.getTypeObject(innermost).getAttrs()); |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | |
| 535 | declarator.getAttributes().remove(&attr); |
| 536 | state.addIgnoredTypeAttr(attr); |
| 537 | } |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | static void distributeFunctionTypeAttr(TypeProcessingState &state, |
| 544 | ParsedAttr &attr, QualType type) { |
| 545 | Declarator &declarator = state.getDeclarator(); |
| 546 | |
| 547 | |
| 548 | |
| 549 | for (unsigned i = state.getCurrentChunkIndex(); i != 0; --i) { |
| 550 | DeclaratorChunk &chunk = declarator.getTypeObject(i-1); |
| 551 | switch (chunk.Kind) { |
| 552 | case DeclaratorChunk::Function: |
| 553 | moveAttrFromListToList(attr, state.getCurrentAttributes(), |
| 554 | chunk.getAttrs()); |
| 555 | return; |
| 556 | |
| 557 | case DeclaratorChunk::Paren: |
| 558 | case DeclaratorChunk::Pointer: |
| 559 | case DeclaratorChunk::BlockPointer: |
| 560 | case DeclaratorChunk::Array: |
| 561 | case DeclaratorChunk::Reference: |
| 562 | case DeclaratorChunk::MemberPointer: |
| 563 | case DeclaratorChunk::Pipe: |
| 564 | continue; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | diagnoseBadTypeAttribute(state.getSema(), attr, type); |
| 569 | } |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | static bool distributeFunctionTypeAttrToInnermost( |
| 575 | TypeProcessingState &state, ParsedAttr &attr, |
| 576 | ParsedAttributesView &attrList, QualType &declSpecType) { |
| 577 | Declarator &declarator = state.getDeclarator(); |
| 578 | |
| 579 | |
| 580 | for (unsigned i = 0, e = declarator.getNumTypeObjects(); i != e; ++i) { |
| 581 | DeclaratorChunk &chunk = declarator.getTypeObject(i); |
| 582 | if (chunk.Kind != DeclaratorChunk::Function) continue; |
| 583 | |
| 584 | moveAttrFromListToList(attr, attrList, chunk.getAttrs()); |
| 585 | return true; |
| 586 | } |
| 587 | |
| 588 | return handleFunctionTypeAttr(state, attr, declSpecType); |
| 589 | } |
| 590 | |
| 591 | |
| 592 | |
| 593 | static void distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state, |
| 594 | ParsedAttr &attr, |
| 595 | QualType &declSpecType) { |
| 596 | state.saveDeclSpecAttrs(); |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | if (attr.isCXX11Attribute()) { |
| 602 | moveAttrFromListToList(attr, state.getCurrentAttributes(), |
| 603 | state.getDeclarator().getAttributes()); |
| 604 | return; |
| 605 | } |
| 606 | |
| 607 | |
| 608 | if (distributeFunctionTypeAttrToInnermost( |
| 609 | state, attr, state.getCurrentAttributes(), declSpecType)) |
| 610 | return; |
| 611 | |
| 612 | |
| 613 | |
| 614 | state.addIgnoredTypeAttr(attr); |
| 615 | } |
| 616 | |
| 617 | |
| 618 | |
| 619 | static void distributeFunctionTypeAttrFromDeclarator(TypeProcessingState &state, |
| 620 | ParsedAttr &attr, |
| 621 | QualType &declSpecType) { |
| 622 | Declarator &declarator = state.getDeclarator(); |
| 623 | |
| 624 | |
| 625 | if (distributeFunctionTypeAttrToInnermost( |
| 626 | state, attr, declarator.getAttributes(), declSpecType)) |
| 627 | return; |
| 628 | |
| 629 | |
| 630 | |
| 631 | declarator.getAttributes().remove(&attr); |
| 632 | state.addIgnoredTypeAttr(attr); |
| 633 | } |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | static void distributeTypeAttrsFromDeclarator(TypeProcessingState &state, |
| 645 | QualType &declSpecType) { |
| 646 | |
| 647 | (0) . __assert_fail ("!state.getDeclarator().getAttributes().empty() && \"declarator has no attrs!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 648, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!state.getDeclarator().getAttributes().empty() && |
| 648 | (0) . __assert_fail ("!state.getDeclarator().getAttributes().empty() && \"declarator has no attrs!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 648, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "declarator has no attrs!"); |
| 649 | |
| 650 | |
| 651 | |
| 652 | ParsedAttributesView AttrsCopy{state.getDeclarator().getAttributes()}; |
| 653 | for (ParsedAttr &attr : AttrsCopy) { |
| 654 | |
| 655 | |
| 656 | if (attr.isCXX11Attribute()) |
| 657 | continue; |
| 658 | |
| 659 | switch (attr.getKind()) { |
| 660 | OBJC_POINTER_TYPE_ATTRS_CASELIST: |
| 661 | distributeObjCPointerTypeAttrFromDeclarator(state, attr, declSpecType); |
| 662 | break; |
| 663 | |
| 664 | FUNCTION_TYPE_ATTRS_CASELIST: |
| 665 | distributeFunctionTypeAttrFromDeclarator(state, attr, declSpecType); |
| 666 | break; |
| 667 | |
| 668 | MS_TYPE_ATTRS_CASELIST: |
| 669 | |
| 670 | continue; |
| 671 | |
| 672 | NULLABILITY_TYPE_ATTRS_CASELIST: |
| 673 | |
| 674 | |
| 675 | |
| 676 | case ParsedAttr::AT_ObjCKindOf: |
| 677 | continue; |
| 678 | |
| 679 | default: |
| 680 | break; |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | |
| 686 | |
| 687 | static void maybeSynthesizeBlockSignature(TypeProcessingState &state, |
| 688 | QualType declSpecType) { |
| 689 | Declarator &declarator = state.getDeclarator(); |
| 690 | |
| 691 | |
| 692 | |
| 693 | if (declarator.isFunctionDeclarator()) { |
| 694 | |
| 695 | declarator.getFunctionTypeInfo().hasPrototype = true; |
| 696 | return; |
| 697 | } |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | if (!declarator.getNumTypeObjects() && declSpecType->isFunctionType()) |
| 706 | return; |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | SourceLocation loc = declarator.getBeginLoc(); |
| 715 | |
| 716 | |
| 717 | SourceLocation NoLoc; |
| 718 | declarator.AddInnermostTypeInfo(DeclaratorChunk::getFunction( |
| 719 | , |
| 720 | , |
| 721 | NoLoc, |
| 722 | , |
| 723 | , |
| 724 | NoLoc, |
| 725 | NoLoc, |
| 726 | , |
| 727 | NoLoc, |
| 728 | NoLoc, EST_None, |
| 729 | SourceRange(), |
| 730 | , |
| 731 | , |
| 732 | , |
| 733 | , |
| 734 | , |
| 735 | None, loc, loc, declarator)); |
| 736 | |
| 737 | |
| 738 | |
| 739 | assert(state.getCurrentChunkIndex() == declarator.getNumTypeObjects() - 1); |
| 740 | state.setCurrentChunkIndex(declarator.getNumTypeObjects()); |
| 741 | } |
| 742 | |
| 743 | static void diagnoseAndRemoveTypeQualifiers(Sema &S, const DeclSpec &DS, |
| 744 | unsigned &TypeQuals, |
| 745 | QualType TypeSoFar, |
| 746 | unsigned RemoveTQs, |
| 747 | unsigned DiagID) { |
| 748 | |
| 749 | |
| 750 | typedef std::pair<DeclSpec::TQ, SourceLocation> QualLoc; |
| 751 | for (QualLoc Qual : {QualLoc(DeclSpec::TQ_const, DS.getConstSpecLoc()), |
| 752 | QualLoc(DeclSpec::TQ_restrict, DS.getRestrictSpecLoc()), |
| 753 | QualLoc(DeclSpec::TQ_volatile, DS.getVolatileSpecLoc()), |
| 754 | QualLoc(DeclSpec::TQ_atomic, DS.getAtomicSpecLoc())}) { |
| 755 | if (!(RemoveTQs & Qual.first)) |
| 756 | continue; |
| 757 | |
| 758 | if (!S.inTemplateInstantiation()) { |
| 759 | if (TypeQuals & Qual.first) |
| 760 | S.Diag(Qual.second, DiagID) |
| 761 | << DeclSpec::getSpecifierName(Qual.first) << TypeSoFar |
| 762 | << FixItHint::CreateRemoval(Qual.second); |
| 763 | } |
| 764 | |
| 765 | TypeQuals &= ~Qual.first; |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | |
| 770 | |
| 771 | static bool checkOmittedBlockReturnType(Sema &S, Declarator &declarator, |
| 772 | QualType Result) { |
| 773 | if (!isOmittedBlockReturnType(declarator)) |
| 774 | return false; |
| 775 | |
| 776 | |
| 777 | SmallVector<ParsedAttr *, 2> ToBeRemoved; |
| 778 | for (ParsedAttr &AL : declarator.getMutableDeclSpec().getAttributes()) { |
| 779 | if (AL.isInvalid() || !AL.isTypeAttr()) |
| 780 | continue; |
| 781 | S.Diag(AL.getLoc(), |
| 782 | diag::warn_block_literal_attributes_on_omitted_return_type) |
| 783 | << AL.getName(); |
| 784 | ToBeRemoved.push_back(&AL); |
| 785 | } |
| 786 | |
| 787 | for (ParsedAttr *AL : ToBeRemoved) |
| 788 | declarator.getMutableDeclSpec().getAttributes().remove(AL); |
| 789 | |
| 790 | |
| 791 | const DeclSpec &DS = declarator.getDeclSpec(); |
| 792 | unsigned TypeQuals = DS.getTypeQualifiers(); |
| 793 | diagnoseAndRemoveTypeQualifiers(S, DS, TypeQuals, Result, (unsigned)-1, |
| 794 | diag::warn_block_literal_qualifiers_on_omitted_return_type); |
| 795 | declarator.getMutableDeclSpec().ClearTypeQualifiers(); |
| 796 | |
| 797 | return true; |
| 798 | } |
| 799 | |
| 800 | |
| 801 | static QualType applyObjCTypeArgs(Sema &S, SourceLocation loc, QualType type, |
| 802 | ArrayRef<TypeSourceInfo *> typeArgs, |
| 803 | SourceRange typeArgsRange, |
| 804 | bool failOnError = false) { |
| 805 | |
| 806 | const auto *objcObjectType = type->getAs<ObjCObjectType>(); |
| 807 | if (!objcObjectType || !objcObjectType->getInterface()) { |
| 808 | S.Diag(loc, diag::err_objc_type_args_non_class) |
| 809 | << type |
| 810 | << typeArgsRange; |
| 811 | |
| 812 | if (failOnError) |
| 813 | return QualType(); |
| 814 | return type; |
| 815 | } |
| 816 | |
| 817 | |
| 818 | ObjCInterfaceDecl *objcClass = objcObjectType->getInterface(); |
| 819 | ObjCTypeParamList *typeParams = objcClass->getTypeParamList(); |
| 820 | if (!typeParams) { |
| 821 | S.Diag(loc, diag::err_objc_type_args_non_parameterized_class) |
| 822 | << objcClass->getDeclName() |
| 823 | << FixItHint::CreateRemoval(typeArgsRange); |
| 824 | |
| 825 | if (failOnError) |
| 826 | return QualType(); |
| 827 | |
| 828 | return type; |
| 829 | } |
| 830 | |
| 831 | |
| 832 | if (objcObjectType->isSpecialized()) { |
| 833 | S.Diag(loc, diag::err_objc_type_args_specialized_class) |
| 834 | << type |
| 835 | << FixItHint::CreateRemoval(typeArgsRange); |
| 836 | |
| 837 | if (failOnError) |
| 838 | return QualType(); |
| 839 | |
| 840 | return type; |
| 841 | } |
| 842 | |
| 843 | |
| 844 | SmallVector<QualType, 4> finalTypeArgs; |
| 845 | unsigned numTypeParams = typeParams->size(); |
| 846 | bool anyPackExpansions = false; |
| 847 | for (unsigned i = 0, n = typeArgs.size(); i != n; ++i) { |
| 848 | TypeSourceInfo *typeArgInfo = typeArgs[i]; |
| 849 | QualType typeArg = typeArgInfo->getType(); |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | if (TypeLoc qual = typeArgInfo->getTypeLoc().findExplicitQualifierLoc()) { |
| 855 | bool diagnosed = false; |
| 856 | SourceRange rangeToRemove; |
| 857 | if (auto attr = qual.getAs<AttributedTypeLoc>()) { |
| 858 | rangeToRemove = attr.getLocalSourceRange(); |
| 859 | if (attr.getTypePtr()->getImmediateNullability()) { |
| 860 | typeArg = attr.getTypePtr()->getModifiedType(); |
| 861 | S.Diag(attr.getBeginLoc(), |
| 862 | diag::err_objc_type_arg_explicit_nullability) |
| 863 | << typeArg << FixItHint::CreateRemoval(rangeToRemove); |
| 864 | diagnosed = true; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | if (!diagnosed) { |
| 869 | S.Diag(qual.getBeginLoc(), diag::err_objc_type_arg_qualified) |
| 870 | << typeArg << typeArg.getQualifiers().getAsString() |
| 871 | << FixItHint::CreateRemoval(rangeToRemove); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | |
| 876 | typeArg = typeArg.getUnqualifiedType(); |
| 877 | |
| 878 | finalTypeArgs.push_back(typeArg); |
| 879 | |
| 880 | if (typeArg->getAs<PackExpansionType>()) |
| 881 | anyPackExpansions = true; |
| 882 | |
| 883 | |
| 884 | ObjCTypeParamDecl *typeParam = nullptr; |
| 885 | if (!anyPackExpansions) { |
| 886 | if (i < numTypeParams) { |
| 887 | typeParam = typeParams->begin()[i]; |
| 888 | } else { |
| 889 | |
| 890 | S.Diag(loc, diag::err_objc_type_args_wrong_arity) |
| 891 | << false |
| 892 | << objcClass->getDeclName() |
| 893 | << (unsigned)typeArgs.size() |
| 894 | << numTypeParams; |
| 895 | S.Diag(objcClass->getLocation(), diag::note_previous_decl) |
| 896 | << objcClass; |
| 897 | |
| 898 | if (failOnError) |
| 899 | return QualType(); |
| 900 | |
| 901 | return type; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | |
| 906 | if (const auto *typeArgObjC = typeArg->getAs<ObjCObjectPointerType>()) { |
| 907 | |
| 908 | |
| 909 | |
| 910 | if (!typeParam) { |
| 911 | (0) . __assert_fail ("anyPackExpansions && \"Too many arguments?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 911, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(anyPackExpansions && "Too many arguments?"); |
| 912 | continue; |
| 913 | } |
| 914 | |
| 915 | |
| 916 | QualType bound = typeParam->getUnderlyingType(); |
| 917 | const auto *boundObjC = bound->getAs<ObjCObjectPointerType>(); |
| 918 | |
| 919 | |
| 920 | if (typeArgObjC->isObjCIdType()) { |
| 921 | |
| 922 | |
| 923 | if (boundObjC->isObjCIdType()) |
| 924 | continue; |
| 925 | } else if (S.Context.canAssignObjCInterfaces(boundObjC, typeArgObjC)) { |
| 926 | |
| 927 | continue; |
| 928 | } |
| 929 | |
| 930 | |
| 931 | S.Diag(typeArgInfo->getTypeLoc().getBeginLoc(), |
| 932 | diag::err_objc_type_arg_does_not_match_bound) |
| 933 | << typeArg << bound << typeParam->getDeclName(); |
| 934 | S.Diag(typeParam->getLocation(), diag::note_objc_type_param_here) |
| 935 | << typeParam->getDeclName(); |
| 936 | |
| 937 | if (failOnError) |
| 938 | return QualType(); |
| 939 | |
| 940 | return type; |
| 941 | } |
| 942 | |
| 943 | |
| 944 | if (typeArg->isBlockPointerType()) { |
| 945 | |
| 946 | |
| 947 | |
| 948 | if (!typeParam) { |
| 949 | (0) . __assert_fail ("anyPackExpansions && \"Too many arguments?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 949, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(anyPackExpansions && "Too many arguments?"); |
| 950 | continue; |
| 951 | } |
| 952 | |
| 953 | |
| 954 | QualType bound = typeParam->getUnderlyingType(); |
| 955 | if (bound->isBlockCompatibleObjCPointerType(S.Context)) |
| 956 | continue; |
| 957 | |
| 958 | |
| 959 | S.Diag(typeArgInfo->getTypeLoc().getBeginLoc(), |
| 960 | diag::err_objc_type_arg_does_not_match_bound) |
| 961 | << typeArg << bound << typeParam->getDeclName(); |
| 962 | S.Diag(typeParam->getLocation(), diag::note_objc_type_param_here) |
| 963 | << typeParam->getDeclName(); |
| 964 | |
| 965 | if (failOnError) |
| 966 | return QualType(); |
| 967 | |
| 968 | return type; |
| 969 | } |
| 970 | |
| 971 | |
| 972 | if (typeArg->isDependentType()) { |
| 973 | continue; |
| 974 | } |
| 975 | |
| 976 | |
| 977 | S.Diag(typeArgInfo->getTypeLoc().getBeginLoc(), |
| 978 | diag::err_objc_type_arg_not_id_compatible) |
| 979 | << typeArg << typeArgInfo->getTypeLoc().getSourceRange(); |
| 980 | |
| 981 | if (failOnError) |
| 982 | return QualType(); |
| 983 | |
| 984 | return type; |
| 985 | } |
| 986 | |
| 987 | |
| 988 | if (!anyPackExpansions && finalTypeArgs.size() != numTypeParams) { |
| 989 | S.Diag(loc, diag::err_objc_type_args_wrong_arity) |
| 990 | << (typeArgs.size() < typeParams->size()) |
| 991 | << objcClass->getDeclName() |
| 992 | << (unsigned)finalTypeArgs.size() |
| 993 | << (unsigned)numTypeParams; |
| 994 | S.Diag(objcClass->getLocation(), diag::note_previous_decl) |
| 995 | << objcClass; |
| 996 | |
| 997 | if (failOnError) |
| 998 | return QualType(); |
| 999 | |
| 1000 | return type; |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | return S.Context.getObjCObjectType(type, finalTypeArgs, { }, false); |
| 1005 | } |
| 1006 | |
| 1007 | QualType Sema::BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
| 1008 | SourceLocation ProtocolLAngleLoc, |
| 1009 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 1010 | ArrayRef<SourceLocation> ProtocolLocs, |
| 1011 | SourceLocation ProtocolRAngleLoc, |
| 1012 | bool FailOnError) { |
| 1013 | QualType Result = QualType(Decl->getTypeForDecl(), 0); |
| 1014 | if (!Protocols.empty()) { |
| 1015 | bool HasError; |
| 1016 | Result = Context.applyObjCProtocolQualifiers(Result, Protocols, |
| 1017 | HasError); |
| 1018 | if (HasError) { |
| 1019 | Diag(SourceLocation(), diag::err_invalid_protocol_qualifiers) |
| 1020 | << SourceRange(ProtocolLAngleLoc, ProtocolRAngleLoc); |
| 1021 | if (FailOnError) Result = QualType(); |
| 1022 | } |
| 1023 | if (FailOnError && Result.isNull()) |
| 1024 | return QualType(); |
| 1025 | } |
| 1026 | |
| 1027 | return Result; |
| 1028 | } |
| 1029 | |
| 1030 | QualType Sema::BuildObjCObjectType(QualType BaseType, |
| 1031 | SourceLocation Loc, |
| 1032 | SourceLocation TypeArgsLAngleLoc, |
| 1033 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 1034 | SourceLocation TypeArgsRAngleLoc, |
| 1035 | SourceLocation ProtocolLAngleLoc, |
| 1036 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 1037 | ArrayRef<SourceLocation> ProtocolLocs, |
| 1038 | SourceLocation ProtocolRAngleLoc, |
| 1039 | bool FailOnError) { |
| 1040 | QualType Result = BaseType; |
| 1041 | if (!TypeArgs.empty()) { |
| 1042 | Result = applyObjCTypeArgs(*this, Loc, Result, TypeArgs, |
| 1043 | SourceRange(TypeArgsLAngleLoc, |
| 1044 | TypeArgsRAngleLoc), |
| 1045 | FailOnError); |
| 1046 | if (FailOnError && Result.isNull()) |
| 1047 | return QualType(); |
| 1048 | } |
| 1049 | |
| 1050 | if (!Protocols.empty()) { |
| 1051 | bool HasError; |
| 1052 | Result = Context.applyObjCProtocolQualifiers(Result, Protocols, |
| 1053 | HasError); |
| 1054 | if (HasError) { |
| 1055 | Diag(Loc, diag::err_invalid_protocol_qualifiers) |
| 1056 | << SourceRange(ProtocolLAngleLoc, ProtocolRAngleLoc); |
| 1057 | if (FailOnError) Result = QualType(); |
| 1058 | } |
| 1059 | if (FailOnError && Result.isNull()) |
| 1060 | return QualType(); |
| 1061 | } |
| 1062 | |
| 1063 | return Result; |
| 1064 | } |
| 1065 | |
| 1066 | TypeResult Sema::actOnObjCProtocolQualifierType( |
| 1067 | SourceLocation lAngleLoc, |
| 1068 | ArrayRef<Decl *> protocols, |
| 1069 | ArrayRef<SourceLocation> protocolLocs, |
| 1070 | SourceLocation rAngleLoc) { |
| 1071 | |
| 1072 | QualType Result = Context.getObjCObjectType( |
| 1073 | Context.ObjCBuiltinIdTy, { }, |
| 1074 | llvm::makeArrayRef( |
| 1075 | (ObjCProtocolDecl * const *)protocols.data(), |
| 1076 | protocols.size()), |
| 1077 | false); |
| 1078 | Result = Context.getObjCObjectPointerType(Result); |
| 1079 | |
| 1080 | TypeSourceInfo *ResultTInfo = Context.CreateTypeSourceInfo(Result); |
| 1081 | TypeLoc ResultTL = ResultTInfo->getTypeLoc(); |
| 1082 | |
| 1083 | auto ObjCObjectPointerTL = ResultTL.castAs<ObjCObjectPointerTypeLoc>(); |
| 1084 | ObjCObjectPointerTL.setStarLoc(SourceLocation()); |
| 1085 | |
| 1086 | auto ObjCObjectTL = ObjCObjectPointerTL.getPointeeLoc() |
| 1087 | .castAs<ObjCObjectTypeLoc>(); |
| 1088 | ObjCObjectTL.setHasBaseTypeAsWritten(false); |
| 1089 | ObjCObjectTL.getBaseLoc().initialize(Context, SourceLocation()); |
| 1090 | |
| 1091 | |
| 1092 | ObjCObjectTL.setTypeArgsLAngleLoc(SourceLocation()); |
| 1093 | ObjCObjectTL.setTypeArgsRAngleLoc(SourceLocation()); |
| 1094 | |
| 1095 | |
| 1096 | ObjCObjectTL.setProtocolLAngleLoc(lAngleLoc); |
| 1097 | ObjCObjectTL.setProtocolRAngleLoc(rAngleLoc); |
| 1098 | for (unsigned i = 0, n = protocols.size(); i != n; ++i) |
| 1099 | ObjCObjectTL.setProtocolLoc(i, protocolLocs[i]); |
| 1100 | |
| 1101 | |
| 1102 | return CreateParsedType(Result, ResultTInfo); |
| 1103 | } |
| 1104 | |
| 1105 | TypeResult Sema::actOnObjCTypeArgsAndProtocolQualifiers( |
| 1106 | Scope *S, |
| 1107 | SourceLocation Loc, |
| 1108 | ParsedType BaseType, |
| 1109 | SourceLocation TypeArgsLAngleLoc, |
| 1110 | ArrayRef<ParsedType> TypeArgs, |
| 1111 | SourceLocation TypeArgsRAngleLoc, |
| 1112 | SourceLocation ProtocolLAngleLoc, |
| 1113 | ArrayRef<Decl *> Protocols, |
| 1114 | ArrayRef<SourceLocation> ProtocolLocs, |
| 1115 | SourceLocation ProtocolRAngleLoc) { |
| 1116 | TypeSourceInfo *BaseTypeInfo = nullptr; |
| 1117 | QualType T = GetTypeFromParser(BaseType, &BaseTypeInfo); |
| 1118 | if (T.isNull()) |
| 1119 | return true; |
| 1120 | |
| 1121 | |
| 1122 | if (!BaseTypeInfo) |
| 1123 | BaseTypeInfo = Context.getTrivialTypeSourceInfo(T, Loc); |
| 1124 | |
| 1125 | |
| 1126 | SmallVector<TypeSourceInfo *, 4> ActualTypeArgInfos; |
| 1127 | for (unsigned i = 0, n = TypeArgs.size(); i != n; ++i) { |
| 1128 | TypeSourceInfo *TypeArgInfo = nullptr; |
| 1129 | QualType TypeArg = GetTypeFromParser(TypeArgs[i], &TypeArgInfo); |
| 1130 | if (TypeArg.isNull()) { |
| 1131 | ActualTypeArgInfos.clear(); |
| 1132 | break; |
| 1133 | } |
| 1134 | |
| 1135 | (0) . __assert_fail ("TypeArgInfo && \"No type source info?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1135, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(TypeArgInfo && "No type source info?"); |
| 1136 | ActualTypeArgInfos.push_back(TypeArgInfo); |
| 1137 | } |
| 1138 | |
| 1139 | |
| 1140 | QualType Result = BuildObjCObjectType( |
| 1141 | T, BaseTypeInfo->getTypeLoc().getSourceRange().getBegin(), |
| 1142 | TypeArgsLAngleLoc, ActualTypeArgInfos, TypeArgsRAngleLoc, |
| 1143 | ProtocolLAngleLoc, |
| 1144 | llvm::makeArrayRef((ObjCProtocolDecl * const *)Protocols.data(), |
| 1145 | Protocols.size()), |
| 1146 | ProtocolLocs, ProtocolRAngleLoc, |
| 1147 | ); |
| 1148 | |
| 1149 | if (Result == T) |
| 1150 | return BaseType; |
| 1151 | |
| 1152 | |
| 1153 | TypeSourceInfo *ResultTInfo = Context.CreateTypeSourceInfo(Result); |
| 1154 | TypeLoc ResultTL = ResultTInfo->getTypeLoc(); |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | if (auto ObjCObjectPointerTL = ResultTL.getAs<ObjCObjectPointerTypeLoc>()) { |
| 1159 | |
| 1160 | ObjCObjectPointerTL.setStarLoc(SourceLocation()); |
| 1161 | ResultTL = ObjCObjectPointerTL.getPointeeLoc(); |
| 1162 | } |
| 1163 | |
| 1164 | if (auto OTPTL = ResultTL.getAs<ObjCTypeParamTypeLoc>()) { |
| 1165 | |
| 1166 | if (OTPTL.getNumProtocols() > 0) { |
| 1167 | assert(OTPTL.getNumProtocols() == Protocols.size()); |
| 1168 | OTPTL.setProtocolLAngleLoc(ProtocolLAngleLoc); |
| 1169 | OTPTL.setProtocolRAngleLoc(ProtocolRAngleLoc); |
| 1170 | for (unsigned i = 0, n = Protocols.size(); i != n; ++i) |
| 1171 | OTPTL.setProtocolLoc(i, ProtocolLocs[i]); |
| 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | return CreateParsedType(Result, ResultTInfo); |
| 1176 | } |
| 1177 | |
| 1178 | auto ObjCObjectTL = ResultTL.castAs<ObjCObjectTypeLoc>(); |
| 1179 | |
| 1180 | |
| 1181 | if (ObjCObjectTL.getNumTypeArgs() > 0) { |
| 1182 | assert(ObjCObjectTL.getNumTypeArgs() == ActualTypeArgInfos.size()); |
| 1183 | ObjCObjectTL.setTypeArgsLAngleLoc(TypeArgsLAngleLoc); |
| 1184 | ObjCObjectTL.setTypeArgsRAngleLoc(TypeArgsRAngleLoc); |
| 1185 | for (unsigned i = 0, n = ActualTypeArgInfos.size(); i != n; ++i) |
| 1186 | ObjCObjectTL.setTypeArgTInfo(i, ActualTypeArgInfos[i]); |
| 1187 | } else { |
| 1188 | ObjCObjectTL.setTypeArgsLAngleLoc(SourceLocation()); |
| 1189 | ObjCObjectTL.setTypeArgsRAngleLoc(SourceLocation()); |
| 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | if (ObjCObjectTL.getNumProtocols() > 0) { |
| 1194 | assert(ObjCObjectTL.getNumProtocols() == Protocols.size()); |
| 1195 | ObjCObjectTL.setProtocolLAngleLoc(ProtocolLAngleLoc); |
| 1196 | ObjCObjectTL.setProtocolRAngleLoc(ProtocolRAngleLoc); |
| 1197 | for (unsigned i = 0, n = Protocols.size(); i != n; ++i) |
| 1198 | ObjCObjectTL.setProtocolLoc(i, ProtocolLocs[i]); |
| 1199 | } else { |
| 1200 | ObjCObjectTL.setProtocolLAngleLoc(SourceLocation()); |
| 1201 | ObjCObjectTL.setProtocolRAngleLoc(SourceLocation()); |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | ObjCObjectTL.setHasBaseTypeAsWritten(true); |
| 1206 | if (ObjCObjectTL.getType() == T) |
| 1207 | ObjCObjectTL.getBaseLoc().initializeFullCopy(BaseTypeInfo->getTypeLoc()); |
| 1208 | else |
| 1209 | ObjCObjectTL.getBaseLoc().initialize(Context, Loc); |
| 1210 | |
| 1211 | |
| 1212 | return CreateParsedType(Result, ResultTInfo); |
| 1213 | } |
| 1214 | |
| 1215 | static OpenCLAccessAttr::Spelling |
| 1216 | getImageAccess(const ParsedAttributesView &Attrs) { |
| 1217 | for (const ParsedAttr &AL : Attrs) |
| 1218 | if (AL.getKind() == ParsedAttr::AT_OpenCLAccess) |
| 1219 | return static_cast<OpenCLAccessAttr::Spelling>(AL.getSemanticSpelling()); |
| 1220 | return OpenCLAccessAttr::Keyword_read_only; |
| 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | static QualType ConvertDeclSpecToType(TypeProcessingState &state) { |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | Sema &S = state.getSema(); |
| 1234 | Declarator &declarator = state.getDeclarator(); |
| 1235 | DeclSpec &DS = declarator.getMutableDeclSpec(); |
| 1236 | SourceLocation DeclLoc = declarator.getIdentifierLoc(); |
| 1237 | if (DeclLoc.isInvalid()) |
| 1238 | DeclLoc = DS.getBeginLoc(); |
| 1239 | |
| 1240 | ASTContext &Context = S.Context; |
| 1241 | |
| 1242 | QualType Result; |
| 1243 | switch (DS.getTypeSpecType()) { |
| 1244 | case DeclSpec::TST_void: |
| 1245 | Result = Context.VoidTy; |
| 1246 | break; |
| 1247 | case DeclSpec::TST_char: |
| 1248 | if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified) |
| 1249 | Result = Context.CharTy; |
| 1250 | else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) |
| 1251 | Result = Context.SignedCharTy; |
| 1252 | else { |
| 1253 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unsigned && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1254, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned && |
| 1254 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unsigned && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1254, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unknown TSS value"); |
| 1255 | Result = Context.UnsignedCharTy; |
| 1256 | } |
| 1257 | break; |
| 1258 | case DeclSpec::TST_wchar: |
| 1259 | if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified) |
| 1260 | Result = Context.WCharTy; |
| 1261 | else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) { |
| 1262 | S.Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec) |
| 1263 | << DS.getSpecifierName(DS.getTypeSpecType(), |
| 1264 | Context.getPrintingPolicy()); |
| 1265 | Result = Context.getSignedWCharType(); |
| 1266 | } else { |
| 1267 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unsigned && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1268, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned && |
| 1268 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unsigned && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1268, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unknown TSS value"); |
| 1269 | S.Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec) |
| 1270 | << DS.getSpecifierName(DS.getTypeSpecType(), |
| 1271 | Context.getPrintingPolicy()); |
| 1272 | Result = Context.getUnsignedWCharType(); |
| 1273 | } |
| 1274 | break; |
| 1275 | case DeclSpec::TST_char8: |
| 1276 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unspecified && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1277, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified && |
| 1277 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unspecified && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1277, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unknown TSS value"); |
| 1278 | Result = Context.Char8Ty; |
| 1279 | break; |
| 1280 | case DeclSpec::TST_char16: |
| 1281 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unspecified && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1282, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified && |
| 1282 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unspecified && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1282, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unknown TSS value"); |
| 1283 | Result = Context.Char16Ty; |
| 1284 | break; |
| 1285 | case DeclSpec::TST_char32: |
| 1286 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unspecified && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1287, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DS.getTypeSpecSign() == DeclSpec::TSS_unspecified && |
| 1287 | (0) . __assert_fail ("DS.getTypeSpecSign() == DeclSpec..TSS_unspecified && \"Unknown TSS value\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1287, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unknown TSS value"); |
| 1288 | Result = Context.Char32Ty; |
| 1289 | break; |
| 1290 | case DeclSpec::TST_unspecified: |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | if (S.getLangOpts().CPlusPlus14 && |
| 1296 | declarator.getContext() == DeclaratorContext::LambdaExprContext) { |
| 1297 | |
| 1298 | Result = Context.getAutoDeductType(); |
| 1299 | break; |
| 1300 | } else if (declarator.getContext() == |
| 1301 | DeclaratorContext::LambdaExprContext || |
| 1302 | checkOmittedBlockReturnType(S, declarator, |
| 1303 | Context.DependentTy)) { |
| 1304 | Result = Context.DependentTy; |
| 1305 | break; |
| 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | if (S.getLangOpts().ImplicitInt) { |
| 1316 | |
| 1317 | |
| 1318 | if (DS.isEmpty()) { |
| 1319 | S.Diag(DeclLoc, diag::ext_missing_declspec) |
| 1320 | << DS.getSourceRange() |
| 1321 | << FixItHint::CreateInsertion(DS.getBeginLoc(), "int"); |
| 1322 | } |
| 1323 | } else if (!DS.hasTypeSpecifier()) { |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | if (S.getLangOpts().CPlusPlus) { |
| 1329 | S.Diag(DeclLoc, diag::err_missing_type_specifier) |
| 1330 | << DS.getSourceRange(); |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | declarator.setInvalidType(true); |
| 1336 | } else if (S.getLangOpts().OpenCLVersion >= 200 && DS.isTypeSpecPipe()){ |
| 1337 | S.Diag(DeclLoc, diag::err_missing_actual_pipe_type) |
| 1338 | << DS.getSourceRange(); |
| 1339 | declarator.setInvalidType(true); |
| 1340 | } else { |
| 1341 | S.Diag(DeclLoc, diag::ext_missing_type_specifier) |
| 1342 | << DS.getSourceRange(); |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | LLVM_FALLTHROUGH; |
| 1347 | case DeclSpec::TST_int: { |
| 1348 | if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) { |
| 1349 | switch (DS.getTypeSpecWidth()) { |
| 1350 | case DeclSpec::TSW_unspecified: Result = Context.IntTy; break; |
| 1351 | case DeclSpec::TSW_short: Result = Context.ShortTy; break; |
| 1352 | case DeclSpec::TSW_long: Result = Context.LongTy; break; |
| 1353 | case DeclSpec::TSW_longlong: |
| 1354 | Result = Context.LongLongTy; |
| 1355 | |
| 1356 | |
| 1357 | if (!S.getLangOpts().C99) { |
| 1358 | if (S.getLangOpts().CPlusPlus) |
| 1359 | S.Diag(DS.getTypeSpecWidthLoc(), |
| 1360 | S.getLangOpts().CPlusPlus11 ? |
| 1361 | diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong); |
| 1362 | else |
| 1363 | S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_c99_longlong); |
| 1364 | } |
| 1365 | break; |
| 1366 | } |
| 1367 | } else { |
| 1368 | switch (DS.getTypeSpecWidth()) { |
| 1369 | case DeclSpec::TSW_unspecified: Result = Context.UnsignedIntTy; break; |
| 1370 | case DeclSpec::TSW_short: Result = Context.UnsignedShortTy; break; |
| 1371 | case DeclSpec::TSW_long: Result = Context.UnsignedLongTy; break; |
| 1372 | case DeclSpec::TSW_longlong: |
| 1373 | Result = Context.UnsignedLongLongTy; |
| 1374 | |
| 1375 | |
| 1376 | if (!S.getLangOpts().C99) { |
| 1377 | if (S.getLangOpts().CPlusPlus) |
| 1378 | S.Diag(DS.getTypeSpecWidthLoc(), |
| 1379 | S.getLangOpts().CPlusPlus11 ? |
| 1380 | diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong); |
| 1381 | else |
| 1382 | S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_c99_longlong); |
| 1383 | } |
| 1384 | break; |
| 1385 | } |
| 1386 | } |
| 1387 | break; |
| 1388 | } |
| 1389 | case DeclSpec::TST_accum: { |
| 1390 | switch (DS.getTypeSpecWidth()) { |
| 1391 | case DeclSpec::TSW_short: |
| 1392 | Result = Context.ShortAccumTy; |
| 1393 | break; |
| 1394 | case DeclSpec::TSW_unspecified: |
| 1395 | Result = Context.AccumTy; |
| 1396 | break; |
| 1397 | case DeclSpec::TSW_long: |
| 1398 | Result = Context.LongAccumTy; |
| 1399 | break; |
| 1400 | case DeclSpec::TSW_longlong: |
| 1401 | llvm_unreachable("Unable to specify long long as _Accum width"); |
| 1402 | } |
| 1403 | |
| 1404 | if (DS.getTypeSpecSign() == DeclSpec::TSS_unsigned) |
| 1405 | Result = Context.getCorrespondingUnsignedType(Result); |
| 1406 | |
| 1407 | if (DS.isTypeSpecSat()) |
| 1408 | Result = Context.getCorrespondingSaturatedType(Result); |
| 1409 | |
| 1410 | break; |
| 1411 | } |
| 1412 | case DeclSpec::TST_fract: { |
| 1413 | switch (DS.getTypeSpecWidth()) { |
| 1414 | case DeclSpec::TSW_short: |
| 1415 | Result = Context.ShortFractTy; |
| 1416 | break; |
| 1417 | case DeclSpec::TSW_unspecified: |
| 1418 | Result = Context.FractTy; |
| 1419 | break; |
| 1420 | case DeclSpec::TSW_long: |
| 1421 | Result = Context.LongFractTy; |
| 1422 | break; |
| 1423 | case DeclSpec::TSW_longlong: |
| 1424 | llvm_unreachable("Unable to specify long long as _Fract width"); |
| 1425 | } |
| 1426 | |
| 1427 | if (DS.getTypeSpecSign() == DeclSpec::TSS_unsigned) |
| 1428 | Result = Context.getCorrespondingUnsignedType(Result); |
| 1429 | |
| 1430 | if (DS.isTypeSpecSat()) |
| 1431 | Result = Context.getCorrespondingSaturatedType(Result); |
| 1432 | |
| 1433 | break; |
| 1434 | } |
| 1435 | case DeclSpec::TST_int128: |
| 1436 | if (!S.Context.getTargetInfo().hasInt128Type() && |
| 1437 | !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice)) |
| 1438 | S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) |
| 1439 | << "__int128"; |
| 1440 | if (DS.getTypeSpecSign() == DeclSpec::TSS_unsigned) |
| 1441 | Result = Context.UnsignedInt128Ty; |
| 1442 | else |
| 1443 | Result = Context.Int128Ty; |
| 1444 | break; |
| 1445 | case DeclSpec::TST_float16: |
| 1446 | |
| 1447 | |
| 1448 | |
| 1449 | if (!S.Context.getTargetInfo().hasFloat16Type() && !S.getLangOpts().CUDA && |
| 1450 | !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice)) |
| 1451 | S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) |
| 1452 | << "_Float16"; |
| 1453 | Result = Context.Float16Ty; |
| 1454 | break; |
| 1455 | case DeclSpec::TST_half: Result = Context.HalfTy; break; |
| 1456 | case DeclSpec::TST_float: Result = Context.FloatTy; break; |
| 1457 | case DeclSpec::TST_double: |
| 1458 | if (DS.getTypeSpecWidth() == DeclSpec::TSW_long) |
| 1459 | Result = Context.LongDoubleTy; |
| 1460 | else |
| 1461 | Result = Context.DoubleTy; |
| 1462 | break; |
| 1463 | case DeclSpec::TST_float128: |
| 1464 | if (!S.Context.getTargetInfo().hasFloat128Type() && |
| 1465 | !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice)) |
| 1466 | S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) |
| 1467 | << "__float128"; |
| 1468 | Result = Context.Float128Ty; |
| 1469 | break; |
| 1470 | case DeclSpec::TST_bool: Result = Context.BoolTy; break; |
| 1471 | break; |
| 1472 | case DeclSpec::TST_decimal32: |
| 1473 | case DeclSpec::TST_decimal64: |
| 1474 | case DeclSpec::TST_decimal128: |
| 1475 | S.Diag(DS.getTypeSpecTypeLoc(), diag::err_decimal_unsupported); |
| 1476 | Result = Context.IntTy; |
| 1477 | declarator.setInvalidType(true); |
| 1478 | break; |
| 1479 | case DeclSpec::TST_class: |
| 1480 | case DeclSpec::TST_enum: |
| 1481 | case DeclSpec::TST_union: |
| 1482 | case DeclSpec::TST_struct: |
| 1483 | case DeclSpec::TST_interface: { |
| 1484 | TagDecl *D = dyn_cast_or_null<TagDecl>(DS.getRepAsDecl()); |
| 1485 | if (!D) { |
| 1486 | |
| 1487 | Result = Context.IntTy; |
| 1488 | declarator.setInvalidType(true); |
| 1489 | break; |
| 1490 | } |
| 1491 | |
| 1492 | |
| 1493 | S.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeNameLoc()); |
| 1494 | |
| 1495 | (0) . __assert_fail ("DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 && \"No qualifiers on tag names!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1496, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && |
| 1496 | (0) . __assert_fail ("DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 && \"No qualifiers on tag names!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1496, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> DS.getTypeSpecSign() == 0 && "No qualifiers on tag names!"); |
| 1497 | |
| 1498 | |
| 1499 | Result = Context.getTypeDeclType(D); |
| 1500 | |
| 1501 | |
| 1502 | ElaboratedTypeKeyword Keyword |
| 1503 | = ElaboratedType::getKeywordForTypeSpec(DS.getTypeSpecType()); |
| 1504 | Result = S.getElaboratedType(Keyword, DS.getTypeSpecScope(), Result, |
| 1505 | DS.isTypeSpecOwned() ? D : nullptr); |
| 1506 | break; |
| 1507 | } |
| 1508 | case DeclSpec::TST_typename: { |
| 1509 | (0) . __assert_fail ("DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 && \"Can't handle qualifiers on typedef names yet!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1511, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && |
| 1510 | (0) . __assert_fail ("DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 && \"Can't handle qualifiers on typedef names yet!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1511, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> DS.getTypeSpecSign() == 0 && |
| 1511 | (0) . __assert_fail ("DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 && \"Can't handle qualifiers on typedef names yet!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1511, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Can't handle qualifiers on typedef names yet!"); |
| 1512 | Result = S.GetTypeFromParser(DS.getRepAsType()); |
| 1513 | if (Result.isNull()) { |
| 1514 | declarator.setInvalidType(true); |
| 1515 | } |
| 1516 | |
| 1517 | |
| 1518 | break; |
| 1519 | } |
| 1520 | case DeclSpec::TST_typeofType: |
| 1521 | |
| 1522 | Result = S.GetTypeFromParser(DS.getRepAsType()); |
| 1523 | (0) . __assert_fail ("!Result.isNull() && \"Didn't get a type for typeof?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1523, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Result.isNull() && "Didn't get a type for typeof?"); |
| 1524 | if (!Result->isDependentType()) |
| 1525 | if (const TagType *TT = Result->getAs<TagType>()) |
| 1526 | S.DiagnoseUseOfDecl(TT->getDecl(), DS.getTypeSpecTypeLoc()); |
| 1527 | |
| 1528 | Result = Context.getTypeOfType(Result); |
| 1529 | break; |
| 1530 | case DeclSpec::TST_typeofExpr: { |
| 1531 | Expr *E = DS.getRepAsExpr(); |
| 1532 | (0) . __assert_fail ("E && \"Didn't get an expression for typeof?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1532, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(E && "Didn't get an expression for typeof?"); |
| 1533 | |
| 1534 | Result = S.BuildTypeofExprType(E, DS.getTypeSpecTypeLoc()); |
| 1535 | if (Result.isNull()) { |
| 1536 | Result = Context.IntTy; |
| 1537 | declarator.setInvalidType(true); |
| 1538 | } |
| 1539 | break; |
| 1540 | } |
| 1541 | case DeclSpec::TST_decltype: { |
| 1542 | Expr *E = DS.getRepAsExpr(); |
| 1543 | (0) . __assert_fail ("E && \"Didn't get an expression for decltype?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1543, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(E && "Didn't get an expression for decltype?"); |
| 1544 | |
| 1545 | Result = S.BuildDecltypeType(E, DS.getTypeSpecTypeLoc()); |
| 1546 | if (Result.isNull()) { |
| 1547 | Result = Context.IntTy; |
| 1548 | declarator.setInvalidType(true); |
| 1549 | } |
| 1550 | break; |
| 1551 | } |
| 1552 | case DeclSpec::TST_underlyingType: |
| 1553 | Result = S.GetTypeFromParser(DS.getRepAsType()); |
| 1554 | (0) . __assert_fail ("!Result.isNull() && \"Didn't get a type for __underlying_type?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1554, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Result.isNull() && "Didn't get a type for __underlying_type?"); |
| 1555 | Result = S.BuildUnaryTransformType(Result, |
| 1556 | UnaryTransformType::EnumUnderlyingType, |
| 1557 | DS.getTypeSpecTypeLoc()); |
| 1558 | if (Result.isNull()) { |
| 1559 | Result = Context.IntTy; |
| 1560 | declarator.setInvalidType(true); |
| 1561 | } |
| 1562 | break; |
| 1563 | |
| 1564 | case DeclSpec::TST_auto: |
| 1565 | Result = Context.getAutoType(QualType(), AutoTypeKeyword::Auto, false); |
| 1566 | break; |
| 1567 | |
| 1568 | case DeclSpec::TST_auto_type: |
| 1569 | Result = Context.getAutoType(QualType(), AutoTypeKeyword::GNUAutoType, false); |
| 1570 | break; |
| 1571 | |
| 1572 | case DeclSpec::TST_decltype_auto: |
| 1573 | Result = Context.getAutoType(QualType(), AutoTypeKeyword::DecltypeAuto, |
| 1574 | false); |
| 1575 | break; |
| 1576 | |
| 1577 | case DeclSpec::TST_unknown_anytype: |
| 1578 | Result = Context.UnknownAnyTy; |
| 1579 | break; |
| 1580 | |
| 1581 | case DeclSpec::TST_atomic: |
| 1582 | Result = S.GetTypeFromParser(DS.getRepAsType()); |
| 1583 | (0) . __assert_fail ("!Result.isNull() && \"Didn't get a type for _Atomic?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1583, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Result.isNull() && "Didn't get a type for _Atomic?"); |
| 1584 | Result = S.BuildAtomicType(Result, DS.getTypeSpecTypeLoc()); |
| 1585 | if (Result.isNull()) { |
| 1586 | Result = Context.IntTy; |
| 1587 | declarator.setInvalidType(true); |
| 1588 | } |
| 1589 | break; |
| 1590 | |
| 1591 | #define GENERIC_IMAGE_TYPE(ImgType, Id) \ |
| 1592 | case DeclSpec::TST_##ImgType##_t: \ |
| 1593 | switch (getImageAccess(DS.getAttributes())) { \ |
| 1594 | case OpenCLAccessAttr::Keyword_write_only: \ |
| 1595 | Result = Context.Id##WOTy; \ |
| 1596 | break; \ |
| 1597 | case OpenCLAccessAttr::Keyword_read_write: \ |
| 1598 | Result = Context.Id##RWTy; \ |
| 1599 | break; \ |
| 1600 | case OpenCLAccessAttr::Keyword_read_only: \ |
| 1601 | Result = Context.Id##ROTy; \ |
| 1602 | break; \ |
| 1603 | } \ |
| 1604 | break; |
| 1605 | #include "clang/Basic/OpenCLImageTypes.def" |
| 1606 | |
| 1607 | case DeclSpec::TST_error: |
| 1608 | Result = Context.IntTy; |
| 1609 | declarator.setInvalidType(true); |
| 1610 | break; |
| 1611 | } |
| 1612 | |
| 1613 | if (S.getLangOpts().OpenCL && |
| 1614 | S.checkOpenCLDisabledTypeDeclSpec(DS, Result)) |
| 1615 | declarator.setInvalidType(true); |
| 1616 | |
| 1617 | bool IsFixedPointType = DS.getTypeSpecType() == DeclSpec::TST_accum || |
| 1618 | DS.getTypeSpecType() == DeclSpec::TST_fract; |
| 1619 | |
| 1620 | |
| 1621 | if (DS.isTypeSpecSat() && !IsFixedPointType) |
| 1622 | S.Diag(DS.getTypeSpecSatLoc(), diag::err_invalid_saturation_spec) |
| 1623 | << DS.getSpecifierName(DS.getTypeSpecType(), |
| 1624 | Context.getPrintingPolicy()); |
| 1625 | |
| 1626 | |
| 1627 | if (DS.getTypeSpecComplex() == DeclSpec::TSC_complex) { |
| 1628 | if (S.getLangOpts().Freestanding) |
| 1629 | S.Diag(DS.getTypeSpecComplexLoc(), diag::ext_freestanding_complex); |
| 1630 | Result = Context.getComplexType(Result); |
| 1631 | } else if (DS.isTypeAltiVecVector()) { |
| 1632 | unsigned typeSize = static_cast<unsigned>(Context.getTypeSize(Result)); |
| 1633 | (0) . __assert_fail ("typeSize > 0 && \"type size for vector must be greater than 0 bits\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1633, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(typeSize > 0 && "type size for vector must be greater than 0 bits"); |
| 1634 | VectorType::VectorKind VecKind = VectorType::AltiVecVector; |
| 1635 | if (DS.isTypeAltiVecPixel()) |
| 1636 | VecKind = VectorType::AltiVecPixel; |
| 1637 | else if (DS.isTypeAltiVecBool()) |
| 1638 | VecKind = VectorType::AltiVecBool; |
| 1639 | Result = Context.getVectorType(Result, 128/typeSize, VecKind); |
| 1640 | } |
| 1641 | |
| 1642 | |
| 1643 | if (DS.getTypeSpecComplex() == DeclSpec::TSC_imaginary) |
| 1644 | S.Diag(DS.getTypeSpecComplexLoc(), diag::err_imaginary_not_supported); |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | if (declarator.getContext() == DeclaratorContext::BlockLiteralContext) |
| 1649 | maybeSynthesizeBlockSignature(state, Result); |
| 1650 | |
| 1651 | |
| 1652 | |
| 1653 | |
| 1654 | |
| 1655 | if (!DS.isTypeSpecPipe()) |
| 1656 | processTypeAttrs(state, Result, TAL_DeclSpec, DS.getAttributes()); |
| 1657 | |
| 1658 | |
| 1659 | if (unsigned TypeQuals = DS.getTypeQualifiers()) { |
| 1660 | |
| 1661 | |
| 1662 | |
| 1663 | |
| 1664 | |
| 1665 | |
| 1666 | |
| 1667 | |
| 1668 | if (TypeQuals && Result->isFunctionType()) { |
| 1669 | diagnoseAndRemoveTypeQualifiers( |
| 1670 | S, DS, TypeQuals, Result, DeclSpec::TQ_const | DeclSpec::TQ_volatile, |
| 1671 | S.getLangOpts().CPlusPlus |
| 1672 | ? diag::warn_typecheck_function_qualifiers_ignored |
| 1673 | : diag::warn_typecheck_function_qualifiers_unspecified); |
| 1674 | |
| 1675 | |
| 1676 | } |
| 1677 | |
| 1678 | |
| 1679 | |
| 1680 | |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 | if (TypeQuals && Result->isReferenceType()) { |
| 1687 | diagnoseAndRemoveTypeQualifiers( |
| 1688 | S, DS, TypeQuals, Result, |
| 1689 | DeclSpec::TQ_const | DeclSpec::TQ_volatile | DeclSpec::TQ_atomic, |
| 1690 | diag::warn_typecheck_reference_qualifiers); |
| 1691 | } |
| 1692 | |
| 1693 | |
| 1694 | |
| 1695 | |
| 1696 | if (!S.getLangOpts().C99 && !S.getLangOpts().CPlusPlus |
| 1697 | && TypeQuals & Result.getCVRQualifiers()) { |
| 1698 | if (TypeQuals & DeclSpec::TQ_const && Result.isConstQualified()) { |
| 1699 | S.Diag(DS.getConstSpecLoc(), diag::ext_duplicate_declspec) |
| 1700 | << "const"; |
| 1701 | } |
| 1702 | |
| 1703 | if (TypeQuals & DeclSpec::TQ_volatile && Result.isVolatileQualified()) { |
| 1704 | S.Diag(DS.getVolatileSpecLoc(), diag::ext_duplicate_declspec) |
| 1705 | << "volatile"; |
| 1706 | } |
| 1707 | |
| 1708 | |
| 1709 | |
| 1710 | } |
| 1711 | |
| 1712 | QualType Qualified = S.BuildQualifiedType(Result, DeclLoc, TypeQuals, &DS); |
| 1713 | |
| 1714 | |
| 1715 | if (Qualified.isNull()) |
| 1716 | declarator.setInvalidType(true); |
| 1717 | else |
| 1718 | Result = Qualified; |
| 1719 | } |
| 1720 | |
| 1721 | (0) . __assert_fail ("!Result.isNull() && \"This function should not return a null type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1721, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Result.isNull() && "This function should not return a null type"); |
| 1722 | return Result; |
| 1723 | } |
| 1724 | |
| 1725 | static std::string getPrintableNameForEntity(DeclarationName Entity) { |
| 1726 | if (Entity) |
| 1727 | return Entity.getAsString(); |
| 1728 | |
| 1729 | return "type name"; |
| 1730 | } |
| 1731 | |
| 1732 | QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc, |
| 1733 | Qualifiers Qs, const DeclSpec *DS) { |
| 1734 | if (T.isNull()) |
| 1735 | return QualType(); |
| 1736 | |
| 1737 | |
| 1738 | if (T->isReferenceType()) { |
| 1739 | Qs.removeConst(); |
| 1740 | Qs.removeVolatile(); |
| 1741 | } |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 | if (Qs.hasRestrict()) { |
| 1746 | unsigned DiagID = 0; |
| 1747 | QualType ProblemTy; |
| 1748 | |
| 1749 | if (T->isAnyPointerType() || T->isReferenceType() || |
| 1750 | T->isMemberPointerType()) { |
| 1751 | QualType EltTy; |
| 1752 | if (T->isObjCObjectPointerType()) |
| 1753 | EltTy = T; |
| 1754 | else if (const MemberPointerType *PTy = T->getAs<MemberPointerType>()) |
| 1755 | EltTy = PTy->getPointeeType(); |
| 1756 | else |
| 1757 | EltTy = T->getPointeeType(); |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | if (!EltTy->isIncompleteOrObjectType()) { |
| 1762 | DiagID = diag::err_typecheck_invalid_restrict_invalid_pointee; |
| 1763 | ProblemTy = EltTy; |
| 1764 | } |
| 1765 | } else if (!T->isDependentType()) { |
| 1766 | DiagID = diag::err_typecheck_invalid_restrict_not_pointer; |
| 1767 | ProblemTy = T; |
| 1768 | } |
| 1769 | |
| 1770 | if (DiagID) { |
| 1771 | Diag(DS ? DS->getRestrictSpecLoc() : Loc, DiagID) << ProblemTy; |
| 1772 | Qs.removeRestrict(); |
| 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | return Context.getQualifiedType(T, Qs); |
| 1777 | } |
| 1778 | |
| 1779 | QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc, |
| 1780 | unsigned CVRAU, const DeclSpec *DS) { |
| 1781 | if (T.isNull()) |
| 1782 | return QualType(); |
| 1783 | |
| 1784 | |
| 1785 | if (T->isReferenceType()) |
| 1786 | CVRAU &= |
| 1787 | ~(DeclSpec::TQ_const | DeclSpec::TQ_volatile | DeclSpec::TQ_atomic); |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | unsigned CVR = CVRAU & ~(DeclSpec::TQ_atomic | DeclSpec::TQ_unaligned); |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | if (CVRAU & DeclSpec::TQ_atomic && !T->isAtomicType()) { |
| 1802 | |
| 1803 | |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | |
| 1808 | |
| 1809 | SplitQualType Split = T.getSplitUnqualifiedType(); |
| 1810 | T = BuildAtomicType(QualType(Split.Ty, 0), |
| 1811 | DS ? DS->getAtomicSpecLoc() : Loc); |
| 1812 | if (T.isNull()) |
| 1813 | return T; |
| 1814 | Split.Quals.addCVRQualifiers(CVR); |
| 1815 | return BuildQualifiedType(T, Loc, Split.Quals); |
| 1816 | } |
| 1817 | |
| 1818 | Qualifiers Q = Qualifiers::fromCVRMask(CVR); |
| 1819 | Q.setUnaligned(CVRAU & DeclSpec::TQ_unaligned); |
| 1820 | return BuildQualifiedType(T, Loc, Q, DS); |
| 1821 | } |
| 1822 | |
| 1823 | |
| 1824 | QualType Sema::BuildParenType(QualType T) { |
| 1825 | return Context.getParenType(T); |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | static QualType inferARCLifetimeForPointee(Sema &S, QualType type, |
| 1830 | SourceLocation loc, |
| 1831 | bool isReference) { |
| 1832 | |
| 1833 | if (!type->isObjCLifetimeType() || |
| 1834 | type.getObjCLifetime() != Qualifiers::OCL_None) |
| 1835 | return type; |
| 1836 | |
| 1837 | Qualifiers::ObjCLifetime implicitLifetime = Qualifiers::OCL_None; |
| 1838 | |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | |
| 1843 | if (type.isConstQualified()) { |
| 1844 | implicitLifetime = Qualifiers::OCL_ExplicitNone; |
| 1845 | |
| 1846 | |
| 1847 | |
| 1848 | |
| 1849 | } else if (type->isObjCARCImplicitlyUnretainedType()) { |
| 1850 | implicitLifetime = Qualifiers::OCL_ExplicitNone; |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | } else if (S.isUnevaluatedContext()) { |
| 1855 | return type; |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | } else { |
| 1861 | |
| 1862 | |
| 1863 | |
| 1864 | if (S.DelayedDiagnostics.shouldDelayDiagnostics()) { |
| 1865 | S.DelayedDiagnostics.add( |
| 1866 | sema::DelayedDiagnostic::makeForbiddenType(loc, |
| 1867 | diag::err_arc_indirect_no_ownership, type, isReference)); |
| 1868 | } else { |
| 1869 | S.Diag(loc, diag::err_arc_indirect_no_ownership) << type << isReference; |
| 1870 | } |
| 1871 | implicitLifetime = Qualifiers::OCL_Strong; |
| 1872 | } |
| 1873 | (0) . __assert_fail ("implicitLifetime && \"didn't infer any lifetime!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1873, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(implicitLifetime && "didn't infer any lifetime!"); |
| 1874 | |
| 1875 | Qualifiers qs; |
| 1876 | qs.addObjCLifetime(implicitLifetime); |
| 1877 | return S.Context.getQualifiedType(type, qs); |
| 1878 | } |
| 1879 | |
| 1880 | static std::string getFunctionQualifiersAsString(const FunctionProtoType *FnTy){ |
| 1881 | std::string Quals = FnTy->getMethodQuals().getAsString(); |
| 1882 | |
| 1883 | switch (FnTy->getRefQualifier()) { |
| 1884 | case RQ_None: |
| 1885 | break; |
| 1886 | |
| 1887 | case RQ_LValue: |
| 1888 | if (!Quals.empty()) |
| 1889 | Quals += ' '; |
| 1890 | Quals += '&'; |
| 1891 | break; |
| 1892 | |
| 1893 | case RQ_RValue: |
| 1894 | if (!Quals.empty()) |
| 1895 | Quals += ' '; |
| 1896 | Quals += "&&"; |
| 1897 | break; |
| 1898 | } |
| 1899 | |
| 1900 | return Quals; |
| 1901 | } |
| 1902 | |
| 1903 | namespace { |
| 1904 | |
| 1905 | |
| 1906 | |
| 1907 | |
| 1908 | |
| 1909 | |
| 1910 | |
| 1911 | |
| 1912 | |
| 1913 | |
| 1914 | enum QualifiedFunctionKind { QFK_BlockPointer, QFK_Pointer, QFK_Reference }; |
| 1915 | } |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | static bool checkQualifiedFunction(Sema &S, QualType T, SourceLocation Loc, |
| 1920 | QualifiedFunctionKind QFK) { |
| 1921 | |
| 1922 | const FunctionProtoType *FPT = T->getAs<FunctionProtoType>(); |
| 1923 | if (!FPT || (FPT->getMethodQuals().empty() && FPT->getRefQualifier() == RQ_None)) |
| 1924 | return false; |
| 1925 | |
| 1926 | S.Diag(Loc, diag::err_compound_qualified_function_type) |
| 1927 | << QFK << isa<FunctionType>(T.IgnoreParens()) << T |
| 1928 | << getFunctionQualifiersAsString(FPT); |
| 1929 | return true; |
| 1930 | } |
| 1931 | |
| 1932 | |
| 1933 | |
| 1934 | |
| 1935 | |
| 1936 | |
| 1937 | |
| 1938 | |
| 1939 | |
| 1940 | |
| 1941 | |
| 1942 | |
| 1943 | |
| 1944 | |
| 1945 | QualType Sema::BuildPointerType(QualType T, |
| 1946 | SourceLocation Loc, DeclarationName Entity) { |
| 1947 | if (T->isReferenceType()) { |
| 1948 | |
| 1949 | Diag(Loc, diag::err_illegal_decl_pointer_to_reference) |
| 1950 | << getPrintableNameForEntity(Entity) << T; |
| 1951 | return QualType(); |
| 1952 | } |
| 1953 | |
| 1954 | if (T->isFunctionType() && getLangOpts().OpenCL) { |
| 1955 | Diag(Loc, diag::err_opencl_function_pointer); |
| 1956 | return QualType(); |
| 1957 | } |
| 1958 | |
| 1959 | if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer)) |
| 1960 | return QualType(); |
| 1961 | |
| 1962 | (0) . __assert_fail ("!T->isObjCObjectType() && \"Should build ObjCObjectPointerType\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1962, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!T->isObjCObjectType() && "Should build ObjCObjectPointerType"); |
| 1963 | |
| 1964 | |
| 1965 | if (getLangOpts().ObjCAutoRefCount) |
| 1966 | T = inferARCLifetimeForPointee(*this, T, Loc, false); |
| 1967 | |
| 1968 | |
| 1969 | return Context.getPointerType(T); |
| 1970 | } |
| 1971 | |
| 1972 | |
| 1973 | |
| 1974 | |
| 1975 | |
| 1976 | |
| 1977 | |
| 1978 | |
| 1979 | |
| 1980 | |
| 1981 | |
| 1982 | |
| 1983 | |
| 1984 | |
| 1985 | QualType Sema::BuildReferenceType(QualType T, bool SpelledAsLValue, |
| 1986 | SourceLocation Loc, |
| 1987 | DeclarationName Entity) { |
| 1988 | (0) . __assert_fail ("Context.getCanonicalType(T) != Context.OverloadTy && \"Unresolved overloaded function type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1989, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Context.getCanonicalType(T) != Context.OverloadTy && |
| 1989 | (0) . __assert_fail ("Context.getCanonicalType(T) != Context.OverloadTy && \"Unresolved overloaded function type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 1989, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unresolved overloaded function type"); |
| 1990 | |
| 1991 | |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | |
| 1996 | |
| 1997 | bool LValueRef = SpelledAsLValue || T->getAs<LValueReferenceType>(); |
| 1998 | |
| 1999 | |
| 2000 | |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | |
| 2006 | |
| 2007 | |
| 2008 | |
| 2009 | |
| 2010 | |
| 2011 | |
| 2012 | |
| 2013 | |
| 2014 | |
| 2015 | |
| 2016 | if (T->isVoidType()) { |
| 2017 | Diag(Loc, diag::err_reference_to_void); |
| 2018 | return QualType(); |
| 2019 | } |
| 2020 | |
| 2021 | if (checkQualifiedFunction(*this, T, Loc, QFK_Reference)) |
| 2022 | return QualType(); |
| 2023 | |
| 2024 | |
| 2025 | if (getLangOpts().ObjCAutoRefCount) |
| 2026 | T = inferARCLifetimeForPointee(*this, T, Loc, true); |
| 2027 | |
| 2028 | |
| 2029 | if (LValueRef) |
| 2030 | return Context.getLValueReferenceType(T, SpelledAsLValue); |
| 2031 | return Context.getRValueReferenceType(T); |
| 2032 | } |
| 2033 | |
| 2034 | |
| 2035 | |
| 2036 | |
| 2037 | |
| 2038 | |
| 2039 | |
| 2040 | |
| 2041 | |
| 2042 | QualType Sema::BuildReadPipeType(QualType T, SourceLocation Loc) { |
| 2043 | return Context.getReadPipeType(T); |
| 2044 | } |
| 2045 | |
| 2046 | |
| 2047 | |
| 2048 | |
| 2049 | |
| 2050 | |
| 2051 | |
| 2052 | |
| 2053 | |
| 2054 | QualType Sema::BuildWritePipeType(QualType T, SourceLocation Loc) { |
| 2055 | return Context.getWritePipeType(T); |
| 2056 | } |
| 2057 | |
| 2058 | |
| 2059 | |
| 2060 | static bool isArraySizeVLA(Sema &S, Expr *ArraySize, llvm::APSInt &SizeVal) { |
| 2061 | |
| 2062 | |
| 2063 | class VLADiagnoser : public Sema::VerifyICEDiagnoser { |
| 2064 | public: |
| 2065 | VLADiagnoser() : Sema::VerifyICEDiagnoser(true) {} |
| 2066 | |
| 2067 | void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) override { |
| 2068 | } |
| 2069 | |
| 2070 | void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR) override { |
| 2071 | S.Diag(Loc, diag::ext_vla_folded_to_constant) << SR; |
| 2072 | } |
| 2073 | } Diagnoser; |
| 2074 | |
| 2075 | return S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser, |
| 2076 | S.LangOpts.GNUMode || |
| 2077 | S.LangOpts.OpenCL).isInvalid(); |
| 2078 | } |
| 2079 | |
| 2080 | |
| 2081 | |
| 2082 | |
| 2083 | |
| 2084 | |
| 2085 | |
| 2086 | |
| 2087 | |
| 2088 | |
| 2089 | |
| 2090 | |
| 2091 | |
| 2092 | |
| 2093 | |
| 2094 | |
| 2095 | QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, |
| 2096 | Expr *ArraySize, unsigned Quals, |
| 2097 | SourceRange Brackets, DeclarationName Entity) { |
| 2098 | |
| 2099 | SourceLocation Loc = Brackets.getBegin(); |
| 2100 | if (getLangOpts().CPlusPlus) { |
| 2101 | |
| 2102 | |
| 2103 | |
| 2104 | |
| 2105 | |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | |
| 2110 | |
| 2111 | |
| 2112 | if (T->isReferenceType()) { |
| 2113 | Diag(Loc, diag::err_illegal_decl_array_of_references) |
| 2114 | << getPrintableNameForEntity(Entity) << T; |
| 2115 | return QualType(); |
| 2116 | } |
| 2117 | |
| 2118 | if (T->isVoidType() || T->isIncompleteArrayType()) { |
| 2119 | Diag(Loc, diag::err_illegal_decl_array_incomplete_type) << T; |
| 2120 | return QualType(); |
| 2121 | } |
| 2122 | |
| 2123 | if (RequireNonAbstractType(Brackets.getBegin(), T, |
| 2124 | diag::err_array_of_abstract_type)) |
| 2125 | return QualType(); |
| 2126 | |
| 2127 | |
| 2128 | |
| 2129 | if (Context.getTargetInfo().getCXXABI().isMicrosoft()) |
| 2130 | if (const MemberPointerType *MPTy = T->getAs<MemberPointerType>()) |
| 2131 | if (!MPTy->getClass()->isDependentType()) |
| 2132 | (void)isCompleteType(Loc, T); |
| 2133 | |
| 2134 | } else { |
| 2135 | |
| 2136 | |
| 2137 | if (RequireCompleteType(Loc, T, |
| 2138 | diag::err_illegal_decl_array_incomplete_type)) |
| 2139 | return QualType(); |
| 2140 | } |
| 2141 | |
| 2142 | if (T->isFunctionType()) { |
| 2143 | Diag(Loc, diag::err_illegal_decl_array_of_functions) |
| 2144 | << getPrintableNameForEntity(Entity) << T; |
| 2145 | return QualType(); |
| 2146 | } |
| 2147 | |
| 2148 | if (const RecordType *EltTy = T->getAs<RecordType>()) { |
| 2149 | |
| 2150 | |
| 2151 | if (EltTy->getDecl()->hasFlexibleArrayMember()) |
| 2152 | Diag(Loc, diag::ext_flexible_array_in_array) << T; |
| 2153 | } else if (T->isObjCObjectType()) { |
| 2154 | Diag(Loc, diag::err_objc_array_of_interfaces) << T; |
| 2155 | return QualType(); |
| 2156 | } |
| 2157 | |
| 2158 | |
| 2159 | if (ArraySize && ArraySize->hasPlaceholderType()) { |
| 2160 | ExprResult Result = CheckPlaceholderExpr(ArraySize); |
| 2161 | if (Result.isInvalid()) return QualType(); |
| 2162 | ArraySize = Result.get(); |
| 2163 | } |
| 2164 | |
| 2165 | |
| 2166 | if (ArraySize && !ArraySize->isRValue()) { |
| 2167 | ExprResult Result = DefaultLvalueConversion(ArraySize); |
| 2168 | if (Result.isInvalid()) |
| 2169 | return QualType(); |
| 2170 | |
| 2171 | ArraySize = Result.get(); |
| 2172 | } |
| 2173 | |
| 2174 | |
| 2175 | |
| 2176 | if (!getLangOpts().CPlusPlus11 && |
| 2177 | ArraySize && !ArraySize->isTypeDependent() && |
| 2178 | !ArraySize->getType()->isIntegralOrUnscopedEnumerationType()) { |
| 2179 | Diag(ArraySize->getBeginLoc(), diag::err_array_size_non_int) |
| 2180 | << ArraySize->getType() << ArraySize->getSourceRange(); |
| 2181 | return QualType(); |
| 2182 | } |
| 2183 | |
| 2184 | llvm::APSInt ConstVal(Context.getTypeSize(Context.getSizeType())); |
| 2185 | if (!ArraySize) { |
| 2186 | if (ASM == ArrayType::Star) |
| 2187 | T = Context.getVariableArrayType(T, nullptr, ASM, Quals, Brackets); |
| 2188 | else |
| 2189 | T = Context.getIncompleteArrayType(T, ASM, Quals); |
| 2190 | } else if (ArraySize->isTypeDependent() || ArraySize->isValueDependent()) { |
| 2191 | T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals, Brackets); |
| 2192 | } else if ((!T->isDependentType() && !T->isIncompleteType() && |
| 2193 | !T->isConstantSizeType()) || |
| 2194 | isArraySizeVLA(*this, ArraySize, ConstVal)) { |
| 2195 | |
| 2196 | |
| 2197 | if (getLangOpts().CPlusPlus11 && |
| 2198 | !ArraySize->getType()->isIntegralOrUnscopedEnumerationType()) { |
| 2199 | Diag(ArraySize->getBeginLoc(), diag::err_array_size_non_int) |
| 2200 | << ArraySize->getType() << ArraySize->getSourceRange(); |
| 2201 | return QualType(); |
| 2202 | } |
| 2203 | |
| 2204 | |
| 2205 | |
| 2206 | |
| 2207 | T = Context.getVariableArrayType(T, ArraySize, ASM, Quals, Brackets); |
| 2208 | } else { |
| 2209 | |
| 2210 | |
| 2211 | if (ConstVal.isSigned() && ConstVal.isNegative()) { |
| 2212 | if (Entity) |
| 2213 | Diag(ArraySize->getBeginLoc(), diag::err_decl_negative_array_size) |
| 2214 | << getPrintableNameForEntity(Entity) << ArraySize->getSourceRange(); |
| 2215 | else |
| 2216 | Diag(ArraySize->getBeginLoc(), diag::err_typecheck_negative_array_size) |
| 2217 | << ArraySize->getSourceRange(); |
| 2218 | return QualType(); |
| 2219 | } |
| 2220 | if (ConstVal == 0) { |
| 2221 | |
| 2222 | |
| 2223 | Diag(ArraySize->getBeginLoc(), isSFINAEContext() |
| 2224 | ? diag::err_typecheck_zero_array_size |
| 2225 | : diag::ext_typecheck_zero_array_size) |
| 2226 | << ArraySize->getSourceRange(); |
| 2227 | |
| 2228 | if (ASM == ArrayType::Static) { |
| 2229 | Diag(ArraySize->getBeginLoc(), |
| 2230 | diag::warn_typecheck_zero_static_array_size) |
| 2231 | << ArraySize->getSourceRange(); |
| 2232 | ASM = ArrayType::Normal; |
| 2233 | } |
| 2234 | } else if (!T->isDependentType() && !T->isVariablyModifiedType() && |
| 2235 | !T->isIncompleteType() && !T->isUndeducedType()) { |
| 2236 | |
| 2237 | unsigned ActiveSizeBits |
| 2238 | = ConstantArrayType::getNumAddressingBits(Context, T, ConstVal); |
| 2239 | if (ActiveSizeBits > ConstantArrayType::getMaxSizeBits(Context)) { |
| 2240 | Diag(ArraySize->getBeginLoc(), diag::err_array_too_large) |
| 2241 | << ConstVal.toString(10) << ArraySize->getSourceRange(); |
| 2242 | return QualType(); |
| 2243 | } |
| 2244 | } |
| 2245 | |
| 2246 | T = Context.getConstantArrayType(T, ConstVal, ASM, Quals); |
| 2247 | } |
| 2248 | |
| 2249 | |
| 2250 | if (getLangOpts().OpenCL && T->isVariableArrayType()) { |
| 2251 | Diag(Loc, diag::err_opencl_vla); |
| 2252 | return QualType(); |
| 2253 | } |
| 2254 | |
| 2255 | if (T->isVariableArrayType() && !Context.getTargetInfo().isVLASupported()) { |
| 2256 | |
| 2257 | targetDiag(Loc, (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) |
| 2258 | ? diag::err_cuda_vla |
| 2259 | : diag::err_vla_unsupported) |
| 2260 | << ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) |
| 2261 | ? CurrentCUDATarget() |
| 2262 | : CFT_InvalidTarget); |
| 2263 | } |
| 2264 | |
| 2265 | |
| 2266 | if (!getLangOpts().C99) { |
| 2267 | if (T->isVariableArrayType()) { |
| 2268 | |
| 2269 | if (isSFINAEContext()) { |
| 2270 | Diag(Loc, diag::err_vla_in_sfinae); |
| 2271 | return QualType(); |
| 2272 | } |
| 2273 | |
| 2274 | else |
| 2275 | Diag(Loc, diag::ext_vla); |
| 2276 | } else if (ASM != ArrayType::Normal || Quals != 0) |
| 2277 | Diag(Loc, |
| 2278 | getLangOpts().CPlusPlus? diag::err_c99_array_usage_cxx |
| 2279 | : diag::ext_c99_array_usage) << ASM; |
| 2280 | } |
| 2281 | |
| 2282 | if (T->isVariableArrayType()) { |
| 2283 | |
| 2284 | Diag(Loc, diag::warn_vla_used); |
| 2285 | } |
| 2286 | |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | if (getLangOpts().OpenCL) { |
| 2291 | const QualType ArrType = Context.getBaseElementType(T); |
| 2292 | if (ArrType->isBlockPointerType() || ArrType->isPipeType() || |
| 2293 | ArrType->isSamplerT() || ArrType->isImageType()) { |
| 2294 | Diag(Loc, diag::err_opencl_invalid_type_array) << ArrType; |
| 2295 | return QualType(); |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | return T; |
| 2300 | } |
| 2301 | |
| 2302 | QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr, |
| 2303 | SourceLocation AttrLoc) { |
| 2304 | |
| 2305 | |
| 2306 | if (!CurType->isDependentType() && |
| 2307 | (!CurType->isBuiltinType() || CurType->isBooleanType() || |
| 2308 | (!CurType->isIntegerType() && !CurType->isRealFloatingType()))) { |
| 2309 | Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << CurType; |
| 2310 | return QualType(); |
| 2311 | } |
| 2312 | |
| 2313 | if (SizeExpr->isTypeDependent() || SizeExpr->isValueDependent()) |
| 2314 | return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc, |
| 2315 | VectorType::GenericVector); |
| 2316 | |
| 2317 | llvm::APSInt VecSize(32); |
| 2318 | if (!SizeExpr->isIntegerConstantExpr(VecSize, Context)) { |
| 2319 | Diag(AttrLoc, diag::err_attribute_argument_type) |
| 2320 | << "vector_size" << AANT_ArgumentIntegerConstant |
| 2321 | << SizeExpr->getSourceRange(); |
| 2322 | return QualType(); |
| 2323 | } |
| 2324 | |
| 2325 | if (CurType->isDependentType()) |
| 2326 | return Context.getDependentVectorType(CurType, SizeExpr, AttrLoc, |
| 2327 | VectorType::GenericVector); |
| 2328 | |
| 2329 | unsigned VectorSize = static_cast<unsigned>(VecSize.getZExtValue() * 8); |
| 2330 | unsigned TypeSize = static_cast<unsigned>(Context.getTypeSize(CurType)); |
| 2331 | |
| 2332 | if (VectorSize == 0) { |
| 2333 | Diag(AttrLoc, diag::err_attribute_zero_size) << SizeExpr->getSourceRange(); |
| 2334 | return QualType(); |
| 2335 | } |
| 2336 | |
| 2337 | |
| 2338 | if (VectorSize % TypeSize) { |
| 2339 | Diag(AttrLoc, diag::err_attribute_invalid_size) |
| 2340 | << SizeExpr->getSourceRange(); |
| 2341 | return QualType(); |
| 2342 | } |
| 2343 | |
| 2344 | if (VectorType::isVectorSizeTooLarge(VectorSize / TypeSize)) { |
| 2345 | Diag(AttrLoc, diag::err_attribute_size_too_large) |
| 2346 | << SizeExpr->getSourceRange(); |
| 2347 | return QualType(); |
| 2348 | } |
| 2349 | |
| 2350 | return Context.getVectorType(CurType, VectorSize / TypeSize, |
| 2351 | VectorType::GenericVector); |
| 2352 | } |
| 2353 | |
| 2354 | |
| 2355 | |
| 2356 | |
| 2357 | QualType Sema::BuildExtVectorType(QualType T, Expr *ArraySize, |
| 2358 | SourceLocation AttrLoc) { |
| 2359 | |
| 2360 | |
| 2361 | |
| 2362 | |
| 2363 | |
| 2364 | |
| 2365 | |
| 2366 | if ((!T->isDependentType() && !T->isIntegerType() && |
| 2367 | !T->isRealFloatingType()) || |
| 2368 | T->isBooleanType()) { |
| 2369 | Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << T; |
| 2370 | return QualType(); |
| 2371 | } |
| 2372 | |
| 2373 | if (!ArraySize->isTypeDependent() && !ArraySize->isValueDependent()) { |
| 2374 | llvm::APSInt vecSize(32); |
| 2375 | if (!ArraySize->isIntegerConstantExpr(vecSize, Context)) { |
| 2376 | Diag(AttrLoc, diag::err_attribute_argument_type) |
| 2377 | << "ext_vector_type" << AANT_ArgumentIntegerConstant |
| 2378 | << ArraySize->getSourceRange(); |
| 2379 | return QualType(); |
| 2380 | } |
| 2381 | |
| 2382 | |
| 2383 | |
| 2384 | unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue()); |
| 2385 | |
| 2386 | if (vectorSize == 0) { |
| 2387 | Diag(AttrLoc, diag::err_attribute_zero_size) |
| 2388 | << ArraySize->getSourceRange(); |
| 2389 | return QualType(); |
| 2390 | } |
| 2391 | |
| 2392 | if (VectorType::isVectorSizeTooLarge(vectorSize)) { |
| 2393 | Diag(AttrLoc, diag::err_attribute_size_too_large) |
| 2394 | << ArraySize->getSourceRange(); |
| 2395 | return QualType(); |
| 2396 | } |
| 2397 | |
| 2398 | return Context.getExtVectorType(T, vectorSize); |
| 2399 | } |
| 2400 | |
| 2401 | return Context.getDependentSizedExtVectorType(T, ArraySize, AttrLoc); |
| 2402 | } |
| 2403 | |
| 2404 | bool Sema::CheckFunctionReturnType(QualType T, SourceLocation Loc) { |
| 2405 | if (T->isArrayType() || T->isFunctionType()) { |
| 2406 | Diag(Loc, diag::err_func_returning_array_function) |
| 2407 | << T->isFunctionType() << T; |
| 2408 | return true; |
| 2409 | } |
| 2410 | |
| 2411 | |
| 2412 | if (T->isHalfType() && !getLangOpts().HalfArgsAndReturns) { |
| 2413 | Diag(Loc, diag::err_parameters_retval_cannot_have_fp16_type) << 1 << |
| 2414 | FixItHint::CreateInsertion(Loc, "*"); |
| 2415 | return true; |
| 2416 | } |
| 2417 | |
| 2418 | |
| 2419 | |
| 2420 | if (T->isObjCObjectType()) { |
| 2421 | Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value) |
| 2422 | << 0 << T << FixItHint::CreateInsertion(Loc, "*"); |
| 2423 | return true; |
| 2424 | } |
| 2425 | |
| 2426 | return false; |
| 2427 | } |
| 2428 | |
| 2429 | |
| 2430 | |
| 2431 | |
| 2432 | static void checkExtParameterInfos(Sema &S, ArrayRef<QualType> paramTypes, |
| 2433 | const FunctionProtoType::ExtProtoInfo &EPI, |
| 2434 | llvm::function_ref<SourceLocation(unsigned)> getParamLoc) { |
| 2435 | (0) . __assert_fail ("EPI.ExtParameterInfos && \"shouldn't get here without param infos\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 2435, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(EPI.ExtParameterInfos && "shouldn't get here without param infos"); |
| 2436 | |
| 2437 | bool hasCheckedSwiftCall = false; |
| 2438 | auto checkForSwiftCC = [&](unsigned paramIndex) { |
| 2439 | |
| 2440 | if (hasCheckedSwiftCall) return; |
| 2441 | hasCheckedSwiftCall = true; |
| 2442 | if (EPI.ExtInfo.getCC() == CC_Swift) return; |
| 2443 | S.Diag(getParamLoc(paramIndex), diag::err_swift_param_attr_not_swiftcall) |
| 2444 | << getParameterABISpelling(EPI.ExtParameterInfos[paramIndex].getABI()); |
| 2445 | }; |
| 2446 | |
| 2447 | for (size_t paramIndex = 0, numParams = paramTypes.size(); |
| 2448 | paramIndex != numParams; ++paramIndex) { |
| 2449 | switch (EPI.ExtParameterInfos[paramIndex].getABI()) { |
| 2450 | |
| 2451 | case ParameterABI::Ordinary: |
| 2452 | continue; |
| 2453 | |
| 2454 | |
| 2455 | |
| 2456 | case ParameterABI::SwiftIndirectResult: |
| 2457 | checkForSwiftCC(paramIndex); |
| 2458 | if (paramIndex != 0 && |
| 2459 | EPI.ExtParameterInfos[paramIndex - 1].getABI() |
| 2460 | != ParameterABI::SwiftIndirectResult) { |
| 2461 | S.Diag(getParamLoc(paramIndex), |
| 2462 | diag::err_swift_indirect_result_not_first); |
| 2463 | } |
| 2464 | continue; |
| 2465 | |
| 2466 | case ParameterABI::SwiftContext: |
| 2467 | checkForSwiftCC(paramIndex); |
| 2468 | continue; |
| 2469 | |
| 2470 | |
| 2471 | case ParameterABI::SwiftErrorResult: |
| 2472 | checkForSwiftCC(paramIndex); |
| 2473 | if (paramIndex == 0 || |
| 2474 | EPI.ExtParameterInfos[paramIndex - 1].getABI() != |
| 2475 | ParameterABI::SwiftContext) { |
| 2476 | S.Diag(getParamLoc(paramIndex), |
| 2477 | diag::err_swift_error_result_not_after_swift_context); |
| 2478 | } |
| 2479 | continue; |
| 2480 | } |
| 2481 | llvm_unreachable("bad ABI kind"); |
| 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | QualType Sema::BuildFunctionType(QualType T, |
| 2486 | MutableArrayRef<QualType> ParamTypes, |
| 2487 | SourceLocation Loc, DeclarationName Entity, |
| 2488 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 2489 | bool Invalid = false; |
| 2490 | |
| 2491 | Invalid |= CheckFunctionReturnType(T, Loc); |
| 2492 | |
| 2493 | for (unsigned Idx = 0, Cnt = ParamTypes.size(); Idx < Cnt; ++Idx) { |
| 2494 | |
| 2495 | QualType ParamType = Context.getAdjustedParameterType(ParamTypes[Idx]); |
| 2496 | if (ParamType->isVoidType()) { |
| 2497 | Diag(Loc, diag::err_param_with_void_type); |
| 2498 | Invalid = true; |
| 2499 | } else if (ParamType->isHalfType() && !getLangOpts().HalfArgsAndReturns) { |
| 2500 | |
| 2501 | Diag(Loc, diag::err_parameters_retval_cannot_have_fp16_type) << 0 << |
| 2502 | FixItHint::CreateInsertion(Loc, "*"); |
| 2503 | Invalid = true; |
| 2504 | } |
| 2505 | |
| 2506 | ParamTypes[Idx] = ParamType; |
| 2507 | } |
| 2508 | |
| 2509 | if (EPI.ExtParameterInfos) { |
| 2510 | checkExtParameterInfos(*this, ParamTypes, EPI, |
| 2511 | [=](unsigned i) { return Loc; }); |
| 2512 | } |
| 2513 | |
| 2514 | if (EPI.ExtInfo.getProducesResult()) { |
| 2515 | |
| 2516 | checkNSReturnsRetainedReturnType(Loc, T); |
| 2517 | } |
| 2518 | |
| 2519 | if (Invalid) |
| 2520 | return QualType(); |
| 2521 | |
| 2522 | return Context.getFunctionType(T, ParamTypes, EPI); |
| 2523 | } |
| 2524 | |
| 2525 | |
| 2526 | |
| 2527 | |
| 2528 | |
| 2529 | |
| 2530 | |
| 2531 | |
| 2532 | |
| 2533 | |
| 2534 | QualType Sema::BuildMemberPointerType(QualType T, QualType Class, |
| 2535 | SourceLocation Loc, |
| 2536 | DeclarationName Entity) { |
| 2537 | |
| 2538 | |
| 2539 | if (CheckDistantExceptionSpec(T)) { |
| 2540 | Diag(Loc, diag::err_distant_exception_spec); |
| 2541 | return QualType(); |
| 2542 | } |
| 2543 | |
| 2544 | |
| 2545 | |
| 2546 | if (T->isReferenceType()) { |
| 2547 | Diag(Loc, diag::err_illegal_decl_mempointer_to_reference) |
| 2548 | << getPrintableNameForEntity(Entity) << T; |
| 2549 | return QualType(); |
| 2550 | } |
| 2551 | |
| 2552 | if (T->isVoidType()) { |
| 2553 | Diag(Loc, diag::err_illegal_decl_mempointer_to_void) |
| 2554 | << getPrintableNameForEntity(Entity); |
| 2555 | return QualType(); |
| 2556 | } |
| 2557 | |
| 2558 | if (!Class->isDependentType() && !Class->isRecordType()) { |
| 2559 | Diag(Loc, diag::err_mempointer_in_nonclass_type) << Class; |
| 2560 | return QualType(); |
| 2561 | } |
| 2562 | |
| 2563 | |
| 2564 | |
| 2565 | bool IsCtorOrDtor = |
| 2566 | (Entity.getNameKind() == DeclarationName::CXXConstructorName) || |
| 2567 | (Entity.getNameKind() == DeclarationName::CXXDestructorName); |
| 2568 | if (T->isFunctionType()) |
| 2569 | adjustMemberFunctionCC(T, , IsCtorOrDtor, Loc); |
| 2570 | |
| 2571 | return Context.getMemberPointerType(T, Class.getTypePtr()); |
| 2572 | } |
| 2573 | |
| 2574 | |
| 2575 | |
| 2576 | |
| 2577 | |
| 2578 | |
| 2579 | |
| 2580 | |
| 2581 | |
| 2582 | |
| 2583 | |
| 2584 | |
| 2585 | QualType Sema::BuildBlockPointerType(QualType T, |
| 2586 | SourceLocation Loc, |
| 2587 | DeclarationName Entity) { |
| 2588 | if (!T->isFunctionType()) { |
| 2589 | Diag(Loc, diag::err_nonfunction_block_type); |
| 2590 | return QualType(); |
| 2591 | } |
| 2592 | |
| 2593 | if (checkQualifiedFunction(*this, T, Loc, QFK_BlockPointer)) |
| 2594 | return QualType(); |
| 2595 | |
| 2596 | return Context.getBlockPointerType(T); |
| 2597 | } |
| 2598 | |
| 2599 | QualType Sema::GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo) { |
| 2600 | QualType QT = Ty.get(); |
| 2601 | if (QT.isNull()) { |
| 2602 | if (TInfo) *TInfo = nullptr; |
| 2603 | return QualType(); |
| 2604 | } |
| 2605 | |
| 2606 | TypeSourceInfo *DI = nullptr; |
| 2607 | if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT)) { |
| 2608 | QT = LIT->getType(); |
| 2609 | DI = LIT->getTypeSourceInfo(); |
| 2610 | } |
| 2611 | |
| 2612 | if (TInfo) *TInfo = DI; |
| 2613 | return QT; |
| 2614 | } |
| 2615 | |
| 2616 | static void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state, |
| 2617 | Qualifiers::ObjCLifetime ownership, |
| 2618 | unsigned chunkIndex); |
| 2619 | |
| 2620 | |
| 2621 | |
| 2622 | |
| 2623 | static void inferARCWriteback(TypeProcessingState &state, |
| 2624 | QualType &declSpecType) { |
| 2625 | Sema &S = state.getSema(); |
| 2626 | Declarator &declarator = state.getDeclarator(); |
| 2627 | |
| 2628 | |
| 2629 | |
| 2630 | |
| 2631 | |
| 2632 | unsigned outermostPointerIndex = 0; |
| 2633 | bool isBlockPointer = false; |
| 2634 | unsigned numPointers = 0; |
| 2635 | for (unsigned i = 0, e = declarator.getNumTypeObjects(); i != e; ++i) { |
| 2636 | unsigned chunkIndex = i; |
| 2637 | DeclaratorChunk &chunk = declarator.getTypeObject(chunkIndex); |
| 2638 | switch (chunk.Kind) { |
| 2639 | case DeclaratorChunk::Paren: |
| 2640 | |
| 2641 | break; |
| 2642 | |
| 2643 | case DeclaratorChunk::Reference: |
| 2644 | case DeclaratorChunk::Pointer: |
| 2645 | |
| 2646 | |
| 2647 | |
| 2648 | outermostPointerIndex = chunkIndex; |
| 2649 | numPointers++; |
| 2650 | break; |
| 2651 | |
| 2652 | case DeclaratorChunk::BlockPointer: |
| 2653 | |
| 2654 | |
| 2655 | |
| 2656 | if (numPointers != 1) return; |
| 2657 | numPointers++; |
| 2658 | outermostPointerIndex = chunkIndex; |
| 2659 | isBlockPointer = true; |
| 2660 | |
| 2661 | |
| 2662 | goto done; |
| 2663 | |
| 2664 | case DeclaratorChunk::Array: |
| 2665 | case DeclaratorChunk::Function: |
| 2666 | case DeclaratorChunk::MemberPointer: |
| 2667 | case DeclaratorChunk::Pipe: |
| 2668 | return; |
| 2669 | } |
| 2670 | } |
| 2671 | done: |
| 2672 | |
| 2673 | |
| 2674 | |
| 2675 | |
| 2676 | if (numPointers == 1) { |
| 2677 | |
| 2678 | if (!declSpecType->isObjCRetainableType()) return; |
| 2679 | |
| 2680 | |
| 2681 | if (declSpecType.getObjCLifetime()) return; |
| 2682 | |
| 2683 | |
| 2684 | Qualifiers qs; |
| 2685 | |
| 2686 | if (declSpecType->isObjCARCImplicitlyUnretainedType()) |
| 2687 | qs.addObjCLifetime(Qualifiers::OCL_ExplicitNone); |
| 2688 | else |
| 2689 | qs.addObjCLifetime(Qualifiers::OCL_Autoreleasing); |
| 2690 | declSpecType = S.Context.getQualifiedType(declSpecType, qs); |
| 2691 | |
| 2692 | |
| 2693 | |
| 2694 | } else if (numPointers == 2) { |
| 2695 | |
| 2696 | |
| 2697 | |
| 2698 | if (!isBlockPointer && !declSpecType->isObjCObjectType()) |
| 2699 | return; |
| 2700 | |
| 2701 | |
| 2702 | DeclaratorChunk &chunk = declarator.getTypeObject(outermostPointerIndex); |
| 2703 | if (chunk.Kind != DeclaratorChunk::Pointer && |
| 2704 | chunk.Kind != DeclaratorChunk::BlockPointer) |
| 2705 | return; |
| 2706 | for (const ParsedAttr &AL : chunk.getAttrs()) |
| 2707 | if (AL.getKind() == ParsedAttr::AT_ObjCOwnership) |
| 2708 | return; |
| 2709 | |
| 2710 | transferARCOwnershipToDeclaratorChunk(state, Qualifiers::OCL_Autoreleasing, |
| 2711 | outermostPointerIndex); |
| 2712 | |
| 2713 | |
| 2714 | } else return; |
| 2715 | |
| 2716 | |
| 2717 | } |
| 2718 | |
| 2719 | void Sema::diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
| 2720 | SourceLocation FallbackLoc, |
| 2721 | SourceLocation ConstQualLoc, |
| 2722 | SourceLocation VolatileQualLoc, |
| 2723 | SourceLocation RestrictQualLoc, |
| 2724 | SourceLocation AtomicQualLoc, |
| 2725 | SourceLocation UnalignedQualLoc) { |
| 2726 | if (!Quals) |
| 2727 | return; |
| 2728 | |
| 2729 | struct Qual { |
| 2730 | const char *Name; |
| 2731 | unsigned Mask; |
| 2732 | SourceLocation Loc; |
| 2733 | } const QualKinds[5] = { |
| 2734 | { "const", DeclSpec::TQ_const, ConstQualLoc }, |
| 2735 | { "volatile", DeclSpec::TQ_volatile, VolatileQualLoc }, |
| 2736 | { "restrict", DeclSpec::TQ_restrict, RestrictQualLoc }, |
| 2737 | { "__unaligned", DeclSpec::TQ_unaligned, UnalignedQualLoc }, |
| 2738 | { "_Atomic", DeclSpec::TQ_atomic, AtomicQualLoc } |
| 2739 | }; |
| 2740 | |
| 2741 | SmallString<32> QualStr; |
| 2742 | unsigned NumQuals = 0; |
| 2743 | SourceLocation Loc; |
| 2744 | FixItHint FixIts[5]; |
| 2745 | |
| 2746 | |
| 2747 | for (auto &E : QualKinds) { |
| 2748 | if (Quals & E.Mask) { |
| 2749 | if (!QualStr.empty()) QualStr += ' '; |
| 2750 | QualStr += E.Name; |
| 2751 | |
| 2752 | |
| 2753 | SourceLocation QualLoc = E.Loc; |
| 2754 | if (QualLoc.isValid()) { |
| 2755 | FixIts[NumQuals] = FixItHint::CreateRemoval(QualLoc); |
| 2756 | if (Loc.isInvalid() || |
| 2757 | getSourceManager().isBeforeInTranslationUnit(QualLoc, Loc)) |
| 2758 | Loc = QualLoc; |
| 2759 | } |
| 2760 | |
| 2761 | ++NumQuals; |
| 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | Diag(Loc.isInvalid() ? FallbackLoc : Loc, DiagID) |
| 2766 | << QualStr << NumQuals << FixIts[0] << FixIts[1] << FixIts[2] << FixIts[3]; |
| 2767 | } |
| 2768 | |
| 2769 | |
| 2770 | static void diagnoseRedundantReturnTypeQualifiers(Sema &S, QualType RetTy, |
| 2771 | Declarator &D, |
| 2772 | unsigned FunctionChunkIndex) { |
| 2773 | if (D.getTypeObject(FunctionChunkIndex).Fun.hasTrailingReturnType()) { |
| 2774 | |
| 2775 | |
| 2776 | S.diagnoseIgnoredQualifiers(diag::warn_qual_return_type, |
| 2777 | RetTy.getLocalCVRQualifiers(), |
| 2778 | D.getIdentifierLoc()); |
| 2779 | return; |
| 2780 | } |
| 2781 | |
| 2782 | for (unsigned OuterChunkIndex = FunctionChunkIndex + 1, |
| 2783 | End = D.getNumTypeObjects(); |
| 2784 | OuterChunkIndex != End; ++OuterChunkIndex) { |
| 2785 | DeclaratorChunk &OuterChunk = D.getTypeObject(OuterChunkIndex); |
| 2786 | switch (OuterChunk.Kind) { |
| 2787 | case DeclaratorChunk::Paren: |
| 2788 | continue; |
| 2789 | |
| 2790 | case DeclaratorChunk::Pointer: { |
| 2791 | DeclaratorChunk::PointerTypeInfo &PTI = OuterChunk.Ptr; |
| 2792 | S.diagnoseIgnoredQualifiers( |
| 2793 | diag::warn_qual_return_type, |
| 2794 | PTI.TypeQuals, |
| 2795 | SourceLocation(), |
| 2796 | SourceLocation::getFromRawEncoding(PTI.ConstQualLoc), |
| 2797 | SourceLocation::getFromRawEncoding(PTI.VolatileQualLoc), |
| 2798 | SourceLocation::getFromRawEncoding(PTI.RestrictQualLoc), |
| 2799 | SourceLocation::getFromRawEncoding(PTI.AtomicQualLoc), |
| 2800 | SourceLocation::getFromRawEncoding(PTI.UnalignedQualLoc)); |
| 2801 | return; |
| 2802 | } |
| 2803 | |
| 2804 | case DeclaratorChunk::Function: |
| 2805 | case DeclaratorChunk::BlockPointer: |
| 2806 | case DeclaratorChunk::Reference: |
| 2807 | case DeclaratorChunk::Array: |
| 2808 | case DeclaratorChunk::MemberPointer: |
| 2809 | case DeclaratorChunk::Pipe: |
| 2810 | |
| 2811 | |
| 2812 | unsigned AtomicQual = RetTy->isAtomicType() ? DeclSpec::TQ_atomic : 0; |
| 2813 | S.diagnoseIgnoredQualifiers(diag::warn_qual_return_type, |
| 2814 | RetTy.getCVRQualifiers() | AtomicQual, |
| 2815 | D.getIdentifierLoc()); |
| 2816 | return; |
| 2817 | } |
| 2818 | |
| 2819 | llvm_unreachable("unknown declarator chunk kind"); |
| 2820 | } |
| 2821 | |
| 2822 | |
| 2823 | |
| 2824 | |
| 2825 | if (D.getName().getKind() == UnqualifiedIdKind::IK_ConversionFunctionId) |
| 2826 | return; |
| 2827 | |
| 2828 | |
| 2829 | |
| 2830 | S.diagnoseIgnoredQualifiers(diag::warn_qual_return_type, |
| 2831 | D.getDeclSpec().getTypeQualifiers(), |
| 2832 | D.getIdentifierLoc(), |
| 2833 | D.getDeclSpec().getConstSpecLoc(), |
| 2834 | D.getDeclSpec().getVolatileSpecLoc(), |
| 2835 | D.getDeclSpec().getRestrictSpecLoc(), |
| 2836 | D.getDeclSpec().getAtomicSpecLoc(), |
| 2837 | D.getDeclSpec().getUnalignedSpecLoc()); |
| 2838 | } |
| 2839 | |
| 2840 | static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state, |
| 2841 | TypeSourceInfo *&ReturnTypeInfo) { |
| 2842 | Sema &SemaRef = state.getSema(); |
| 2843 | Declarator &D = state.getDeclarator(); |
| 2844 | QualType T; |
| 2845 | ReturnTypeInfo = nullptr; |
| 2846 | |
| 2847 | |
| 2848 | TagDecl *OwnedTagDecl = nullptr; |
| 2849 | |
| 2850 | switch (D.getName().getKind()) { |
| 2851 | case UnqualifiedIdKind::IK_ImplicitSelfParam: |
| 2852 | case UnqualifiedIdKind::IK_OperatorFunctionId: |
| 2853 | case UnqualifiedIdKind::IK_Identifier: |
| 2854 | case UnqualifiedIdKind::IK_LiteralOperatorId: |
| 2855 | case UnqualifiedIdKind::IK_TemplateId: |
| 2856 | T = ConvertDeclSpecToType(state); |
| 2857 | |
| 2858 | if (!D.isInvalidType() && D.getDeclSpec().isTypeSpecOwned()) { |
| 2859 | OwnedTagDecl = cast<TagDecl>(D.getDeclSpec().getRepAsDecl()); |
| 2860 | |
| 2861 | OwnedTagDecl->setEmbeddedInDeclarator(true); |
| 2862 | } |
| 2863 | break; |
| 2864 | |
| 2865 | case UnqualifiedIdKind::IK_ConstructorName: |
| 2866 | case UnqualifiedIdKind::IK_ConstructorTemplateId: |
| 2867 | case UnqualifiedIdKind::IK_DestructorName: |
| 2868 | |
| 2869 | |
| 2870 | T = SemaRef.Context.VoidTy; |
| 2871 | processTypeAttrs(state, T, TAL_DeclSpec, |
| 2872 | D.getMutableDeclSpec().getAttributes()); |
| 2873 | break; |
| 2874 | |
| 2875 | case UnqualifiedIdKind::IK_DeductionGuideName: |
| 2876 | |
| 2877 | |
| 2878 | T = SemaRef.Context.DependentTy; |
| 2879 | break; |
| 2880 | |
| 2881 | case UnqualifiedIdKind::IK_ConversionFunctionId: |
| 2882 | |
| 2883 | |
| 2884 | T = SemaRef.GetTypeFromParser(D.getName().ConversionFunctionId, |
| 2885 | &ReturnTypeInfo); |
| 2886 | break; |
| 2887 | } |
| 2888 | |
| 2889 | if (!D.getAttributes().empty()) |
| 2890 | distributeTypeAttrsFromDeclarator(state, T); |
| 2891 | |
| 2892 | |
| 2893 | if (DeducedType *Deduced = T->getContainedDeducedType()) { |
| 2894 | AutoType *Auto = dyn_cast<AutoType>(Deduced); |
| 2895 | int Error = -1; |
| 2896 | |
| 2897 | |
| 2898 | |
| 2899 | bool IsCXXAutoType = |
| 2900 | (Auto && Auto->getKeyword() != AutoTypeKeyword::GNUAutoType); |
| 2901 | bool IsDeducedReturnType = false; |
| 2902 | |
| 2903 | switch (D.getContext()) { |
| 2904 | case DeclaratorContext::LambdaExprContext: |
| 2905 | |
| 2906 | |
| 2907 | break; |
| 2908 | case DeclaratorContext::ObjCParameterContext: |
| 2909 | case DeclaratorContext::ObjCResultContext: |
| 2910 | case DeclaratorContext::PrototypeContext: |
| 2911 | Error = 0; |
| 2912 | break; |
| 2913 | case DeclaratorContext::LambdaExprParameterContext: |
| 2914 | |
| 2915 | if (!SemaRef.getLangOpts().CPlusPlus14 || |
| 2916 | !Auto || Auto->getKeyword() != AutoTypeKeyword::Auto) |
| 2917 | Error = 16; |
| 2918 | else { |
| 2919 | |
| 2920 | |
| 2921 | sema::LambdaScopeInfo *LSI = SemaRef.getCurLambda(); |
| 2922 | (0) . __assert_fail ("LSI && \"No LambdaScopeInfo on the stack!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 2922, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(LSI && "No LambdaScopeInfo on the stack!"); |
| 2923 | const unsigned TemplateParameterDepth = LSI->AutoTemplateParameterDepth; |
| 2924 | const unsigned AutoParameterPosition = LSI->AutoTemplateParams.size(); |
| 2925 | const bool IsParameterPack = D.hasEllipsis(); |
| 2926 | |
| 2927 | |
| 2928 | |
| 2929 | |
| 2930 | TemplateTypeParmDecl *CorrespondingTemplateParam = |
| 2931 | TemplateTypeParmDecl::Create( |
| 2932 | SemaRef.Context, SemaRef.Context.getTranslationUnitDecl(), |
| 2933 | SourceLocation(), D.getBeginLoc(), |
| 2934 | TemplateParameterDepth, AutoParameterPosition, |
| 2935 | nullptr, false, IsParameterPack); |
| 2936 | LSI->AutoTemplateParams.push_back(CorrespondingTemplateParam); |
| 2937 | |
| 2938 | |
| 2939 | |
| 2940 | |
| 2941 | T = SemaRef.ReplaceAutoType( |
| 2942 | T, QualType(CorrespondingTemplateParam->getTypeForDecl(), 0)); |
| 2943 | } |
| 2944 | break; |
| 2945 | case DeclaratorContext::MemberContext: { |
| 2946 | if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static || |
| 2947 | D.isFunctionDeclarator()) |
| 2948 | break; |
| 2949 | bool Cxx = SemaRef.getLangOpts().CPlusPlus; |
| 2950 | switch (cast<TagDecl>(SemaRef.CurContext)->getTagKind()) { |
| 2951 | case TTK_Enum: llvm_unreachable("unhandled tag kind"); |
| 2952 | case TTK_Struct: Error = Cxx ? 1 : 2; break; |
| 2953 | case TTK_Union: Error = Cxx ? 3 : 4; break; |
| 2954 | case TTK_Class: Error = 5; break; |
| 2955 | case TTK_Interface: Error = 6; break; |
| 2956 | } |
| 2957 | if (D.getDeclSpec().isFriendSpecified()) |
| 2958 | Error = 20; |
| 2959 | break; |
| 2960 | } |
| 2961 | case DeclaratorContext::CXXCatchContext: |
| 2962 | case DeclaratorContext::ObjCCatchContext: |
| 2963 | Error = 7; |
| 2964 | break; |
| 2965 | case DeclaratorContext::TemplateParamContext: |
| 2966 | if (isa<DeducedTemplateSpecializationType>(Deduced)) |
| 2967 | Error = 19; |
| 2968 | else if (!SemaRef.getLangOpts().CPlusPlus17) |
| 2969 | Error = 8; |
| 2970 | break; |
| 2971 | case DeclaratorContext::BlockLiteralContext: |
| 2972 | Error = 9; |
| 2973 | break; |
| 2974 | case DeclaratorContext::TemplateArgContext: |
| 2975 | |
| 2976 | |
| 2977 | if (isa<DeducedTemplateSpecializationType>(Deduced) && |
| 2978 | !D.getNumTypeObjects() && |
| 2979 | D.getDeclSpec().getParsedSpecifiers() == DeclSpec::PQ_TypeSpecifier) |
| 2980 | break; |
| 2981 | LLVM_FALLTHROUGH; |
| 2982 | case DeclaratorContext::TemplateTypeArgContext: |
| 2983 | Error = 10; |
| 2984 | break; |
| 2985 | case DeclaratorContext::AliasDeclContext: |
| 2986 | case DeclaratorContext::AliasTemplateContext: |
| 2987 | Error = 12; |
| 2988 | break; |
| 2989 | case DeclaratorContext::TrailingReturnContext: |
| 2990 | case DeclaratorContext::TrailingReturnVarContext: |
| 2991 | if (!SemaRef.getLangOpts().CPlusPlus14 || !IsCXXAutoType) |
| 2992 | Error = 13; |
| 2993 | IsDeducedReturnType = true; |
| 2994 | break; |
| 2995 | case DeclaratorContext::ConversionIdContext: |
| 2996 | if (!SemaRef.getLangOpts().CPlusPlus14 || !IsCXXAutoType) |
| 2997 | Error = 14; |
| 2998 | IsDeducedReturnType = true; |
| 2999 | break; |
| 3000 | case DeclaratorContext::FunctionalCastContext: |
| 3001 | if (isa<DeducedTemplateSpecializationType>(Deduced)) |
| 3002 | break; |
| 3003 | LLVM_FALLTHROUGH; |
| 3004 | case DeclaratorContext::TypeNameContext: |
| 3005 | Error = 15; |
| 3006 | break; |
| 3007 | case DeclaratorContext::FileContext: |
| 3008 | case DeclaratorContext::BlockContext: |
| 3009 | case DeclaratorContext::ForContext: |
| 3010 | case DeclaratorContext::InitStmtContext: |
| 3011 | case DeclaratorContext::ConditionContext: |
| 3012 | |
| 3013 | |
| 3014 | |
| 3015 | break; |
| 3016 | case DeclaratorContext::CXXNewContext: |
| 3017 | |
| 3018 | |
| 3019 | if (!IsCXXAutoType && !isa<DeducedTemplateSpecializationType>(Deduced)) |
| 3020 | Error = 17; |
| 3021 | break; |
| 3022 | case DeclaratorContext::KNRTypeListContext: |
| 3023 | Error = 18; |
| 3024 | break; |
| 3025 | } |
| 3026 | |
| 3027 | if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) |
| 3028 | Error = 11; |
| 3029 | |
| 3030 | |
| 3031 | |
| 3032 | if (D.isFunctionDeclarator() && |
| 3033 | (!SemaRef.getLangOpts().CPlusPlus11 || !IsCXXAutoType)) |
| 3034 | Error = 13; |
| 3035 | |
| 3036 | bool HaveTrailing = false; |
| 3037 | |
| 3038 | |
| 3039 | |
| 3040 | |
| 3041 | |
| 3042 | |
| 3043 | |
| 3044 | if (SemaRef.getLangOpts().CPlusPlus11 && IsCXXAutoType && |
| 3045 | D.hasTrailingReturnType()) { |
| 3046 | HaveTrailing = true; |
| 3047 | Error = -1; |
| 3048 | } |
| 3049 | |
| 3050 | SourceRange AutoRange = D.getDeclSpec().getTypeSpecTypeLoc(); |
| 3051 | if (D.getName().getKind() == UnqualifiedIdKind::IK_ConversionFunctionId) |
| 3052 | AutoRange = D.getName().getSourceRange(); |
| 3053 | |
| 3054 | if (Error != -1) { |
| 3055 | unsigned Kind; |
| 3056 | if (Auto) { |
| 3057 | switch (Auto->getKeyword()) { |
| 3058 | case AutoTypeKeyword::Auto: Kind = 0; break; |
| 3059 | case AutoTypeKeyword::DecltypeAuto: Kind = 1; break; |
| 3060 | case AutoTypeKeyword::GNUAutoType: Kind = 2; break; |
| 3061 | } |
| 3062 | } else { |
| 3063 | (0) . __assert_fail ("isa(Deduced) && \"unknown auto type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 3064, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<DeducedTemplateSpecializationType>(Deduced) && |
| 3064 | (0) . __assert_fail ("isa(Deduced) && \"unknown auto type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 3064, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "unknown auto type"); |
| 3065 | Kind = 3; |
| 3066 | } |
| 3067 | |
| 3068 | auto *DTST = dyn_cast<DeducedTemplateSpecializationType>(Deduced); |
| 3069 | TemplateName TN = DTST ? DTST->getTemplateName() : TemplateName(); |
| 3070 | |
| 3071 | SemaRef.Diag(AutoRange.getBegin(), diag::err_auto_not_allowed) |
| 3072 | << Kind << Error << (int)SemaRef.getTemplateNameKindForDiagnostics(TN) |
| 3073 | << QualType(Deduced, 0) << AutoRange; |
| 3074 | if (auto *TD = TN.getAsTemplateDecl()) |
| 3075 | SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here); |
| 3076 | |
| 3077 | T = SemaRef.Context.IntTy; |
| 3078 | D.setInvalidType(true); |
| 3079 | } else if (!HaveTrailing && |
| 3080 | D.getContext() != DeclaratorContext::LambdaExprContext) { |
| 3081 | |
| 3082 | |
| 3083 | SemaRef.Diag(AutoRange.getBegin(), |
| 3084 | D.getContext() == |
| 3085 | DeclaratorContext::LambdaExprParameterContext |
| 3086 | ? diag::warn_cxx11_compat_generic_lambda |
| 3087 | : IsDeducedReturnType |
| 3088 | ? diag::warn_cxx11_compat_deduced_return_type |
| 3089 | : diag::warn_cxx98_compat_auto_type_specifier) |
| 3090 | << AutoRange; |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | if (SemaRef.getLangOpts().CPlusPlus && |
| 3095 | OwnedTagDecl && OwnedTagDecl->isCompleteDefinition()) { |
| 3096 | |
| 3097 | |
| 3098 | unsigned DiagID = 0; |
| 3099 | switch (D.getContext()) { |
| 3100 | case DeclaratorContext::TrailingReturnContext: |
| 3101 | case DeclaratorContext::TrailingReturnVarContext: |
| 3102 | |
| 3103 | |
| 3104 | llvm_unreachable("parser should not have allowed this"); |
| 3105 | break; |
| 3106 | case DeclaratorContext::FileContext: |
| 3107 | case DeclaratorContext::MemberContext: |
| 3108 | case DeclaratorContext::BlockContext: |
| 3109 | case DeclaratorContext::ForContext: |
| 3110 | case DeclaratorContext::InitStmtContext: |
| 3111 | case DeclaratorContext::BlockLiteralContext: |
| 3112 | case DeclaratorContext::LambdaExprContext: |
| 3113 | |
| 3114 | |
| 3115 | |
| 3116 | |
| 3117 | case DeclaratorContext::AliasDeclContext: |
| 3118 | break; |
| 3119 | case DeclaratorContext::AliasTemplateContext: |
| 3120 | DiagID = diag::err_type_defined_in_alias_template; |
| 3121 | break; |
| 3122 | case DeclaratorContext::TypeNameContext: |
| 3123 | case DeclaratorContext::FunctionalCastContext: |
| 3124 | case DeclaratorContext::ConversionIdContext: |
| 3125 | case DeclaratorContext::TemplateParamContext: |
| 3126 | case DeclaratorContext::CXXNewContext: |
| 3127 | case DeclaratorContext::CXXCatchContext: |
| 3128 | case DeclaratorContext::ObjCCatchContext: |
| 3129 | case DeclaratorContext::TemplateArgContext: |
| 3130 | case DeclaratorContext::TemplateTypeArgContext: |
| 3131 | DiagID = diag::err_type_defined_in_type_specifier; |
| 3132 | break; |
| 3133 | case DeclaratorContext::PrototypeContext: |
| 3134 | case DeclaratorContext::LambdaExprParameterContext: |
| 3135 | case DeclaratorContext::ObjCParameterContext: |
| 3136 | case DeclaratorContext::ObjCResultContext: |
| 3137 | case DeclaratorContext::KNRTypeListContext: |
| 3138 | |
| 3139 | |
| 3140 | DiagID = diag::err_type_defined_in_param_type; |
| 3141 | break; |
| 3142 | case DeclaratorContext::ConditionContext: |
| 3143 | |
| 3144 | |
| 3145 | |
| 3146 | DiagID = diag::err_type_defined_in_condition; |
| 3147 | break; |
| 3148 | } |
| 3149 | |
| 3150 | if (DiagID != 0) { |
| 3151 | SemaRef.Diag(OwnedTagDecl->getLocation(), DiagID) |
| 3152 | << SemaRef.Context.getTypeDeclType(OwnedTagDecl); |
| 3153 | D.setInvalidType(true); |
| 3154 | } |
| 3155 | } |
| 3156 | |
| 3157 | (0) . __assert_fail ("!T.isNull() && \"This function should not return a null type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 3157, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!T.isNull() && "This function should not return a null type"); |
| 3158 | return T; |
| 3159 | } |
| 3160 | |
| 3161 | |
| 3162 | |
| 3163 | static void warnAboutAmbiguousFunction(Sema &S, Declarator &D, |
| 3164 | DeclaratorChunk &DeclType, QualType RT) { |
| 3165 | const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; |
| 3166 | (0) . __assert_fail ("FTI.isAmbiguous && \"no direct-initializer / function ambiguity\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 3166, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FTI.isAmbiguous && "no direct-initializer / function ambiguity"); |
| 3167 | |
| 3168 | |
| 3169 | if (RT->isVoidType()) |
| 3170 | return; |
| 3171 | |
| 3172 | |
| 3173 | if (!RT->isRecordType() && FTI.NumParams > 1) |
| 3174 | return; |
| 3175 | |
| 3176 | |
| 3177 | if (RT->isReferenceType() && FTI.NumParams != 1) |
| 3178 | return; |
| 3179 | |
| 3180 | |
| 3181 | |
| 3182 | if (!D.isFunctionDeclarator() || |
| 3183 | D.getFunctionDefinitionKind() != FDK_Declaration || |
| 3184 | !S.CurContext->isFunctionOrMethod() || |
| 3185 | D.getDeclSpec().getStorageClassSpec() |
| 3186 | != DeclSpec::SCS_unspecified) |
| 3187 | return; |
| 3188 | |
| 3189 | |
| 3190 | |
| 3191 | if (D.getContext() == DeclaratorContext::ConditionContext) |
| 3192 | return; |
| 3193 | |
| 3194 | SourceRange ParenRange(DeclType.Loc, DeclType.EndLoc); |
| 3195 | |
| 3196 | S.Diag(DeclType.Loc, |
| 3197 | FTI.NumParams ? diag::warn_parens_disambiguated_as_function_declaration |
| 3198 | : diag::warn_empty_parens_are_function_decl) |
| 3199 | << ParenRange; |
| 3200 | |
| 3201 | |
| 3202 | |
| 3203 | |
| 3204 | |
| 3205 | |
| 3206 | if (!D.isFirstDeclarator() && D.getIdentifier()) { |
| 3207 | FullSourceLoc Comma(D.getCommaLoc(), S.SourceMgr); |
| 3208 | FullSourceLoc Name(D.getIdentifierLoc(), S.SourceMgr); |
| 3209 | if (Comma.getFileID() != Name.getFileID() || |
| 3210 | Comma.getSpellingLineNumber() != Name.getSpellingLineNumber()) { |
| 3211 | LookupResult Result(S, D.getIdentifier(), SourceLocation(), |
| 3212 | Sema::LookupOrdinaryName); |
| 3213 | if (S.LookupName(Result, S.getCurScope())) |
| 3214 | S.Diag(D.getCommaLoc(), diag::note_empty_parens_function_call) |
| 3215 | << FixItHint::CreateReplacement(D.getCommaLoc(), ";") |
| 3216 | << D.getIdentifier(); |
| 3217 | Result.suppressDiagnostics(); |
| 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | if (FTI.NumParams > 0) { |
| 3222 | |
| 3223 | |
| 3224 | |
| 3225 | SourceRange Range = FTI.Params[0].Param->getSourceRange(); |
| 3226 | SourceLocation B = Range.getBegin(); |
| 3227 | SourceLocation E = S.getLocForEndOfToken(Range.getEnd()); |
| 3228 | |
| 3229 | |
| 3230 | S.Diag(B, diag::note_additional_parens_for_variable_declaration) |
| 3231 | << FixItHint::CreateInsertion(B, "(") |
| 3232 | << FixItHint::CreateInsertion(E, ")"); |
| 3233 | } else { |
| 3234 | |
| 3235 | |
| 3236 | |
| 3237 | const CXXRecordDecl *RD = RT->getAsCXXRecordDecl(); |
| 3238 | |
| 3239 | |
| 3240 | |
| 3241 | |
| 3242 | |
| 3243 | if (RD && RD->hasDefinition() && |
| 3244 | (RD->isEmpty() || RD->hasUserProvidedDefaultConstructor())) |
| 3245 | S.Diag(DeclType.Loc, diag::note_empty_parens_default_ctor) |
| 3246 | << FixItHint::CreateRemoval(ParenRange); |
| 3247 | else { |
| 3248 | std::string Init = |
| 3249 | S.getFixItZeroInitializerForType(RT, ParenRange.getBegin()); |
| 3250 | if (Init.empty() && S.LangOpts.CPlusPlus11) |
| 3251 | Init = "{}"; |
| 3252 | if (!Init.empty()) |
| 3253 | S.Diag(DeclType.Loc, diag::note_empty_parens_zero_initialize) |
| 3254 | << FixItHint::CreateReplacement(ParenRange, Init); |
| 3255 | } |
| 3256 | } |
| 3257 | } |
| 3258 | |
| 3259 | |
| 3260 | |
| 3261 | static void warnAboutRedundantParens(Sema &S, Declarator &D, QualType T) { |
| 3262 | DeclaratorChunk &Paren = D.getTypeObject(D.getNumTypeObjects() - 1); |
| 3263 | (0) . __assert_fail ("Paren.Kind == DeclaratorChunk..Paren && \"do not have redundant top-level parentheses\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 3264, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Paren.Kind == DeclaratorChunk::Paren && |
| 3264 | (0) . __assert_fail ("Paren.Kind == DeclaratorChunk..Paren && \"do not have redundant top-level parentheses\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 3264, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "do not have redundant top-level parentheses"); |
| 3265 | |
| 3266 | |
| 3267 | |
| 3268 | if (S.inTemplateInstantiation()) |
| 3269 | return; |
| 3270 | |
| 3271 | |
| 3272 | |
| 3273 | bool CouldBeTemporaryObject = |
| 3274 | S.getLangOpts().CPlusPlus && D.isExpressionContext() && |
| 3275 | !D.isInvalidType() && D.getIdentifier() && |
| 3276 | D.getDeclSpec().getParsedSpecifiers() == DeclSpec::PQ_TypeSpecifier && |
| 3277 | (T->isRecordType() || T->isDependentType()) && |
| 3278 | D.getDeclSpec().getTypeQualifiers() == 0 && D.isFirstDeclarator(); |
| 3279 | |
| 3280 | bool StartsWithDeclaratorId = true; |
| 3281 | for (auto &C : D.type_objects()) { |
| 3282 | switch (C.Kind) { |
| 3283 | case DeclaratorChunk::Paren: |
| 3284 | if (&C == &Paren) |
| 3285 | continue; |
| 3286 | LLVM_FALLTHROUGH; |
| 3287 | case DeclaratorChunk::Pointer: |
| 3288 | StartsWithDeclaratorId = false; |
| 3289 | continue; |
| 3290 | |
| 3291 | case DeclaratorChunk::Array: |
| 3292 | if (!C.Arr.NumElts) |
| 3293 | CouldBeTemporaryObject = false; |
| 3294 | continue; |
| 3295 | |
| 3296 | case DeclaratorChunk::Reference: |
| 3297 | |
| 3298 | |
| 3299 | |
| 3300 | |
| 3301 | CouldBeTemporaryObject = false; |
| 3302 | StartsWithDeclaratorId = false; |
| 3303 | continue; |
| 3304 | |
| 3305 | case DeclaratorChunk::Function: |
| 3306 | |
| 3307 | if (D.getContext() == DeclaratorContext::CXXNewContext) |
| 3308 | return; |
| 3309 | |
| 3310 | |
| 3311 | |
| 3312 | CouldBeTemporaryObject = false; |
| 3313 | continue; |
| 3314 | |
| 3315 | case DeclaratorChunk::BlockPointer: |
| 3316 | case DeclaratorChunk::MemberPointer: |
| 3317 | case DeclaratorChunk::Pipe: |
| 3318 | |
| 3319 | CouldBeTemporaryObject = false; |
| 3320 | StartsWithDeclaratorId = false; |
| 3321 | continue; |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | |
| 3326 | |
| 3327 | |
| 3328 | |
| 3329 | |
| 3330 | if (CouldBeTemporaryObject) { |
| 3331 | LookupResult Result(S, D.getIdentifier(), SourceLocation(), |
| 3332 | Sema::LookupOrdinaryName); |
| 3333 | if (!S.LookupName(Result, S.getCurScope())) |
| 3334 | CouldBeTemporaryObject = false; |
| 3335 | Result.suppressDiagnostics(); |
| 3336 | } |
| 3337 | |
| 3338 | SourceRange ParenRange(Paren.Loc, Paren.EndLoc); |
| 3339 | |
| 3340 | if (!CouldBeTemporaryObject) { |
| 3341 | |
| 3342 | |
| 3343 | |
| 3344 | |
| 3345 | if (StartsWithDeclaratorId && D.getCXXScopeSpec().isValid()) { |
| 3346 | for (NestedNameSpecifier *NNS = D.getCXXScopeSpec().getScopeRep(); NNS; |
| 3347 | NNS = NNS->getPrefix()) { |
| 3348 | if (NNS->getKind() == NestedNameSpecifier::Global) |
| 3349 | return; |
| 3350 | } |
| 3351 | } |
| 3352 | |
| 3353 | S.Diag(Paren.Loc, diag::warn_redundant_parens_around_declarator) |
| 3354 | << ParenRange << FixItHint::CreateRemoval(Paren.Loc) |
| 3355 | << FixItHint::CreateRemoval(Paren.EndLoc); |
| 3356 | return; |
| 3357 | } |
| 3358 | |
| 3359 | S.Diag(Paren.Loc, diag::warn_parens_disambiguated_as_variable_declaration) |
| 3360 | << ParenRange << D.getIdentifier(); |
| 3361 | auto *RD = T->getAsCXXRecordDecl(); |
| 3362 | if (!RD || !RD->hasDefinition() || RD->hasNonTrivialDestructor()) |
| 3363 | S.Diag(Paren.Loc, diag::note_raii_guard_add_name) |
| 3364 | << FixItHint::CreateInsertion(Paren.Loc, " varname") << T |
| 3365 | << D.getIdentifier(); |
| 3366 | |
| 3367 | |
| 3368 | S.Diag(D.getBeginLoc(), diag::note_function_style_cast_add_parentheses) |
| 3369 | << FixItHint::CreateInsertion(D.getBeginLoc(), "(") |
| 3370 | << FixItHint::CreateInsertion(S.getLocForEndOfToken(D.getEndLoc()), ")"); |
| 3371 | S.Diag(Paren.Loc, diag::note_remove_parens_for_variable_declaration) |
| 3372 | << FixItHint::CreateRemoval(Paren.Loc) |
| 3373 | << FixItHint::CreateRemoval(Paren.EndLoc); |
| 3374 | } |
| 3375 | |
| 3376 | |
| 3377 | |
| 3378 | |
| 3379 | |
| 3380 | static CallingConv getCCForDeclaratorChunk( |
| 3381 | Sema &S, Declarator &D, const ParsedAttributesView &AttrList, |
| 3382 | const DeclaratorChunk::FunctionTypeInfo &FTI, unsigned ChunkIndex) { |
| 3383 | assert(D.getTypeObject(ChunkIndex).Kind == DeclaratorChunk::Function); |
| 3384 | |
| 3385 | |
| 3386 | for (const ParsedAttr &AL : AttrList) { |
| 3387 | switch (AL.getKind()) { |
| 3388 | CALLING_CONV_ATTRS_CASELIST : { |
| 3389 | |
| 3390 | |
| 3391 | |
| 3392 | CallingConv CC; |
| 3393 | if (!S.CheckCallingConvAttr(AL, CC) && |
| 3394 | (!FTI.isVariadic || supportsVariadicCall(CC))) { |
| 3395 | return CC; |
| 3396 | } |
| 3397 | break; |
| 3398 | } |
| 3399 | |
| 3400 | default: |
| 3401 | break; |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | bool IsCXXInstanceMethod = false; |
| 3406 | |
| 3407 | if (S.getLangOpts().CPlusPlus) { |
| 3408 | |
| 3409 | |
| 3410 | |
| 3411 | unsigned I = ChunkIndex; |
| 3412 | bool FoundNonParen = false; |
| 3413 | while (I && !FoundNonParen) { |
| 3414 | --I; |
| 3415 | if (D.getTypeObject(I).Kind != DeclaratorChunk::Paren) |
| 3416 | FoundNonParen = true; |
| 3417 | } |
| 3418 | |
| 3419 | if (FoundNonParen) { |
| 3420 | |
| 3421 | |
| 3422 | IsCXXInstanceMethod = |
| 3423 | D.getTypeObject(I).Kind == DeclaratorChunk::MemberPointer; |
| 3424 | } else if (D.getContext() == DeclaratorContext::LambdaExprContext) { |
| 3425 | |
| 3426 | |
| 3427 | IsCXXInstanceMethod = true; |
| 3428 | } else { |
| 3429 | |
| 3430 | assert(D.isFunctionDeclarator()); |
| 3431 | |
| 3432 | |
| 3433 | |
| 3434 | IsCXXInstanceMethod = |
| 3435 | D.isFirstDeclarationOfMember() && |
| 3436 | D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef && |
| 3437 | !D.isStaticMember(); |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | CallingConv CC = S.Context.getDefaultCallingConvention(FTI.isVariadic, |
| 3442 | IsCXXInstanceMethod); |
| 3443 | |
| 3444 | |
| 3445 | |
| 3446 | |
| 3447 | |
| 3448 | if (S.getLangOpts().OpenCL) { |
| 3449 | for (const ParsedAttr &AL : D.getDeclSpec().getAttributes()) { |
| 3450 | if (AL.getKind() == ParsedAttr::AT_OpenCLKernel) { |
| 3451 | CC = CC_OpenCLKernel; |
| 3452 | break; |
| 3453 | } |
| 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | return CC; |
| 3458 | } |
| 3459 | |
| 3460 | namespace { |
| 3461 | |
| 3462 | |
| 3463 | enum class SimplePointerKind { |
| 3464 | Pointer, |
| 3465 | BlockPointer, |
| 3466 | MemberPointer, |
| 3467 | Array, |
| 3468 | }; |
| 3469 | } |
| 3470 | |
| 3471 | IdentifierInfo *Sema::getNullabilityKeyword(NullabilityKind nullability) { |
| 3472 | switch (nullability) { |
| 3473 | case NullabilityKind::NonNull: |
| 3474 | if (!Ident__Nonnull) |
| 3475 | Ident__Nonnull = PP.getIdentifierInfo("_Nonnull"); |
| 3476 | return Ident__Nonnull; |
| 3477 | |
| 3478 | case NullabilityKind::Nullable: |
| 3479 | if (!Ident__Nullable) |
| 3480 | Ident__Nullable = PP.getIdentifierInfo("_Nullable"); |
| 3481 | return Ident__Nullable; |
| 3482 | |
| 3483 | case NullabilityKind::Unspecified: |
| 3484 | if (!Ident__Null_unspecified) |
| 3485 | Ident__Null_unspecified = PP.getIdentifierInfo("_Null_unspecified"); |
| 3486 | return Ident__Null_unspecified; |
| 3487 | } |
| 3488 | llvm_unreachable("Unknown nullability kind."); |
| 3489 | } |
| 3490 | |
| 3491 | |
| 3492 | IdentifierInfo *Sema::getNSErrorIdent() { |
| 3493 | if (!Ident_NSError) |
| 3494 | Ident_NSError = PP.getIdentifierInfo("NSError"); |
| 3495 | |
| 3496 | return Ident_NSError; |
| 3497 | } |
| 3498 | |
| 3499 | |
| 3500 | |
| 3501 | static bool hasNullabilityAttr(const ParsedAttributesView &attrs) { |
| 3502 | for (const ParsedAttr &AL : attrs) { |
| 3503 | if (AL.getKind() == ParsedAttr::AT_TypeNonNull || |
| 3504 | AL.getKind() == ParsedAttr::AT_TypeNullable || |
| 3505 | AL.getKind() == ParsedAttr::AT_TypeNullUnspecified) |
| 3506 | return true; |
| 3507 | } |
| 3508 | |
| 3509 | return false; |
| 3510 | } |
| 3511 | |
| 3512 | namespace { |
| 3513 | |
| 3514 | enum class PointerDeclaratorKind { |
| 3515 | |
| 3516 | NonPointer, |
| 3517 | |
| 3518 | SingleLevelPointer, |
| 3519 | |
| 3520 | MultiLevelPointer, |
| 3521 | |
| 3522 | MaybePointerToCFRef, |
| 3523 | |
| 3524 | CFErrorRefPointer, |
| 3525 | |
| 3526 | NSErrorPointerPointer, |
| 3527 | }; |
| 3528 | |
| 3529 | |
| 3530 | |
| 3531 | |
| 3532 | enum class PointerWrappingDeclaratorKind { |
| 3533 | |
| 3534 | None = -1, |
| 3535 | |
| 3536 | Array = 0, |
| 3537 | |
| 3538 | Reference = 1 |
| 3539 | }; |
| 3540 | } |
| 3541 | |
| 3542 | |
| 3543 | |
| 3544 | |
| 3545 | |
| 3546 | static PointerDeclaratorKind |
| 3547 | classifyPointerDeclarator(Sema &S, QualType type, Declarator &declarator, |
| 3548 | PointerWrappingDeclaratorKind &wrappingKind) { |
| 3549 | unsigned numNormalPointers = 0; |
| 3550 | |
| 3551 | |
| 3552 | if (type->isDependentType()) |
| 3553 | return PointerDeclaratorKind::NonPointer; |
| 3554 | |
| 3555 | |
| 3556 | for (unsigned i = 0, n = declarator.getNumTypeObjects(); i != n; ++i) { |
| 3557 | DeclaratorChunk &chunk = declarator.getTypeObject(i); |
| 3558 | switch (chunk.Kind) { |
| 3559 | case DeclaratorChunk::Array: |
| 3560 | if (numNormalPointers == 0) |
| 3561 | wrappingKind = PointerWrappingDeclaratorKind::Array; |
| 3562 | break; |
| 3563 | |
| 3564 | case DeclaratorChunk::Function: |
| 3565 | case DeclaratorChunk::Pipe: |
| 3566 | break; |
| 3567 | |
| 3568 | case DeclaratorChunk::BlockPointer: |
| 3569 | case DeclaratorChunk::MemberPointer: |
| 3570 | return numNormalPointers > 0 ? PointerDeclaratorKind::MultiLevelPointer |
| 3571 | : PointerDeclaratorKind::SingleLevelPointer; |
| 3572 | |
| 3573 | case DeclaratorChunk::Paren: |
| 3574 | break; |
| 3575 | |
| 3576 | case DeclaratorChunk::Reference: |
| 3577 | if (numNormalPointers == 0) |
| 3578 | wrappingKind = PointerWrappingDeclaratorKind::Reference; |
| 3579 | break; |
| 3580 | |
| 3581 | case DeclaratorChunk::Pointer: |
| 3582 | ++numNormalPointers; |
| 3583 | if (numNormalPointers > 2) |
| 3584 | return PointerDeclaratorKind::MultiLevelPointer; |
| 3585 | break; |
| 3586 | } |
| 3587 | } |
| 3588 | |
| 3589 | |
| 3590 | unsigned numTypeSpecifierPointers = 0; |
| 3591 | do { |
| 3592 | |
| 3593 | if (auto ptrType = type->getAs<PointerType>()) { |
| 3594 | ++numNormalPointers; |
| 3595 | |
| 3596 | if (numNormalPointers > 2) |
| 3597 | return PointerDeclaratorKind::MultiLevelPointer; |
| 3598 | |
| 3599 | type = ptrType->getPointeeType(); |
| 3600 | ++numTypeSpecifierPointers; |
| 3601 | continue; |
| 3602 | } |
| 3603 | |
| 3604 | |
| 3605 | if (type->getAs<BlockPointerType>()) { |
| 3606 | return numNormalPointers > 0 ? PointerDeclaratorKind::MultiLevelPointer |
| 3607 | : PointerDeclaratorKind::SingleLevelPointer; |
| 3608 | } |
| 3609 | |
| 3610 | |
| 3611 | if (type->getAs<MemberPointerType>()) { |
| 3612 | return numNormalPointers > 0 ? PointerDeclaratorKind::MultiLevelPointer |
| 3613 | : PointerDeclaratorKind::SingleLevelPointer; |
| 3614 | } |
| 3615 | |
| 3616 | |
| 3617 | if (auto objcObjectPtr = type->getAs<ObjCObjectPointerType>()) { |
| 3618 | ++numNormalPointers; |
| 3619 | ++numTypeSpecifierPointers; |
| 3620 | |
| 3621 | |
| 3622 | if (auto objcClassDecl = objcObjectPtr->getInterfaceDecl()) { |
| 3623 | if (objcClassDecl->getIdentifier() == S.getNSErrorIdent() && |
| 3624 | numNormalPointers == 2 && numTypeSpecifierPointers < 2) { |
| 3625 | return PointerDeclaratorKind::NSErrorPointerPointer; |
| 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | break; |
| 3630 | } |
| 3631 | |
| 3632 | |
| 3633 | if (auto objcClass = type->getAs<ObjCInterfaceType>()) { |
| 3634 | if (objcClass->getInterface()->getIdentifier() == S.getNSErrorIdent()) { |
| 3635 | if (numNormalPointers == 2 && numTypeSpecifierPointers < 2) |
| 3636 | return PointerDeclaratorKind::NSErrorPointerPointer; |
| 3637 | } |
| 3638 | |
| 3639 | break; |
| 3640 | } |
| 3641 | |
| 3642 | |
| 3643 | if (numNormalPointers == 0) |
| 3644 | return PointerDeclaratorKind::NonPointer; |
| 3645 | |
| 3646 | if (auto recordType = type->getAs<RecordType>()) { |
| 3647 | RecordDecl *recordDecl = recordType->getDecl(); |
| 3648 | |
| 3649 | bool isCFError = false; |
| 3650 | if (S.CFError) { |
| 3651 | |
| 3652 | isCFError = (S.CFError == recordDecl); |
| 3653 | } else { |
| 3654 | |
| 3655 | |
| 3656 | |
| 3657 | |
| 3658 | if (recordDecl->getTagKind() == TTK_Struct && numNormalPointers > 0) { |
| 3659 | IdentifierInfo *bridgedType = nullptr; |
| 3660 | if (auto bridgeAttr = recordDecl->getAttr<ObjCBridgeAttr>()) |
| 3661 | bridgedType = bridgeAttr->getBridgedType(); |
| 3662 | else if (auto bridgeAttr = |
| 3663 | recordDecl->getAttr<ObjCBridgeMutableAttr>()) |
| 3664 | bridgedType = bridgeAttr->getBridgedType(); |
| 3665 | |
| 3666 | if (bridgedType == S.getNSErrorIdent()) { |
| 3667 | S.CFError = recordDecl; |
| 3668 | isCFError = true; |
| 3669 | } |
| 3670 | } |
| 3671 | } |
| 3672 | |
| 3673 | |
| 3674 | if (isCFError && numNormalPointers == 2 && numTypeSpecifierPointers < 2) { |
| 3675 | return PointerDeclaratorKind::CFErrorRefPointer; |
| 3676 | } |
| 3677 | break; |
| 3678 | } |
| 3679 | |
| 3680 | break; |
| 3681 | } while (true); |
| 3682 | |
| 3683 | switch (numNormalPointers) { |
| 3684 | case 0: |
| 3685 | return PointerDeclaratorKind::NonPointer; |
| 3686 | |
| 3687 | case 1: |
| 3688 | return PointerDeclaratorKind::SingleLevelPointer; |
| 3689 | |
| 3690 | case 2: |
| 3691 | return PointerDeclaratorKind::MaybePointerToCFRef; |
| 3692 | |
| 3693 | default: |
| 3694 | return PointerDeclaratorKind::MultiLevelPointer; |
| 3695 | } |
| 3696 | } |
| 3697 | |
| 3698 | static FileID getNullabilityCompletenessCheckFileID(Sema &S, |
| 3699 | SourceLocation loc) { |
| 3700 | |
| 3701 | |
| 3702 | for (DeclContext *ctx = S.CurContext; ctx; ctx = ctx->getParent()) { |
| 3703 | if (ctx->isFunctionOrMethod()) |
| 3704 | return FileID(); |
| 3705 | |
| 3706 | if (ctx->isFileContext()) |
| 3707 | break; |
| 3708 | } |
| 3709 | |
| 3710 | |
| 3711 | loc = S.SourceMgr.getExpansionLoc(loc); |
| 3712 | FileID file = S.SourceMgr.getFileID(loc); |
| 3713 | if (file.isInvalid()) |
| 3714 | return FileID(); |
| 3715 | |
| 3716 | |
| 3717 | bool invalid = false; |
| 3718 | const SrcMgr::SLocEntry &sloc = S.SourceMgr.getSLocEntry(file, &invalid); |
| 3719 | if (invalid || !sloc.isFile()) |
| 3720 | return FileID(); |
| 3721 | |
| 3722 | |
| 3723 | |
| 3724 | const SrcMgr::FileInfo &fileInfo = sloc.getFile(); |
| 3725 | if (fileInfo.getIncludeLoc().isInvalid()) |
| 3726 | return FileID(); |
| 3727 | if (fileInfo.getFileCharacteristic() != SrcMgr::C_User && |
| 3728 | S.Diags.getSuppressSystemWarnings()) { |
| 3729 | return FileID(); |
| 3730 | } |
| 3731 | |
| 3732 | return file; |
| 3733 | } |
| 3734 | |
| 3735 | |
| 3736 | |
| 3737 | static void fixItNullability(Sema &S, DiagnosticBuilder &Diag, |
| 3738 | SourceLocation PointerLoc, |
| 3739 | NullabilityKind Nullability) { |
| 3740 | assert(PointerLoc.isValid()); |
| 3741 | if (PointerLoc.isMacroID()) |
| 3742 | return; |
| 3743 | |
| 3744 | SourceLocation FixItLoc = S.getLocForEndOfToken(PointerLoc); |
| 3745 | if (!FixItLoc.isValid() || FixItLoc == PointerLoc) |
| 3746 | return; |
| 3747 | |
| 3748 | const char *NextChar = S.SourceMgr.getCharacterData(FixItLoc); |
| 3749 | if (!NextChar) |
| 3750 | return; |
| 3751 | |
| 3752 | SmallString<32> InsertionTextBuf{" "}; |
| 3753 | InsertionTextBuf += getNullabilitySpelling(Nullability); |
| 3754 | InsertionTextBuf += " "; |
| 3755 | StringRef InsertionText = InsertionTextBuf.str(); |
| 3756 | |
| 3757 | if (isWhitespace(*NextChar)) { |
| 3758 | InsertionText = InsertionText.drop_back(); |
| 3759 | } else if (NextChar[-1] == '[') { |
| 3760 | if (NextChar[0] == ']') |
| 3761 | InsertionText = InsertionText.drop_back().drop_front(); |
| 3762 | else |
| 3763 | InsertionText = InsertionText.drop_front(); |
| 3764 | } else if (!isIdentifierBody(NextChar[0], ) && |
| 3765 | !isIdentifierBody(NextChar[-1], )) { |
| 3766 | InsertionText = InsertionText.drop_back().drop_front(); |
| 3767 | } |
| 3768 | |
| 3769 | Diag << FixItHint::CreateInsertion(FixItLoc, InsertionText); |
| 3770 | } |
| 3771 | |
| 3772 | static void emitNullabilityConsistencyWarning(Sema &S, |
| 3773 | SimplePointerKind PointerKind, |
| 3774 | SourceLocation PointerLoc, |
| 3775 | SourceLocation PointerEndLoc) { |
| 3776 | assert(PointerLoc.isValid()); |
| 3777 | |
| 3778 | if (PointerKind == SimplePointerKind::Array) { |
| 3779 | S.Diag(PointerLoc, diag::warn_nullability_missing_array); |
| 3780 | } else { |
| 3781 | S.Diag(PointerLoc, diag::warn_nullability_missing) |
| 3782 | << static_cast<unsigned>(PointerKind); |
| 3783 | } |
| 3784 | |
| 3785 | auto FixItLoc = PointerEndLoc.isValid() ? PointerEndLoc : PointerLoc; |
| 3786 | if (FixItLoc.isMacroID()) |
| 3787 | return; |
| 3788 | |
| 3789 | auto addFixIt = [&](NullabilityKind Nullability) { |
| 3790 | auto Diag = S.Diag(FixItLoc, diag::note_nullability_fix_it); |
| 3791 | Diag << static_cast<unsigned>(Nullability); |
| 3792 | Diag << static_cast<unsigned>(PointerKind); |
| 3793 | fixItNullability(S, Diag, FixItLoc, Nullability); |
| 3794 | }; |
| 3795 | addFixIt(NullabilityKind::Nullable); |
| 3796 | addFixIt(NullabilityKind::NonNull); |
| 3797 | } |
| 3798 | |
| 3799 | |
| 3800 | |
| 3801 | |
| 3802 | |
| 3803 | |
| 3804 | |
| 3805 | static void |
| 3806 | checkNullabilityConsistency(Sema &S, SimplePointerKind pointerKind, |
| 3807 | SourceLocation pointerLoc, |
| 3808 | SourceLocation pointerEndLoc = SourceLocation()) { |
| 3809 | |
| 3810 | FileID file = getNullabilityCompletenessCheckFileID(S, pointerLoc); |
| 3811 | if (file.isInvalid()) |
| 3812 | return; |
| 3813 | |
| 3814 | |
| 3815 | |
| 3816 | FileNullability &fileNullability = S.NullabilityMap[file]; |
| 3817 | if (!fileNullability.SawTypeNullability) { |
| 3818 | |
| 3819 | |
| 3820 | diag::kind diagKind; |
| 3821 | if (pointerKind == SimplePointerKind::Array) |
| 3822 | diagKind = diag::warn_nullability_missing_array; |
| 3823 | else |
| 3824 | diagKind = diag::warn_nullability_missing; |
| 3825 | |
| 3826 | if (fileNullability.PointerLoc.isInvalid() && |
| 3827 | !S.Context.getDiagnostics().isIgnored(diagKind, pointerLoc)) { |
| 3828 | fileNullability.PointerLoc = pointerLoc; |
| 3829 | fileNullability.PointerEndLoc = pointerEndLoc; |
| 3830 | fileNullability.PointerKind = static_cast<unsigned>(pointerKind); |
| 3831 | } |
| 3832 | |
| 3833 | return; |
| 3834 | } |
| 3835 | |
| 3836 | |
| 3837 | emitNullabilityConsistencyWarning(S, pointerKind, pointerLoc, pointerEndLoc); |
| 3838 | } |
| 3839 | |
| 3840 | |
| 3841 | |
| 3842 | |
| 3843 | |
| 3844 | |
| 3845 | |
| 3846 | |
| 3847 | static void recordNullabilitySeen(Sema &S, SourceLocation loc) { |
| 3848 | FileID file = getNullabilityCompletenessCheckFileID(S, loc); |
| 3849 | if (file.isInvalid()) |
| 3850 | return; |
| 3851 | |
| 3852 | FileNullability &fileNullability = S.NullabilityMap[file]; |
| 3853 | if (fileNullability.SawTypeNullability) |
| 3854 | return; |
| 3855 | fileNullability.SawTypeNullability = true; |
| 3856 | |
| 3857 | |
| 3858 | |
| 3859 | if (fileNullability.PointerLoc.isInvalid()) |
| 3860 | return; |
| 3861 | |
| 3862 | auto kind = static_cast<SimplePointerKind>(fileNullability.PointerKind); |
| 3863 | emitNullabilityConsistencyWarning(S, kind, fileNullability.PointerLoc, |
| 3864 | fileNullability.PointerEndLoc); |
| 3865 | } |
| 3866 | |
| 3867 | |
| 3868 | |
| 3869 | |
| 3870 | |
| 3871 | |
| 3872 | |
| 3873 | |
| 3874 | |
| 3875 | |
| 3876 | static bool hasOuterPointerLikeChunk(const Declarator &D, unsigned endIndex) { |
| 3877 | unsigned i = endIndex; |
| 3878 | while (i != 0) { |
| 3879 | |
| 3880 | --i; |
| 3881 | const DeclaratorChunk &DC = D.getTypeObject(i); |
| 3882 | switch (DC.Kind) { |
| 3883 | case DeclaratorChunk::Paren: |
| 3884 | break; |
| 3885 | case DeclaratorChunk::Array: |
| 3886 | case DeclaratorChunk::Pointer: |
| 3887 | case DeclaratorChunk::Reference: |
| 3888 | case DeclaratorChunk::MemberPointer: |
| 3889 | return true; |
| 3890 | case DeclaratorChunk::Function: |
| 3891 | case DeclaratorChunk::BlockPointer: |
| 3892 | case DeclaratorChunk::Pipe: |
| 3893 | |
| 3894 | break; |
| 3895 | } |
| 3896 | } |
| 3897 | return false; |
| 3898 | } |
| 3899 | |
| 3900 | static bool IsNoDerefableChunk(DeclaratorChunk Chunk) { |
| 3901 | return (Chunk.Kind == DeclaratorChunk::Pointer || |
| 3902 | Chunk.Kind == DeclaratorChunk::Array); |
| 3903 | } |
| 3904 | |
| 3905 | template<typename AttrT> |
| 3906 | static AttrT *createSimpleAttr(ASTContext &Ctx, ParsedAttr &Attr) { |
| 3907 | Attr.setUsedAsTypeAttr(); |
| 3908 | return ::new (Ctx) |
| 3909 | AttrT(Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex()); |
| 3910 | } |
| 3911 | |
| 3912 | static Attr *createNullabilityAttr(ASTContext &Ctx, ParsedAttr &Attr, |
| 3913 | NullabilityKind NK) { |
| 3914 | switch (NK) { |
| 3915 | case NullabilityKind::NonNull: |
| 3916 | return createSimpleAttr<TypeNonNullAttr>(Ctx, Attr); |
| 3917 | |
| 3918 | case NullabilityKind::Nullable: |
| 3919 | return createSimpleAttr<TypeNullableAttr>(Ctx, Attr); |
| 3920 | |
| 3921 | case NullabilityKind::Unspecified: |
| 3922 | return createSimpleAttr<TypeNullUnspecifiedAttr>(Ctx, Attr); |
| 3923 | } |
| 3924 | llvm_unreachable("unknown NullabilityKind"); |
| 3925 | } |
| 3926 | |
| 3927 | |
| 3928 | |
| 3929 | |
| 3930 | |
| 3931 | static bool DiagnoseMultipleAddrSpaceAttributes(Sema &S, LangAS ASOld, |
| 3932 | LangAS ASNew, |
| 3933 | SourceLocation AttrLoc) { |
| 3934 | if (ASOld != LangAS::Default) { |
| 3935 | if (ASOld != ASNew) { |
| 3936 | S.Diag(AttrLoc, diag::err_attribute_address_multiple_qualifiers); |
| 3937 | return true; |
| 3938 | } |
| 3939 | |
| 3940 | S.Diag(AttrLoc, |
| 3941 | diag::warn_attribute_address_multiple_identical_qualifiers); |
| 3942 | } |
| 3943 | return false; |
| 3944 | } |
| 3945 | |
| 3946 | static TypeSourceInfo * |
| 3947 | GetTypeSourceInfoForDeclarator(TypeProcessingState &State, |
| 3948 | QualType T, TypeSourceInfo *ReturnTypeInfo); |
| 3949 | |
| 3950 | static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, |
| 3951 | QualType declSpecType, |
| 3952 | TypeSourceInfo *TInfo) { |
| 3953 | |
| 3954 | |
| 3955 | QualType T = declSpecType; |
| 3956 | Declarator &D = state.getDeclarator(); |
| 3957 | Sema &S = state.getSema(); |
| 3958 | ASTContext &Context = S.Context; |
| 3959 | const LangOptions &LangOpts = S.getLangOpts(); |
| 3960 | |
| 3961 | |
| 3962 | DeclarationName Name; |
| 3963 | if (D.getIdentifier()) |
| 3964 | Name = D.getIdentifier(); |
| 3965 | |
| 3966 | |
| 3967 | bool IsTypedefName = |
| 3968 | D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef || |
| 3969 | D.getContext() == DeclaratorContext::AliasDeclContext || |
| 3970 | D.getContext() == DeclaratorContext::AliasTemplateContext; |
| 3971 | |
| 3972 | |
| 3973 | bool IsQualifiedFunction = T->isFunctionProtoType() && |
| 3974 | (!T->castAs<FunctionProtoType>()->getMethodQuals().empty() || |
| 3975 | T->castAs<FunctionProtoType>()->getRefQualifier() != RQ_None); |
| 3976 | |
| 3977 | |
| 3978 | |
| 3979 | |
| 3980 | |
| 3981 | if (auto *DT = T->getAs<DeducedType>()) { |
| 3982 | const AutoType *AT = T->getAs<AutoType>(); |
| 3983 | bool IsClassTemplateDeduction = isa<DeducedTemplateSpecializationType>(DT); |
| 3984 | if ((AT && AT->isDecltypeAuto()) || IsClassTemplateDeduction) { |
| 3985 | for (unsigned I = 0, E = D.getNumTypeObjects(); I != E; ++I) { |
| 3986 | unsigned Index = E - I - 1; |
| 3987 | DeclaratorChunk &DeclChunk = D.getTypeObject(Index); |
| 3988 | unsigned DiagId = IsClassTemplateDeduction |
| 3989 | ? diag::err_deduced_class_template_compound_type |
| 3990 | : diag::err_decltype_auto_compound_type; |
| 3991 | unsigned DiagKind = 0; |
| 3992 | switch (DeclChunk.Kind) { |
| 3993 | case DeclaratorChunk::Paren: |
| 3994 | |
| 3995 | if (IsClassTemplateDeduction) { |
| 3996 | DiagKind = 4; |
| 3997 | break; |
| 3998 | } |
| 3999 | continue; |
| 4000 | case DeclaratorChunk::Function: { |
| 4001 | if (IsClassTemplateDeduction) { |
| 4002 | DiagKind = 3; |
| 4003 | break; |
| 4004 | } |
| 4005 | unsigned FnIndex; |
| 4006 | if (D.isFunctionDeclarationContext() && |
| 4007 | D.isFunctionDeclarator(FnIndex) && FnIndex == Index) |
| 4008 | continue; |
| 4009 | DiagId = diag::err_decltype_auto_function_declarator_not_declaration; |
| 4010 | break; |
| 4011 | } |
| 4012 | case DeclaratorChunk::Pointer: |
| 4013 | case DeclaratorChunk::BlockPointer: |
| 4014 | case DeclaratorChunk::MemberPointer: |
| 4015 | DiagKind = 0; |
| 4016 | break; |
| 4017 | case DeclaratorChunk::Reference: |
| 4018 | DiagKind = 1; |
| 4019 | break; |
| 4020 | case DeclaratorChunk::Array: |
| 4021 | DiagKind = 2; |
| 4022 | break; |
| 4023 | case DeclaratorChunk::Pipe: |
| 4024 | break; |
| 4025 | } |
| 4026 | |
| 4027 | S.Diag(DeclChunk.Loc, DiagId) << DiagKind; |
| 4028 | D.setInvalidType(true); |
| 4029 | break; |
| 4030 | } |
| 4031 | } |
| 4032 | } |
| 4033 | |
| 4034 | |
| 4035 | Optional<NullabilityKind> inferNullability; |
| 4036 | bool inferNullabilityCS = false; |
| 4037 | bool inferNullabilityInnerOnly = false; |
| 4038 | bool inferNullabilityInnerOnlyComplete = false; |
| 4039 | |
| 4040 | |
| 4041 | bool inAssumeNonNullRegion = false; |
| 4042 | SourceLocation assumeNonNullLoc = S.PP.getPragmaAssumeNonNullLoc(); |
| 4043 | if (assumeNonNullLoc.isValid()) { |
| 4044 | inAssumeNonNullRegion = true; |
| 4045 | recordNullabilitySeen(S, assumeNonNullLoc); |
| 4046 | } |
| 4047 | |
| 4048 | |
| 4049 | enum { |
| 4050 | |
| 4051 | CAMN_No, |
| 4052 | |
| 4053 | |
| 4054 | CAMN_InnerPointers, |
| 4055 | |
| 4056 | |
| 4057 | CAMN_Yes |
| 4058 | } complainAboutMissingNullability = CAMN_No; |
| 4059 | unsigned NumPointersRemaining = 0; |
| 4060 | auto complainAboutInferringWithinChunk = PointerWrappingDeclaratorKind::None; |
| 4061 | |
| 4062 | if (IsTypedefName) { |
| 4063 | |
| 4064 | |
| 4065 | |
| 4066 | complainAboutMissingNullability = CAMN_InnerPointers; |
| 4067 | |
| 4068 | if (T->canHaveNullability() && |
| 4069 | !T->getNullability(S.Context)) { |
| 4070 | |
| 4071 | ++NumPointersRemaining; |
| 4072 | } |
| 4073 | |
| 4074 | for (unsigned i = 0, n = D.getNumTypeObjects(); i != n; ++i) { |
| 4075 | DeclaratorChunk &chunk = D.getTypeObject(i); |
| 4076 | switch (chunk.Kind) { |
| 4077 | case DeclaratorChunk::Array: |
| 4078 | case DeclaratorChunk::Function: |
| 4079 | case DeclaratorChunk::Pipe: |
| 4080 | break; |
| 4081 | |
| 4082 | case DeclaratorChunk::BlockPointer: |
| 4083 | case DeclaratorChunk::MemberPointer: |
| 4084 | ++NumPointersRemaining; |
| 4085 | break; |
| 4086 | |
| 4087 | case DeclaratorChunk::Paren: |
| 4088 | case DeclaratorChunk::Reference: |
| 4089 | continue; |
| 4090 | |
| 4091 | case DeclaratorChunk::Pointer: |
| 4092 | ++NumPointersRemaining; |
| 4093 | continue; |
| 4094 | } |
| 4095 | } |
| 4096 | } else { |
| 4097 | bool isFunctionOrMethod = false; |
| 4098 | switch (auto context = state.getDeclarator().getContext()) { |
| 4099 | case DeclaratorContext::ObjCParameterContext: |
| 4100 | case DeclaratorContext::ObjCResultContext: |
| 4101 | case DeclaratorContext::PrototypeContext: |
| 4102 | case DeclaratorContext::TrailingReturnContext: |
| 4103 | case DeclaratorContext::TrailingReturnVarContext: |
| 4104 | isFunctionOrMethod = true; |
| 4105 | LLVM_FALLTHROUGH; |
| 4106 | |
| 4107 | case DeclaratorContext::MemberContext: |
| 4108 | if (state.getDeclarator().isObjCIvar() && !isFunctionOrMethod) { |
| 4109 | complainAboutMissingNullability = CAMN_No; |
| 4110 | break; |
| 4111 | } |
| 4112 | |
| 4113 | |
| 4114 | if (state.getDeclarator().isObjCWeakProperty() && inAssumeNonNullRegion) { |
| 4115 | inferNullability = NullabilityKind::Nullable; |
| 4116 | break; |
| 4117 | } |
| 4118 | |
| 4119 | LLVM_FALLTHROUGH; |
| 4120 | |
| 4121 | case DeclaratorContext::FileContext: |
| 4122 | case DeclaratorContext::KNRTypeListContext: { |
| 4123 | complainAboutMissingNullability = CAMN_Yes; |
| 4124 | |
| 4125 | |
| 4126 | auto wrappingKind = PointerWrappingDeclaratorKind::None; |
| 4127 | switch (classifyPointerDeclarator(S, T, D, wrappingKind)) { |
| 4128 | case PointerDeclaratorKind::NonPointer: |
| 4129 | case PointerDeclaratorKind::MultiLevelPointer: |
| 4130 | |
| 4131 | break; |
| 4132 | |
| 4133 | case PointerDeclaratorKind::SingleLevelPointer: |
| 4134 | |
| 4135 | if (inAssumeNonNullRegion) { |
| 4136 | complainAboutInferringWithinChunk = wrappingKind; |
| 4137 | inferNullability = NullabilityKind::NonNull; |
| 4138 | inferNullabilityCS = |
| 4139 | (context == DeclaratorContext::ObjCParameterContext || |
| 4140 | context == DeclaratorContext::ObjCResultContext); |
| 4141 | } |
| 4142 | break; |
| 4143 | |
| 4144 | case PointerDeclaratorKind::CFErrorRefPointer: |
| 4145 | case PointerDeclaratorKind::NSErrorPointerPointer: |
| 4146 | |
| 4147 | |
| 4148 | if (isFunctionOrMethod && inAssumeNonNullRegion) |
| 4149 | inferNullability = NullabilityKind::Nullable; |
| 4150 | break; |
| 4151 | |
| 4152 | case PointerDeclaratorKind::MaybePointerToCFRef: |
| 4153 | if (isFunctionOrMethod) { |
| 4154 | |
| 4155 | |
| 4156 | |
| 4157 | auto hasCFReturnsAttr = |
| 4158 | [](const ParsedAttributesView &AttrList) -> bool { |
| 4159 | return AttrList.hasAttribute(ParsedAttr::AT_CFReturnsRetained) || |
| 4160 | AttrList.hasAttribute(ParsedAttr::AT_CFReturnsNotRetained); |
| 4161 | }; |
| 4162 | if (const auto *InnermostChunk = D.getInnermostNonParenChunk()) { |
| 4163 | if (hasCFReturnsAttr(D.getAttributes()) || |
| 4164 | hasCFReturnsAttr(InnermostChunk->getAttrs()) || |
| 4165 | hasCFReturnsAttr(D.getDeclSpec().getAttributes())) { |
| 4166 | inferNullability = NullabilityKind::Nullable; |
| 4167 | inferNullabilityInnerOnly = true; |
| 4168 | } |
| 4169 | } |
| 4170 | } |
| 4171 | break; |
| 4172 | } |
| 4173 | break; |
| 4174 | } |
| 4175 | |
| 4176 | case DeclaratorContext::ConversionIdContext: |
| 4177 | complainAboutMissingNullability = CAMN_Yes; |
| 4178 | break; |
| 4179 | |
| 4180 | case DeclaratorContext::AliasDeclContext: |
| 4181 | case DeclaratorContext::AliasTemplateContext: |
| 4182 | case DeclaratorContext::BlockContext: |
| 4183 | case DeclaratorContext::BlockLiteralContext: |
| 4184 | case DeclaratorContext::ConditionContext: |
| 4185 | case DeclaratorContext::CXXCatchContext: |
| 4186 | case DeclaratorContext::CXXNewContext: |
| 4187 | case DeclaratorContext::ForContext: |
| 4188 | case DeclaratorContext::InitStmtContext: |
| 4189 | case DeclaratorContext::LambdaExprContext: |
| 4190 | case DeclaratorContext::LambdaExprParameterContext: |
| 4191 | case DeclaratorContext::ObjCCatchContext: |
| 4192 | case DeclaratorContext::TemplateParamContext: |
| 4193 | case DeclaratorContext::TemplateArgContext: |
| 4194 | case DeclaratorContext::TemplateTypeArgContext: |
| 4195 | case DeclaratorContext::TypeNameContext: |
| 4196 | case DeclaratorContext::FunctionalCastContext: |
| 4197 | |
| 4198 | break; |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | |
| 4203 | auto isVaList = [&S](QualType T) -> bool { |
| 4204 | auto *typedefTy = T->getAs<TypedefType>(); |
| 4205 | if (!typedefTy) |
| 4206 | return false; |
| 4207 | TypedefDecl *vaListTypedef = S.Context.getBuiltinVaListDecl(); |
| 4208 | do { |
| 4209 | if (typedefTy->getDecl() == vaListTypedef) |
| 4210 | return true; |
| 4211 | if (auto *name = typedefTy->getDecl()->getIdentifier()) |
| 4212 | if (name->isStr("va_list")) |
| 4213 | return true; |
| 4214 | typedefTy = typedefTy->desugar()->getAs<TypedefType>(); |
| 4215 | } while (typedefTy); |
| 4216 | return false; |
| 4217 | }; |
| 4218 | |
| 4219 | |
| 4220 | |
| 4221 | auto inferPointerNullability = |
| 4222 | [&](SimplePointerKind pointerKind, SourceLocation pointerLoc, |
| 4223 | SourceLocation pointerEndLoc, |
| 4224 | ParsedAttributesView &attrs, AttributePool &Pool) -> ParsedAttr * { |
| 4225 | |
| 4226 | if (NumPointersRemaining > 0) |
| 4227 | --NumPointersRemaining; |
| 4228 | |
| 4229 | |
| 4230 | if (hasNullabilityAttr(attrs)) |
| 4231 | return nullptr; |
| 4232 | |
| 4233 | |
| 4234 | if (inferNullability && !inferNullabilityInnerOnlyComplete) { |
| 4235 | ParsedAttr::Syntax syntax = inferNullabilityCS |
| 4236 | ? ParsedAttr::AS_ContextSensitiveKeyword |
| 4237 | : ParsedAttr::AS_Keyword; |
| 4238 | ParsedAttr *nullabilityAttr = Pool.create( |
| 4239 | S.getNullabilityKeyword(*inferNullability), SourceRange(pointerLoc), |
| 4240 | nullptr, SourceLocation(), nullptr, 0, syntax); |
| 4241 | |
| 4242 | attrs.addAtEnd(nullabilityAttr); |
| 4243 | |
| 4244 | if (inferNullabilityCS) { |
| 4245 | state.getDeclarator().getMutableDeclSpec().getObjCQualifiers() |
| 4246 | ->setObjCDeclQualifier(ObjCDeclSpec::DQ_CSNullability); |
| 4247 | } |
| 4248 | |
| 4249 | if (pointerLoc.isValid() && |
| 4250 | complainAboutInferringWithinChunk != |
| 4251 | PointerWrappingDeclaratorKind::None) { |
| 4252 | auto Diag = |
| 4253 | S.Diag(pointerLoc, diag::warn_nullability_inferred_on_nested_type); |
| 4254 | Diag << static_cast<int>(complainAboutInferringWithinChunk); |
| 4255 | fixItNullability(S, Diag, pointerLoc, NullabilityKind::NonNull); |
| 4256 | } |
| 4257 | |
| 4258 | if (inferNullabilityInnerOnly) |
| 4259 | inferNullabilityInnerOnlyComplete = true; |
| 4260 | return nullabilityAttr; |
| 4261 | } |
| 4262 | |
| 4263 | |
| 4264 | |
| 4265 | switch (complainAboutMissingNullability) { |
| 4266 | case CAMN_No: |
| 4267 | break; |
| 4268 | |
| 4269 | case CAMN_InnerPointers: |
| 4270 | if (NumPointersRemaining == 0) |
| 4271 | break; |
| 4272 | LLVM_FALLTHROUGH; |
| 4273 | |
| 4274 | case CAMN_Yes: |
| 4275 | checkNullabilityConsistency(S, pointerKind, pointerLoc, pointerEndLoc); |
| 4276 | } |
| 4277 | return nullptr; |
| 4278 | }; |
| 4279 | |
| 4280 | |
| 4281 | |
| 4282 | if (S.CodeSynthesisContexts.empty()) { |
| 4283 | if (T->canHaveNullability() && |
| 4284 | !T->getNullability(S.Context)) { |
| 4285 | if (isVaList(T)) { |
| 4286 | |
| 4287 | if (NumPointersRemaining > 0) |
| 4288 | --NumPointersRemaining; |
| 4289 | } else { |
| 4290 | SimplePointerKind pointerKind = SimplePointerKind::Pointer; |
| 4291 | if (T->isBlockPointerType()) |
| 4292 | pointerKind = SimplePointerKind::BlockPointer; |
| 4293 | else if (T->isMemberPointerType()) |
| 4294 | pointerKind = SimplePointerKind::MemberPointer; |
| 4295 | |
| 4296 | if (auto *attr = inferPointerNullability( |
| 4297 | pointerKind, D.getDeclSpec().getTypeSpecTypeLoc(), |
| 4298 | D.getDeclSpec().getEndLoc(), |
| 4299 | D.getMutableDeclSpec().getAttributes(), |
| 4300 | D.getMutableDeclSpec().getAttributePool())) { |
| 4301 | T = state.getAttributedType( |
| 4302 | createNullabilityAttr(Context, *attr, *inferNullability), T, T); |
| 4303 | } |
| 4304 | } |
| 4305 | } |
| 4306 | |
| 4307 | if (complainAboutMissingNullability == CAMN_Yes && |
| 4308 | T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) && |
| 4309 | D.isPrototypeContext() && |
| 4310 | !hasOuterPointerLikeChunk(D, D.getNumTypeObjects())) { |
| 4311 | checkNullabilityConsistency(S, SimplePointerKind::Array, |
| 4312 | D.getDeclSpec().getTypeSpecTypeLoc()); |
| 4313 | } |
| 4314 | } |
| 4315 | |
| 4316 | bool ExpectNoDerefChunk = |
| 4317 | state.getCurrentAttributes().hasAttribute(ParsedAttr::AT_NoDeref); |
| 4318 | |
| 4319 | |
| 4320 | |
| 4321 | |
| 4322 | for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { |
| 4323 | unsigned chunkIndex = e - i - 1; |
| 4324 | state.setCurrentChunkIndex(chunkIndex); |
| 4325 | DeclaratorChunk &DeclType = D.getTypeObject(chunkIndex); |
| 4326 | IsQualifiedFunction &= DeclType.Kind == DeclaratorChunk::Paren; |
| 4327 | switch (DeclType.Kind) { |
| 4328 | case DeclaratorChunk::Paren: |
| 4329 | if (i == 0) |
| 4330 | warnAboutRedundantParens(S, D, T); |
| 4331 | T = S.BuildParenType(T); |
| 4332 | break; |
| 4333 | case DeclaratorChunk::BlockPointer: |
| 4334 | |
| 4335 | if (!LangOpts.Blocks) |
| 4336 | S.Diag(DeclType.Loc, diag::err_blocks_disable) << LangOpts.OpenCL; |
| 4337 | |
| 4338 | |
| 4339 | inferPointerNullability(SimplePointerKind::BlockPointer, DeclType.Loc, |
| 4340 | DeclType.EndLoc, DeclType.getAttrs(), |
| 4341 | state.getDeclarator().getAttributePool()); |
| 4342 | |
| 4343 | T = S.BuildBlockPointerType(T, D.getIdentifierLoc(), Name); |
| 4344 | if (DeclType.Cls.TypeQuals || LangOpts.OpenCL) { |
| 4345 | |
| 4346 | |
| 4347 | if (LangOpts.OpenCL) |
| 4348 | DeclType.Cls.TypeQuals |= DeclSpec::TQ_const; |
| 4349 | T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Cls.TypeQuals); |
| 4350 | } |
| 4351 | break; |
| 4352 | case DeclaratorChunk::Pointer: |
| 4353 | |
| 4354 | |
| 4355 | if (LangOpts.CPlusPlus && S.CheckDistantExceptionSpec(T)) { |
| 4356 | S.Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec); |
| 4357 | D.setInvalidType(true); |
| 4358 | |
| 4359 | } |
| 4360 | |
| 4361 | |
| 4362 | inferPointerNullability(SimplePointerKind::Pointer, DeclType.Loc, |
| 4363 | DeclType.EndLoc, DeclType.getAttrs(), |
| 4364 | state.getDeclarator().getAttributePool()); |
| 4365 | |
| 4366 | if (LangOpts.ObjC && T->getAs<ObjCObjectType>()) { |
| 4367 | T = Context.getObjCObjectPointerType(T); |
| 4368 | if (DeclType.Ptr.TypeQuals) |
| 4369 | T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Ptr.TypeQuals); |
| 4370 | break; |
| 4371 | } |
| 4372 | |
| 4373 | |
| 4374 | |
| 4375 | |
| 4376 | if (LangOpts.OpenCL) { |
| 4377 | if (T->isImageType() || T->isSamplerT() || T->isPipeType() || |
| 4378 | T->isBlockPointerType()) { |
| 4379 | S.Diag(D.getIdentifierLoc(), diag::err_opencl_pointer_to_type) << T; |
| 4380 | D.setInvalidType(true); |
| 4381 | } |
| 4382 | } |
| 4383 | |
| 4384 | T = S.BuildPointerType(T, DeclType.Loc, Name); |
| 4385 | if (DeclType.Ptr.TypeQuals) |
| 4386 | T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Ptr.TypeQuals); |
| 4387 | break; |
| 4388 | case DeclaratorChunk::Reference: { |
| 4389 | |
| 4390 | |
| 4391 | if (LangOpts.CPlusPlus && S.CheckDistantExceptionSpec(T)) { |
| 4392 | S.Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec); |
| 4393 | D.setInvalidType(true); |
| 4394 | |
| 4395 | } |
| 4396 | T = S.BuildReferenceType(T, DeclType.Ref.LValueRef, DeclType.Loc, Name); |
| 4397 | |
| 4398 | if (DeclType.Ref.HasRestrict) |
| 4399 | T = S.BuildQualifiedType(T, DeclType.Loc, Qualifiers::Restrict); |
| 4400 | break; |
| 4401 | } |
| 4402 | case DeclaratorChunk::Array: { |
| 4403 | |
| 4404 | |
| 4405 | if (LangOpts.CPlusPlus && S.CheckDistantExceptionSpec(T)) { |
| 4406 | S.Diag(D.getIdentifierLoc(), diag::err_distant_exception_spec); |
| 4407 | D.setInvalidType(true); |
| 4408 | |
| 4409 | } |
| 4410 | DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr; |
| 4411 | Expr *ArraySize = static_cast<Expr*>(ATI.NumElts); |
| 4412 | ArrayType::ArraySizeModifier ASM; |
| 4413 | if (ATI.isStar) |
| 4414 | ASM = ArrayType::Star; |
| 4415 | else if (ATI.hasStatic) |
| 4416 | ASM = ArrayType::Static; |
| 4417 | else |
| 4418 | ASM = ArrayType::Normal; |
| 4419 | if (ASM == ArrayType::Star && !D.isPrototypeContext()) { |
| 4420 | |
| 4421 | |
| 4422 | |
| 4423 | S.Diag(DeclType.Loc, diag::err_array_star_outside_prototype); |
| 4424 | ASM = ArrayType::Normal; |
| 4425 | D.setInvalidType(true); |
| 4426 | } |
| 4427 | |
| 4428 | |
| 4429 | |
| 4430 | |
| 4431 | if (ASM == ArrayType::Static || ATI.TypeQuals) { |
| 4432 | if (!(D.isPrototypeContext() || |
| 4433 | D.getContext() == DeclaratorContext::KNRTypeListContext)) { |
| 4434 | S.Diag(DeclType.Loc, diag::err_array_static_outside_prototype) << |
| 4435 | (ASM == ArrayType::Static ? "'static'" : "type qualifier"); |
| 4436 | |
| 4437 | if (ASM == ArrayType::Static) |
| 4438 | ASM = ArrayType::Normal; |
| 4439 | ATI.TypeQuals = 0; |
| 4440 | D.setInvalidType(true); |
| 4441 | } |
| 4442 | |
| 4443 | |
| 4444 | |
| 4445 | if (hasOuterPointerLikeChunk(D, chunkIndex)) { |
| 4446 | S.Diag(DeclType.Loc, diag::err_array_static_not_outermost) << |
| 4447 | (ASM == ArrayType::Static ? "'static'" : "type qualifier"); |
| 4448 | if (ASM == ArrayType::Static) |
| 4449 | ASM = ArrayType::Normal; |
| 4450 | ATI.TypeQuals = 0; |
| 4451 | D.setInvalidType(true); |
| 4452 | } |
| 4453 | } |
| 4454 | const AutoType *AT = T->getContainedAutoType(); |
| 4455 | |
| 4456 | |
| 4457 | if (AT && |
| 4458 | D.getContext() != DeclaratorContext::LambdaExprParameterContext) { |
| 4459 | |
| 4460 | if (!AT->isDecltypeAuto()) |
| 4461 | S.Diag(DeclType.Loc, diag::err_illegal_decl_array_of_auto) |
| 4462 | << getPrintableNameForEntity(Name) << T; |
| 4463 | T = QualType(); |
| 4464 | break; |
| 4465 | } |
| 4466 | |
| 4467 | |
| 4468 | |
| 4469 | if (complainAboutMissingNullability == CAMN_Yes && |
| 4470 | !hasNullabilityAttr(DeclType.getAttrs()) && |
| 4471 | ASM != ArrayType::Static && |
| 4472 | D.isPrototypeContext() && |
| 4473 | !hasOuterPointerLikeChunk(D, chunkIndex)) { |
| 4474 | checkNullabilityConsistency(S, SimplePointerKind::Array, DeclType.Loc); |
| 4475 | } |
| 4476 | |
| 4477 | T = S.BuildArrayType(T, ASM, ArraySize, ATI.TypeQuals, |
| 4478 | SourceRange(DeclType.Loc, DeclType.EndLoc), Name); |
| 4479 | break; |
| 4480 | } |
| 4481 | case DeclaratorChunk::Function: { |
| 4482 | |
| 4483 | |
| 4484 | |
| 4485 | const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; |
| 4486 | IsQualifiedFunction = |
| 4487 | FTI.hasMethodTypeQualifiers() || FTI.hasRefQualifier(); |
| 4488 | |
| 4489 | |
| 4490 | |
| 4491 | if (!D.isInvalidType()) { |
| 4492 | |
| 4493 | |
| 4494 | if (D.getDeclSpec().hasAutoTypeSpec() && |
| 4495 | !FTI.hasTrailingReturnType() && chunkIndex == 0) { |
| 4496 | if (!S.getLangOpts().CPlusPlus14) { |
| 4497 | S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(), |
| 4498 | D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto |
| 4499 | ? diag::err_auto_missing_trailing_return |
| 4500 | : diag::err_deduced_return_type); |
| 4501 | T = Context.IntTy; |
| 4502 | D.setInvalidType(true); |
| 4503 | } else { |
| 4504 | S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(), |
| 4505 | diag::warn_cxx11_compat_deduced_return_type); |
| 4506 | } |
| 4507 | } else if (FTI.hasTrailingReturnType()) { |
| 4508 | |
| 4509 | if (isa<ParenType>(T)) { |
| 4510 | S.Diag(D.getBeginLoc(), diag::err_trailing_return_in_parens) |
| 4511 | << T << D.getSourceRange(); |
| 4512 | D.setInvalidType(true); |
| 4513 | } else if (D.getName().getKind() == |
| 4514 | UnqualifiedIdKind::IK_DeductionGuideName) { |
| 4515 | if (T != Context.DependentTy) { |
| 4516 | S.Diag(D.getDeclSpec().getBeginLoc(), |
| 4517 | diag::err_deduction_guide_with_complex_decl) |
| 4518 | << D.getSourceRange(); |
| 4519 | D.setInvalidType(true); |
| 4520 | } |
| 4521 | } else if (D.getContext() != DeclaratorContext::LambdaExprContext && |
| 4522 | (T.hasQualifiers() || !isa<AutoType>(T) || |
| 4523 | cast<AutoType>(T)->getKeyword() != |
| 4524 | AutoTypeKeyword::Auto)) { |
| 4525 | S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(), |
| 4526 | diag::err_trailing_return_without_auto) |
| 4527 | << T << D.getDeclSpec().getSourceRange(); |
| 4528 | D.setInvalidType(true); |
| 4529 | } |
| 4530 | T = S.GetTypeFromParser(FTI.getTrailingReturnType(), &TInfo); |
| 4531 | if (T.isNull()) { |
| 4532 | |
| 4533 | T = Context.IntTy; |
| 4534 | D.setInvalidType(true); |
| 4535 | } |
| 4536 | } else { |
| 4537 | |
| 4538 | |
| 4539 | } |
| 4540 | } |
| 4541 | |
| 4542 | |
| 4543 | |
| 4544 | if (!D.isInvalidType() && (T->isArrayType() || T->isFunctionType()) && |
| 4545 | (D.getName().getKind() != |
| 4546 | UnqualifiedIdKind::IK_ConversionFunctionId)) { |
| 4547 | unsigned diagID = diag::err_func_returning_array_function; |
| 4548 | |
| 4549 | |
| 4550 | if (chunkIndex == 0 && |
| 4551 | D.getContext() == DeclaratorContext::BlockLiteralContext) |
| 4552 | diagID = diag::err_block_returning_array_function; |
| 4553 | S.Diag(DeclType.Loc, diagID) << T->isFunctionType() << T; |
| 4554 | T = Context.IntTy; |
| 4555 | D.setInvalidType(true); |
| 4556 | } |
| 4557 | |
| 4558 | |
| 4559 | |
| 4560 | if (T->isHalfType()) { |
| 4561 | if (S.getLangOpts().OpenCL) { |
| 4562 | if (!S.getOpenCLOptions().isEnabled("cl_khr_fp16")) { |
| 4563 | S.Diag(D.getIdentifierLoc(), diag::err_opencl_invalid_return) |
| 4564 | << T << 0 ; |
| 4565 | D.setInvalidType(true); |
| 4566 | } |
| 4567 | } else if (!S.getLangOpts().HalfArgsAndReturns) { |
| 4568 | S.Diag(D.getIdentifierLoc(), |
| 4569 | diag::err_parameters_retval_cannot_have_fp16_type) << 1; |
| 4570 | D.setInvalidType(true); |
| 4571 | } |
| 4572 | } |
| 4573 | |
| 4574 | if (LangOpts.OpenCL) { |
| 4575 | |
| 4576 | |
| 4577 | if (T->isBlockPointerType() || T->isImageType() || T->isSamplerT() || |
| 4578 | T->isPipeType()) { |
| 4579 | S.Diag(D.getIdentifierLoc(), diag::err_opencl_invalid_return) |
| 4580 | << T << 1 ; |
| 4581 | D.setInvalidType(true); |
| 4582 | } |
| 4583 | |
| 4584 | |
| 4585 | |
| 4586 | if (FTI.isVariadic && |
| 4587 | !(D.getIdentifier() && |
| 4588 | ((D.getIdentifier()->getName() == "printf" && |
| 4589 | (LangOpts.OpenCLCPlusPlus || LangOpts.OpenCLVersion >= 120)) || |
| 4590 | D.getIdentifier()->getName().startswith("__")))) { |
| 4591 | S.Diag(D.getIdentifierLoc(), diag::err_opencl_variadic_function); |
| 4592 | D.setInvalidType(true); |
| 4593 | } |
| 4594 | } |
| 4595 | |
| 4596 | |
| 4597 | |
| 4598 | if (T->isObjCObjectType()) { |
| 4599 | SourceLocation DiagLoc, FixitLoc; |
| 4600 | if (TInfo) { |
| 4601 | DiagLoc = TInfo->getTypeLoc().getBeginLoc(); |
| 4602 | FixitLoc = S.getLocForEndOfToken(TInfo->getTypeLoc().getEndLoc()); |
| 4603 | } else { |
| 4604 | DiagLoc = D.getDeclSpec().getTypeSpecTypeLoc(); |
| 4605 | FixitLoc = S.getLocForEndOfToken(D.getDeclSpec().getEndLoc()); |
| 4606 | } |
| 4607 | S.Diag(DiagLoc, diag::err_object_cannot_be_passed_returned_by_value) |
| 4608 | << 0 << T |
| 4609 | << FixItHint::CreateInsertion(FixitLoc, "*"); |
| 4610 | |
| 4611 | T = Context.getObjCObjectPointerType(T); |
| 4612 | if (TInfo) { |
| 4613 | TypeLocBuilder TLB; |
| 4614 | TLB.pushFullCopy(TInfo->getTypeLoc()); |
| 4615 | ObjCObjectPointerTypeLoc TLoc = TLB.push<ObjCObjectPointerTypeLoc>(T); |
| 4616 | TLoc.setStarLoc(FixitLoc); |
| 4617 | TInfo = TLB.getTypeSourceInfo(Context, T); |
| 4618 | } |
| 4619 | |
| 4620 | D.setInvalidType(true); |
| 4621 | } |
| 4622 | |
| 4623 | |
| 4624 | |
| 4625 | if ((T.getCVRQualifiers() || T->isAtomicType()) && |
| 4626 | !(S.getLangOpts().CPlusPlus && |
| 4627 | (T->isDependentType() || T->isRecordType()))) { |
| 4628 | if (T->isVoidType() && !S.getLangOpts().CPlusPlus && |
| 4629 | D.getFunctionDefinitionKind() == FDK_Definition) { |
| 4630 | |
| 4631 | |
| 4632 | |
| 4633 | S.Diag(DeclType.Loc, diag::err_func_returning_qualified_void) << T; |
| 4634 | } else |
| 4635 | diagnoseRedundantReturnTypeQualifiers(S, T, D, chunkIndex); |
| 4636 | } |
| 4637 | |
| 4638 | |
| 4639 | |
| 4640 | |
| 4641 | if (T.getQualifiers().hasObjCLifetime()) { |
| 4642 | SourceLocation AttrLoc; |
| 4643 | if (chunkIndex + 1 < D.getNumTypeObjects()) { |
| 4644 | DeclaratorChunk ReturnTypeChunk = D.getTypeObject(chunkIndex + 1); |
| 4645 | for (const ParsedAttr &AL : ReturnTypeChunk.getAttrs()) { |
| 4646 | if (AL.getKind() == ParsedAttr::AT_ObjCOwnership) { |
| 4647 | AttrLoc = AL.getLoc(); |
| 4648 | break; |
| 4649 | } |
| 4650 | } |
| 4651 | } |
| 4652 | if (AttrLoc.isInvalid()) { |
| 4653 | for (const ParsedAttr &AL : D.getDeclSpec().getAttributes()) { |
| 4654 | if (AL.getKind() == ParsedAttr::AT_ObjCOwnership) { |
| 4655 | AttrLoc = AL.getLoc(); |
| 4656 | break; |
| 4657 | } |
| 4658 | } |
| 4659 | } |
| 4660 | |
| 4661 | if (AttrLoc.isValid()) { |
| 4662 | |
| 4663 | |
| 4664 | |
| 4665 | if (AttrLoc.isMacroID()) |
| 4666 | AttrLoc = |
| 4667 | S.SourceMgr.getImmediateExpansionRange(AttrLoc).getBegin(); |
| 4668 | |
| 4669 | S.Diag(AttrLoc, diag::warn_arc_lifetime_result_type) |
| 4670 | << T.getQualifiers().getObjCLifetime(); |
| 4671 | } |
| 4672 | } |
| 4673 | |
| 4674 | if (LangOpts.CPlusPlus && D.getDeclSpec().hasTagDefinition()) { |
| 4675 | |
| 4676 | |
| 4677 | TagDecl *Tag = cast<TagDecl>(D.getDeclSpec().getRepAsDecl()); |
| 4678 | S.Diag(Tag->getLocation(), diag::err_type_defined_in_result_type) |
| 4679 | << Context.getTypeDeclType(Tag); |
| 4680 | } |
| 4681 | |
| 4682 | |
| 4683 | |
| 4684 | if (IsTypedefName && FTI.getExceptionSpecType() && !LangOpts.CPlusPlus17) |
| 4685 | S.Diag(FTI.getExceptionSpecLocBeg(), |
| 4686 | diag::err_exception_spec_in_typedef) |
| 4687 | << (D.getContext() == DeclaratorContext::AliasDeclContext || |
| 4688 | D.getContext() == DeclaratorContext::AliasTemplateContext); |
| 4689 | |
| 4690 | |
| 4691 | |
| 4692 | if (FTI.isAmbiguous) |
| 4693 | warnAboutAmbiguousFunction(S, D, DeclType, T); |
| 4694 | |
| 4695 | FunctionType::ExtInfo EI( |
| 4696 | getCCForDeclaratorChunk(S, D, DeclType.getAttrs(), FTI, chunkIndex)); |
| 4697 | |
| 4698 | if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus |
| 4699 | && !LangOpts.OpenCL) { |
| 4700 | |
| 4701 | T = Context.getFunctionNoProtoType(T, EI); |
| 4702 | } else { |
| 4703 | |
| 4704 | |
| 4705 | |
| 4706 | if (!FTI.NumParams && FTI.isVariadic && !LangOpts.CPlusPlus) |
| 4707 | if (!D.getAttributes().hasAttribute(ParsedAttr::AT_Overloadable)) |
| 4708 | S.Diag(FTI.getEllipsisLoc(), diag::err_ellipsis_first_param); |
| 4709 | |
| 4710 | if (FTI.NumParams && FTI.Params[0].Param == nullptr) { |
| 4711 | |
| 4712 | |
| 4713 | S.Diag(FTI.Params[0].IdentLoc, |
| 4714 | diag::err_ident_list_in_fn_declaration); |
| 4715 | D.setInvalidType(true); |
| 4716 | |
| 4717 | T = Context.getFunctionNoProtoType(T, EI); |
| 4718 | break; |
| 4719 | } |
| 4720 | |
| 4721 | FunctionProtoType::ExtProtoInfo EPI; |
| 4722 | EPI.ExtInfo = EI; |
| 4723 | EPI.Variadic = FTI.isVariadic; |
| 4724 | EPI.HasTrailingReturn = FTI.hasTrailingReturnType(); |
| 4725 | EPI.TypeQuals.addCVRUQualifiers( |
| 4726 | FTI.MethodQualifiers ? FTI.MethodQualifiers->getTypeQualifiers() |
| 4727 | : 0); |
| 4728 | EPI.RefQualifier = !FTI.hasRefQualifier()? RQ_None |
| 4729 | : FTI.RefQualifierIsLValueRef? RQ_LValue |
| 4730 | : RQ_RValue; |
| 4731 | |
| 4732 | |
| 4733 | |
| 4734 | SmallVector<QualType, 16> ParamTys; |
| 4735 | ParamTys.reserve(FTI.NumParams); |
| 4736 | |
| 4737 | SmallVector<FunctionProtoType::ExtParameterInfo, 16> |
| 4738 | ExtParameterInfos(FTI.NumParams); |
| 4739 | bool HasAnyInterestingExtParameterInfos = false; |
| 4740 | |
| 4741 | for (unsigned i = 0, e = FTI.NumParams; i != e; ++i) { |
| 4742 | ParmVarDecl *Param = cast<ParmVarDecl>(FTI.Params[i].Param); |
| 4743 | QualType ParamTy = Param->getType(); |
| 4744 | (0) . __assert_fail ("!ParamTy.isNull() && \"Couldn't parse type?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 4744, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!ParamTy.isNull() && "Couldn't parse type?"); |
| 4745 | |
| 4746 | |
| 4747 | |
| 4748 | |
| 4749 | if (ParamTy->isVoidType()) { |
| 4750 | |
| 4751 | |
| 4752 | |
| 4753 | if (FTI.NumParams != 1 || FTI.isVariadic) { |
| 4754 | S.Diag(DeclType.Loc, diag::err_void_only_param); |
| 4755 | ParamTy = Context.IntTy; |
| 4756 | Param->setType(ParamTy); |
| 4757 | } else if (FTI.Params[i].Ident) { |
| 4758 | |
| 4759 | S.Diag(FTI.Params[i].IdentLoc, diag::err_param_with_void_type); |
| 4760 | ParamTy = Context.IntTy; |
| 4761 | Param->setType(ParamTy); |
| 4762 | } else { |
| 4763 | |
| 4764 | if (ParamTy.hasQualifiers()) |
| 4765 | S.Diag(DeclType.Loc, diag::err_void_param_qualified); |
| 4766 | |
| 4767 | |
| 4768 | break; |
| 4769 | } |
| 4770 | } else if (ParamTy->isHalfType()) { |
| 4771 | |
| 4772 | |
| 4773 | if (S.getLangOpts().OpenCL) { |
| 4774 | if (!S.getOpenCLOptions().isEnabled("cl_khr_fp16")) { |
| 4775 | S.Diag(Param->getLocation(), |
| 4776 | diag::err_opencl_half_param) << ParamTy; |
| 4777 | D.setInvalidType(); |
| 4778 | Param->setInvalidDecl(); |
| 4779 | } |
| 4780 | } else if (!S.getLangOpts().HalfArgsAndReturns) { |
| 4781 | S.Diag(Param->getLocation(), |
| 4782 | diag::err_parameters_retval_cannot_have_fp16_type) << 0; |
| 4783 | D.setInvalidType(); |
| 4784 | } |
| 4785 | } else if (!FTI.hasPrototype) { |
| 4786 | if (ParamTy->isPromotableIntegerType()) { |
| 4787 | ParamTy = Context.getPromotedIntegerType(ParamTy); |
| 4788 | Param->setKNRPromoted(true); |
| 4789 | } else if (const BuiltinType* BTy = ParamTy->getAs<BuiltinType>()) { |
| 4790 | if (BTy->getKind() == BuiltinType::Float) { |
| 4791 | ParamTy = Context.DoubleTy; |
| 4792 | Param->setKNRPromoted(true); |
| 4793 | } |
| 4794 | } |
| 4795 | } |
| 4796 | |
| 4797 | if (LangOpts.ObjCAutoRefCount && Param->hasAttr<NSConsumedAttr>()) { |
| 4798 | ExtParameterInfos[i] = ExtParameterInfos[i].withIsConsumed(true); |
| 4799 | HasAnyInterestingExtParameterInfos = true; |
| 4800 | } |
| 4801 | |
| 4802 | if (auto attr = Param->getAttr<ParameterABIAttr>()) { |
| 4803 | ExtParameterInfos[i] = |
| 4804 | ExtParameterInfos[i].withABI(attr->getABI()); |
| 4805 | HasAnyInterestingExtParameterInfos = true; |
| 4806 | } |
| 4807 | |
| 4808 | if (Param->hasAttr<PassObjectSizeAttr>()) { |
| 4809 | ExtParameterInfos[i] = ExtParameterInfos[i].withHasPassObjectSize(); |
| 4810 | HasAnyInterestingExtParameterInfos = true; |
| 4811 | } |
| 4812 | |
| 4813 | if (Param->hasAttr<NoEscapeAttr>()) { |
| 4814 | ExtParameterInfos[i] = ExtParameterInfos[i].withIsNoEscape(true); |
| 4815 | HasAnyInterestingExtParameterInfos = true; |
| 4816 | } |
| 4817 | |
| 4818 | ParamTys.push_back(ParamTy); |
| 4819 | } |
| 4820 | |
| 4821 | if (HasAnyInterestingExtParameterInfos) { |
| 4822 | EPI.ExtParameterInfos = ExtParameterInfos.data(); |
| 4823 | checkExtParameterInfos(S, ParamTys, EPI, |
| 4824 | [&](unsigned i) { return FTI.Params[i].Param->getLocation(); }); |
| 4825 | } |
| 4826 | |
| 4827 | SmallVector<QualType, 4> Exceptions; |
| 4828 | SmallVector<ParsedType, 2> DynamicExceptions; |
| 4829 | SmallVector<SourceRange, 2> DynamicExceptionRanges; |
| 4830 | Expr *NoexceptExpr = nullptr; |
| 4831 | |
| 4832 | if (FTI.getExceptionSpecType() == EST_Dynamic) { |
| 4833 | |
| 4834 | |
| 4835 | unsigned N = FTI.getNumExceptions(); |
| 4836 | DynamicExceptions.reserve(N); |
| 4837 | DynamicExceptionRanges.reserve(N); |
| 4838 | for (unsigned I = 0; I != N; ++I) { |
| 4839 | DynamicExceptions.push_back(FTI.Exceptions[I].Ty); |
| 4840 | DynamicExceptionRanges.push_back(FTI.Exceptions[I].Range); |
| 4841 | } |
| 4842 | } else if (isComputedNoexcept(FTI.getExceptionSpecType())) { |
| 4843 | NoexceptExpr = FTI.NoexceptExpr; |
| 4844 | } |
| 4845 | |
| 4846 | S.checkExceptionSpecification(D.isFunctionDeclarationContext(), |
| 4847 | FTI.getExceptionSpecType(), |
| 4848 | DynamicExceptions, |
| 4849 | DynamicExceptionRanges, |
| 4850 | NoexceptExpr, |
| 4851 | Exceptions, |
| 4852 | EPI.ExceptionSpec); |
| 4853 | |
| 4854 | |
| 4855 | |
| 4856 | auto IsClassMember = [&]() { |
| 4857 | return (!state.getDeclarator().getCXXScopeSpec().isEmpty() && |
| 4858 | state.getDeclarator() |
| 4859 | .getCXXScopeSpec() |
| 4860 | .getScopeRep() |
| 4861 | ->getKind() == NestedNameSpecifier::TypeSpec) || |
| 4862 | state.getDeclarator().getContext() == |
| 4863 | DeclaratorContext::MemberContext; |
| 4864 | }; |
| 4865 | |
| 4866 | if (state.getSema().getLangOpts().OpenCLCPlusPlus && IsClassMember()) { |
| 4867 | LangAS ASIdx = LangAS::Default; |
| 4868 | |
| 4869 | |
| 4870 | if (FTI.MethodQualifiers) |
| 4871 | for (ParsedAttr &attr : FTI.MethodQualifiers->getAttributes()) { |
| 4872 | LangAS ASIdxNew = attr.asOpenCLLangAS(); |
| 4873 | if (DiagnoseMultipleAddrSpaceAttributes(S, ASIdx, ASIdxNew, |
| 4874 | attr.getLoc())) |
| 4875 | D.setInvalidType(true); |
| 4876 | else |
| 4877 | ASIdx = ASIdxNew; |
| 4878 | } |
| 4879 | |
| 4880 | |
| 4881 | LangAS AS = |
| 4882 | (ASIdx == LangAS::Default ? LangAS::opencl_generic : ASIdx); |
| 4883 | EPI.TypeQuals.addAddressSpace(AS); |
| 4884 | } |
| 4885 | T = Context.getFunctionType(T, ParamTys, EPI); |
| 4886 | } |
| 4887 | break; |
| 4888 | } |
| 4889 | case DeclaratorChunk::MemberPointer: { |
| 4890 | |
| 4891 | CXXScopeSpec &SS = DeclType.Mem.Scope(); |
| 4892 | QualType ClsType; |
| 4893 | |
| 4894 | |
| 4895 | inferPointerNullability(SimplePointerKind::MemberPointer, DeclType.Loc, |
| 4896 | DeclType.EndLoc, DeclType.getAttrs(), |
| 4897 | state.getDeclarator().getAttributePool()); |
| 4898 | |
| 4899 | if (SS.isInvalid()) { |
| 4900 | |
| 4901 | D.setInvalidType(true); |
| 4902 | } else if (S.isDependentScopeSpecifier(SS) || |
| 4903 | dyn_cast_or_null<CXXRecordDecl>(S.computeDeclContext(SS))) { |
| 4904 | NestedNameSpecifier *NNS = SS.getScopeRep(); |
| 4905 | NestedNameSpecifier *NNSPrefix = NNS->getPrefix(); |
| 4906 | switch (NNS->getKind()) { |
| 4907 | case NestedNameSpecifier::Identifier: |
| 4908 | ClsType = Context.getDependentNameType(ETK_None, NNSPrefix, |
| 4909 | NNS->getAsIdentifier()); |
| 4910 | break; |
| 4911 | |
| 4912 | case NestedNameSpecifier::Namespace: |
| 4913 | case NestedNameSpecifier::NamespaceAlias: |
| 4914 | case NestedNameSpecifier::Global: |
| 4915 | case NestedNameSpecifier::Super: |
| 4916 | llvm_unreachable("Nested-name-specifier must name a type"); |
| 4917 | |
| 4918 | case NestedNameSpecifier::TypeSpec: |
| 4919 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4920 | ClsType = QualType(NNS->getAsType(), 0); |
| 4921 | |
| 4922 | |
| 4923 | |
| 4924 | |
| 4925 | |
| 4926 | if (NNSPrefix && isa<TemplateSpecializationType>(NNS->getAsType())) |
| 4927 | ClsType = Context.getElaboratedType(ETK_None, NNSPrefix, ClsType); |
| 4928 | break; |
| 4929 | } |
| 4930 | } else { |
| 4931 | S.Diag(DeclType.Mem.Scope().getBeginLoc(), |
| 4932 | diag::err_illegal_decl_mempointer_in_nonclass) |
| 4933 | << (D.getIdentifier() ? D.getIdentifier()->getName() : "type name") |
| 4934 | << DeclType.Mem.Scope().getRange(); |
| 4935 | D.setInvalidType(true); |
| 4936 | } |
| 4937 | |
| 4938 | if (!ClsType.isNull()) |
| 4939 | T = S.BuildMemberPointerType(T, ClsType, DeclType.Loc, |
| 4940 | D.getIdentifier()); |
| 4941 | if (T.isNull()) { |
| 4942 | T = Context.IntTy; |
| 4943 | D.setInvalidType(true); |
| 4944 | } else if (DeclType.Mem.TypeQuals) { |
| 4945 | T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Mem.TypeQuals); |
| 4946 | } |
| 4947 | break; |
| 4948 | } |
| 4949 | |
| 4950 | case DeclaratorChunk::Pipe: { |
| 4951 | T = S.BuildReadPipeType(T, DeclType.Loc); |
| 4952 | processTypeAttrs(state, T, TAL_DeclSpec, |
| 4953 | D.getMutableDeclSpec().getAttributes()); |
| 4954 | break; |
| 4955 | } |
| 4956 | } |
| 4957 | |
| 4958 | if (T.isNull()) { |
| 4959 | D.setInvalidType(true); |
| 4960 | T = Context.IntTy; |
| 4961 | } |
| 4962 | |
| 4963 | |
| 4964 | processTypeAttrs(state, T, TAL_DeclChunk, DeclType.getAttrs()); |
| 4965 | |
| 4966 | if (DeclType.Kind != DeclaratorChunk::Paren) { |
| 4967 | if (ExpectNoDerefChunk) { |
| 4968 | if (!IsNoDerefableChunk(DeclType)) |
| 4969 | S.Diag(DeclType.Loc, diag::warn_noderef_on_non_pointer_or_array); |
| 4970 | ExpectNoDerefChunk = false; |
| 4971 | } |
| 4972 | |
| 4973 | ExpectNoDerefChunk = state.didParseNoDeref(); |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | if (ExpectNoDerefChunk) |
| 4978 | S.Diag(state.getDeclarator().getBeginLoc(), |
| 4979 | diag::warn_noderef_on_non_pointer_or_array); |
| 4980 | |
| 4981 | |
| 4982 | |
| 4983 | |
| 4984 | |
| 4985 | |
| 4986 | |
| 4987 | |
| 4988 | |
| 4989 | if (!LangOpts.CPlusPlus && D.getFunctionDefinitionKind() == FDK_Declaration) { |
| 4990 | bool IsBlock = false; |
| 4991 | for (const DeclaratorChunk &DeclType : D.type_objects()) { |
| 4992 | switch (DeclType.Kind) { |
| 4993 | case DeclaratorChunk::BlockPointer: |
| 4994 | IsBlock = true; |
| 4995 | break; |
| 4996 | case DeclaratorChunk::Function: { |
| 4997 | const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; |
| 4998 | if (FTI.NumParams == 0 && !FTI.isVariadic) |
| 4999 | S.Diag(DeclType.Loc, diag::warn_strict_prototypes) |
| 5000 | << IsBlock |
| 5001 | << FixItHint::CreateInsertion(FTI.getRParenLoc(), "void"); |
| 5002 | IsBlock = false; |
| 5003 | break; |
| 5004 | } |
| 5005 | default: |
| 5006 | break; |
| 5007 | } |
| 5008 | } |
| 5009 | } |
| 5010 | |
| 5011 | (0) . __assert_fail ("!T.isNull() && \"T must not be null after this point\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 5011, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!T.isNull() && "T must not be null after this point"); |
| 5012 | |
| 5013 | if (LangOpts.CPlusPlus && T->isFunctionType()) { |
| 5014 | const FunctionProtoType *FnTy = T->getAs<FunctionProtoType>(); |
| 5015 | (0) . __assert_fail ("FnTy && \"Why oh why is there not a FunctionProtoType here?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 5015, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FnTy && "Why oh why is there not a FunctionProtoType here?"); |
| 5016 | |
| 5017 | |
| 5018 | |
| 5019 | |
| 5020 | |
| 5021 | |
| 5022 | |
| 5023 | |
| 5024 | |
| 5025 | enum { NonMember, Member, DeductionGuide } Kind = NonMember; |
| 5026 | if (D.getName().getKind() == UnqualifiedIdKind::IK_DeductionGuideName) |
| 5027 | Kind = DeductionGuide; |
| 5028 | else if (!D.getCXXScopeSpec().isSet()) { |
| 5029 | if ((D.getContext() == DeclaratorContext::MemberContext || |
| 5030 | D.getContext() == DeclaratorContext::LambdaExprContext) && |
| 5031 | !D.getDeclSpec().isFriendSpecified()) |
| 5032 | Kind = Member; |
| 5033 | } else { |
| 5034 | DeclContext *DC = S.computeDeclContext(D.getCXXScopeSpec()); |
| 5035 | if (!DC || DC->isRecord()) |
| 5036 | Kind = Member; |
| 5037 | } |
| 5038 | |
| 5039 | |
| 5040 | |
| 5041 | |
| 5042 | |
| 5043 | |
| 5044 | |
| 5045 | |
| 5046 | |
| 5047 | |
| 5048 | |
| 5049 | |
| 5050 | |
| 5051 | |
| 5052 | |
| 5053 | |
| 5054 | |
| 5055 | if (IsQualifiedFunction && |
| 5056 | !(Kind == Member && |
| 5057 | D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static) && |
| 5058 | !IsTypedefName && |
| 5059 | D.getContext() != DeclaratorContext::TemplateArgContext && |
| 5060 | D.getContext() != DeclaratorContext::TemplateTypeArgContext) { |
| 5061 | SourceLocation Loc = D.getBeginLoc(); |
| 5062 | SourceRange RemovalRange; |
| 5063 | unsigned I; |
| 5064 | if (D.isFunctionDeclarator(I)) { |
| 5065 | SmallVector<SourceLocation, 4> RemovalLocs; |
| 5066 | const DeclaratorChunk &Chunk = D.getTypeObject(I); |
| 5067 | assert(Chunk.Kind == DeclaratorChunk::Function); |
| 5068 | |
| 5069 | if (Chunk.Fun.hasRefQualifier()) |
| 5070 | RemovalLocs.push_back(Chunk.Fun.getRefQualifierLoc()); |
| 5071 | |
| 5072 | if (Chunk.Fun.hasMethodTypeQualifiers()) |
| 5073 | Chunk.Fun.MethodQualifiers->forEachQualifier( |
| 5074 | [&](DeclSpec::TQ TypeQual, StringRef QualName, |
| 5075 | SourceLocation SL) { RemovalLocs.push_back(SL); }); |
| 5076 | |
| 5077 | if (!RemovalLocs.empty()) { |
| 5078 | llvm::sort(RemovalLocs, |
| 5079 | BeforeThanCompare<SourceLocation>(S.getSourceManager())); |
| 5080 | RemovalRange = SourceRange(RemovalLocs.front(), RemovalLocs.back()); |
| 5081 | Loc = RemovalLocs.front(); |
| 5082 | } |
| 5083 | } |
| 5084 | |
| 5085 | S.Diag(Loc, diag::err_invalid_qualified_function_type) |
| 5086 | << Kind << D.isFunctionDeclarator() << T |
| 5087 | << getFunctionQualifiersAsString(FnTy) |
| 5088 | << FixItHint::CreateRemoval(RemovalRange); |
| 5089 | |
| 5090 | |
| 5091 | FunctionProtoType::ExtProtoInfo EPI = FnTy->getExtProtoInfo(); |
| 5092 | EPI.TypeQuals.removeCVRQualifiers(); |
| 5093 | EPI.RefQualifier = RQ_None; |
| 5094 | |
| 5095 | T = Context.getFunctionType(FnTy->getReturnType(), FnTy->getParamTypes(), |
| 5096 | EPI); |
| 5097 | |
| 5098 | for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { |
| 5099 | if (D.getTypeObject(i).Kind != DeclaratorChunk::Paren) |
| 5100 | break; |
| 5101 | T = S.BuildParenType(T); |
| 5102 | } |
| 5103 | } |
| 5104 | } |
| 5105 | |
| 5106 | |
| 5107 | processTypeAttrs(state, T, TAL_DeclName, D.getAttributes()); |
| 5108 | |
| 5109 | |
| 5110 | state.diagnoseIgnoredTypeAttrs(T); |
| 5111 | |
| 5112 | |
| 5113 | |
| 5114 | |
| 5115 | if (D.getDeclSpec().isConstexprSpecified() && T->isObjectType()) { |
| 5116 | T.addConst(); |
| 5117 | } |
| 5118 | |
| 5119 | |
| 5120 | |
| 5121 | if (D.hasEllipsis()) { |
| 5122 | |
| 5123 | |
| 5124 | |
| 5125 | |
| 5126 | switch (D.getContext()) { |
| 5127 | case DeclaratorContext::PrototypeContext: |
| 5128 | case DeclaratorContext::LambdaExprParameterContext: |
| 5129 | |
| 5130 | |
| 5131 | |
| 5132 | |
| 5133 | |
| 5134 | |
| 5135 | |
| 5136 | |
| 5137 | |
| 5138 | if (!T->containsUnexpandedParameterPack()) { |
| 5139 | S.Diag(D.getEllipsisLoc(), |
| 5140 | diag::err_function_parameter_pack_without_parameter_packs) |
| 5141 | << T << D.getSourceRange(); |
| 5142 | D.setEllipsisLoc(SourceLocation()); |
| 5143 | } else { |
| 5144 | T = Context.getPackExpansionType(T, None); |
| 5145 | } |
| 5146 | break; |
| 5147 | case DeclaratorContext::TemplateParamContext: |
| 5148 | |
| 5149 | |
| 5150 | |
| 5151 | |
| 5152 | |
| 5153 | |
| 5154 | |
| 5155 | |
| 5156 | if (T->containsUnexpandedParameterPack()) |
| 5157 | T = Context.getPackExpansionType(T, None); |
| 5158 | else |
| 5159 | S.Diag(D.getEllipsisLoc(), |
| 5160 | LangOpts.CPlusPlus11 |
| 5161 | ? diag::warn_cxx98_compat_variadic_templates |
| 5162 | : diag::ext_variadic_templates); |
| 5163 | break; |
| 5164 | |
| 5165 | case DeclaratorContext::FileContext: |
| 5166 | case DeclaratorContext::KNRTypeListContext: |
| 5167 | case DeclaratorContext::ObjCParameterContext: |
| 5168 | |
| 5169 | case DeclaratorContext::ObjCResultContext: |
| 5170 | |
| 5171 | case DeclaratorContext::TypeNameContext: |
| 5172 | case DeclaratorContext::FunctionalCastContext: |
| 5173 | case DeclaratorContext::CXXNewContext: |
| 5174 | case DeclaratorContext::AliasDeclContext: |
| 5175 | case DeclaratorContext::AliasTemplateContext: |
| 5176 | case DeclaratorContext::MemberContext: |
| 5177 | case DeclaratorContext::BlockContext: |
| 5178 | case DeclaratorContext::ForContext: |
| 5179 | case DeclaratorContext::InitStmtContext: |
| 5180 | case DeclaratorContext::ConditionContext: |
| 5181 | case DeclaratorContext::CXXCatchContext: |
| 5182 | case DeclaratorContext::ObjCCatchContext: |
| 5183 | case DeclaratorContext::BlockLiteralContext: |
| 5184 | case DeclaratorContext::LambdaExprContext: |
| 5185 | case DeclaratorContext::ConversionIdContext: |
| 5186 | case DeclaratorContext::TrailingReturnContext: |
| 5187 | case DeclaratorContext::TrailingReturnVarContext: |
| 5188 | case DeclaratorContext::TemplateArgContext: |
| 5189 | case DeclaratorContext::TemplateTypeArgContext: |
| 5190 | |
| 5191 | |
| 5192 | S.Diag(D.getEllipsisLoc(), |
| 5193 | diag::err_ellipsis_in_declarator_not_parameter); |
| 5194 | D.setEllipsisLoc(SourceLocation()); |
| 5195 | break; |
| 5196 | } |
| 5197 | } |
| 5198 | |
| 5199 | (0) . __assert_fail ("!T.isNull() && \"T must not be null at the end of this function\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 5199, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!T.isNull() && "T must not be null at the end of this function"); |
| 5200 | if (D.isInvalidType()) |
| 5201 | return Context.getTrivialTypeSourceInfo(T); |
| 5202 | |
| 5203 | return GetTypeSourceInfoForDeclarator(state, T, TInfo); |
| 5204 | } |
| 5205 | |
| 5206 | |
| 5207 | |
| 5208 | |
| 5209 | |
| 5210 | |
| 5211 | TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { |
| 5212 | |
| 5213 | |
| 5214 | |
| 5215 | TypeProcessingState state(*this, D); |
| 5216 | |
| 5217 | TypeSourceInfo *ReturnTypeInfo = nullptr; |
| 5218 | QualType T = GetDeclSpecTypeForDeclarator(state, ReturnTypeInfo); |
| 5219 | if (D.isPrototypeContext() && getLangOpts().ObjCAutoRefCount) |
| 5220 | inferARCWriteback(state, T); |
| 5221 | |
| 5222 | return GetFullTypeForDeclarator(state, T, ReturnTypeInfo); |
| 5223 | } |
| 5224 | |
| 5225 | static void transferARCOwnershipToDeclSpec(Sema &S, |
| 5226 | QualType &declSpecTy, |
| 5227 | Qualifiers::ObjCLifetime ownership) { |
| 5228 | if (declSpecTy->isObjCRetainableType() && |
| 5229 | declSpecTy.getObjCLifetime() == Qualifiers::OCL_None) { |
| 5230 | Qualifiers qs; |
| 5231 | qs.addObjCLifetime(ownership); |
| 5232 | declSpecTy = S.Context.getQualifiedType(declSpecTy, qs); |
| 5233 | } |
| 5234 | } |
| 5235 | |
| 5236 | static void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state, |
| 5237 | Qualifiers::ObjCLifetime ownership, |
| 5238 | unsigned chunkIndex) { |
| 5239 | Sema &S = state.getSema(); |
| 5240 | Declarator &D = state.getDeclarator(); |
| 5241 | |
| 5242 | |
| 5243 | DeclaratorChunk &chunk = D.getTypeObject(chunkIndex); |
| 5244 | if (chunk.getAttrs().hasAttribute(ParsedAttr::AT_ObjCOwnership)) |
| 5245 | return; |
| 5246 | |
| 5247 | const char *attrStr = nullptr; |
| 5248 | switch (ownership) { |
| 5249 | case Qualifiers::OCL_None: llvm_unreachable("no ownership!"); |
| 5250 | case Qualifiers::OCL_ExplicitNone: attrStr = "none"; break; |
| 5251 | case Qualifiers::OCL_Strong: attrStr = "strong"; break; |
| 5252 | case Qualifiers::OCL_Weak: attrStr = "weak"; break; |
| 5253 | case Qualifiers::OCL_Autoreleasing: attrStr = "autoreleasing"; break; |
| 5254 | } |
| 5255 | |
| 5256 | IdentifierLoc *Arg = new (S.Context) IdentifierLoc; |
| 5257 | Arg->Ident = &S.Context.Idents.get(attrStr); |
| 5258 | Arg->Loc = SourceLocation(); |
| 5259 | |
| 5260 | ArgsUnion Args(Arg); |
| 5261 | |
| 5262 | |
| 5263 | |
| 5264 | ParsedAttr *attr = D.getAttributePool().create( |
| 5265 | &S.Context.Idents.get("objc_ownership"), SourceLocation(), |
| 5266 | nullptr, SourceLocation(), |
| 5267 | &Args, 1, ParsedAttr::AS_GNU); |
| 5268 | chunk.getAttrs().addAtEnd(attr); |
| 5269 | |
| 5270 | } |
| 5271 | |
| 5272 | |
| 5273 | static void transferARCOwnership(TypeProcessingState &state, |
| 5274 | QualType &declSpecTy, |
| 5275 | Qualifiers::ObjCLifetime ownership) { |
| 5276 | Sema &S = state.getSema(); |
| 5277 | Declarator &D = state.getDeclarator(); |
| 5278 | |
| 5279 | int inner = -1; |
| 5280 | bool hasIndirection = false; |
| 5281 | for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { |
| 5282 | DeclaratorChunk &chunk = D.getTypeObject(i); |
| 5283 | switch (chunk.Kind) { |
| 5284 | case DeclaratorChunk::Paren: |
| 5285 | |
| 5286 | break; |
| 5287 | |
| 5288 | case DeclaratorChunk::Array: |
| 5289 | case DeclaratorChunk::Reference: |
| 5290 | case DeclaratorChunk::Pointer: |
| 5291 | if (inner != -1) |
| 5292 | hasIndirection = true; |
| 5293 | inner = i; |
| 5294 | break; |
| 5295 | |
| 5296 | case DeclaratorChunk::BlockPointer: |
| 5297 | if (inner != -1) |
| 5298 | transferARCOwnershipToDeclaratorChunk(state, ownership, i); |
| 5299 | return; |
| 5300 | |
| 5301 | case DeclaratorChunk::Function: |
| 5302 | case DeclaratorChunk::MemberPointer: |
| 5303 | case DeclaratorChunk::Pipe: |
| 5304 | return; |
| 5305 | } |
| 5306 | } |
| 5307 | |
| 5308 | if (inner == -1) |
| 5309 | return; |
| 5310 | |
| 5311 | DeclaratorChunk &chunk = D.getTypeObject(inner); |
| 5312 | if (chunk.Kind == DeclaratorChunk::Pointer) { |
| 5313 | if (declSpecTy->isObjCRetainableType()) |
| 5314 | return transferARCOwnershipToDeclSpec(S, declSpecTy, ownership); |
| 5315 | if (declSpecTy->isObjCObjectType() && hasIndirection) |
| 5316 | return transferARCOwnershipToDeclaratorChunk(state, ownership, inner); |
| 5317 | } else { |
| 5318 | assert(chunk.Kind == DeclaratorChunk::Array || |
| 5319 | chunk.Kind == DeclaratorChunk::Reference); |
| 5320 | return transferARCOwnershipToDeclSpec(S, declSpecTy, ownership); |
| 5321 | } |
| 5322 | } |
| 5323 | |
| 5324 | TypeSourceInfo *Sema::GetTypeForDeclaratorCast(Declarator &D, QualType FromTy) { |
| 5325 | TypeProcessingState state(*this, D); |
| 5326 | |
| 5327 | TypeSourceInfo *ReturnTypeInfo = nullptr; |
| 5328 | QualType declSpecTy = GetDeclSpecTypeForDeclarator(state, ReturnTypeInfo); |
| 5329 | |
| 5330 | if (getLangOpts().ObjC) { |
| 5331 | Qualifiers::ObjCLifetime ownership = Context.getInnerObjCOwnership(FromTy); |
| 5332 | if (ownership != Qualifiers::OCL_None) |
| 5333 | transferARCOwnership(state, declSpecTy, ownership); |
| 5334 | } |
| 5335 | |
| 5336 | return GetFullTypeForDeclarator(state, declSpecTy, ReturnTypeInfo); |
| 5337 | } |
| 5338 | |
| 5339 | static void fillAttributedTypeLoc(AttributedTypeLoc TL, |
| 5340 | TypeProcessingState &State) { |
| 5341 | TL.setAttr(State.takeAttrForAttributedType(TL.getTypePtr())); |
| 5342 | } |
| 5343 | |
| 5344 | namespace { |
| 5345 | class TypeSpecLocFiller : public TypeLocVisitor<TypeSpecLocFiller> { |
| 5346 | ASTContext &Context; |
| 5347 | TypeProcessingState &State; |
| 5348 | const DeclSpec &DS; |
| 5349 | |
| 5350 | public: |
| 5351 | TypeSpecLocFiller(ASTContext &Context, TypeProcessingState &State, |
| 5352 | const DeclSpec &DS) |
| 5353 | : Context(Context), State(State), DS(DS) {} |
| 5354 | |
| 5355 | void VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 5356 | Visit(TL.getModifiedLoc()); |
| 5357 | fillAttributedTypeLoc(TL, State); |
| 5358 | } |
| 5359 | void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 5360 | Visit(TL.getUnqualifiedLoc()); |
| 5361 | } |
| 5362 | void VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 5363 | TL.setNameLoc(DS.getTypeSpecTypeLoc()); |
| 5364 | } |
| 5365 | void VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 5366 | TL.setNameLoc(DS.getTypeSpecTypeLoc()); |
| 5367 | |
| 5368 | |
| 5369 | |
| 5370 | TL.setNameEndLoc(DS.getEndLoc()); |
| 5371 | } |
| 5372 | void VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 5373 | TypeSourceInfo *RepTInfo = nullptr; |
| 5374 | Sema::GetTypeFromParser(DS.getRepAsType(), &RepTInfo); |
| 5375 | TL.copy(RepTInfo->getTypeLoc()); |
| 5376 | } |
| 5377 | void VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 5378 | TypeSourceInfo *RepTInfo = nullptr; |
| 5379 | Sema::GetTypeFromParser(DS.getRepAsType(), &RepTInfo); |
| 5380 | TL.copy(RepTInfo->getTypeLoc()); |
| 5381 | } |
| 5382 | void VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) { |
| 5383 | TypeSourceInfo *TInfo = nullptr; |
| 5384 | Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); |
| 5385 | |
| 5386 | |
| 5387 | |
| 5388 | if (!TInfo) { |
| 5389 | TL.initialize(Context, DS.getTypeSpecTypeNameLoc()); |
| 5390 | return; |
| 5391 | } |
| 5392 | |
| 5393 | TypeLoc OldTL = TInfo->getTypeLoc(); |
| 5394 | if (TInfo->getType()->getAs<ElaboratedType>()) { |
| 5395 | ElaboratedTypeLoc ElabTL = OldTL.castAs<ElaboratedTypeLoc>(); |
| 5396 | TemplateSpecializationTypeLoc NamedTL = ElabTL.getNamedTypeLoc() |
| 5397 | .castAs<TemplateSpecializationTypeLoc>(); |
| 5398 | TL.copy(NamedTL); |
| 5399 | } else { |
| 5400 | TL.copy(OldTL.castAs<TemplateSpecializationTypeLoc>()); |
| 5401 | ().getRAngleLoc()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 5401, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(TL.getRAngleLoc() == OldTL.castAs<TemplateSpecializationTypeLoc>().getRAngleLoc()); |
| 5402 | } |
| 5403 | |
| 5404 | } |
| 5405 | void VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
| 5406 | assert(DS.getTypeSpecType() == DeclSpec::TST_typeofExpr); |
| 5407 | TL.setTypeofLoc(DS.getTypeSpecTypeLoc()); |
| 5408 | TL.setParensRange(DS.getTypeofParensRange()); |
| 5409 | } |
| 5410 | void VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
| 5411 | assert(DS.getTypeSpecType() == DeclSpec::TST_typeofType); |
| 5412 | TL.setTypeofLoc(DS.getTypeSpecTypeLoc()); |
| 5413 | TL.setParensRange(DS.getTypeofParensRange()); |
| 5414 | assert(DS.getRepAsType()); |
| 5415 | TypeSourceInfo *TInfo = nullptr; |
| 5416 | Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); |
| 5417 | TL.setUnderlyingTInfo(TInfo); |
| 5418 | } |
| 5419 | void VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 5420 | |
| 5421 | assert(DS.getTypeSpecType() == DeclSpec::TST_underlyingType); |
| 5422 | TL.setKWLoc(DS.getTypeSpecTypeLoc()); |
| 5423 | TL.setParensRange(DS.getTypeofParensRange()); |
| 5424 | assert(DS.getRepAsType()); |
| 5425 | TypeSourceInfo *TInfo = nullptr; |
| 5426 | Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); |
| 5427 | TL.setUnderlyingTInfo(TInfo); |
| 5428 | } |
| 5429 | void VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
| 5430 | |
| 5431 | TL.setBuiltinLoc(DS.getTypeSpecTypeLoc()); |
| 5432 | if (TL.needsExtraLocalData()) { |
| 5433 | |
| 5434 | TL.getWrittenBuiltinSpecs() = DS.getWrittenBuiltinSpecs(); |
| 5435 | |
| 5436 | if (TL.getWrittenSignSpec() != TSS_unspecified) |
| 5437 | TL.expandBuiltinRange(DS.getTypeSpecSignLoc()); |
| 5438 | if (TL.getWrittenWidthSpec() != TSW_unspecified) |
| 5439 | TL.expandBuiltinRange(DS.getTypeSpecWidthRange()); |
| 5440 | } |
| 5441 | } |
| 5442 | void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
| 5443 | ElaboratedTypeKeyword Keyword |
| 5444 | = TypeWithKeyword::getKeywordForTypeSpec(DS.getTypeSpecType()); |
| 5445 | if (DS.getTypeSpecType() == TST_typename) { |
| 5446 | TypeSourceInfo *TInfo = nullptr; |
| 5447 | Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); |
| 5448 | if (TInfo) { |
| 5449 | TL.copy(TInfo->getTypeLoc().castAs<ElaboratedTypeLoc>()); |
| 5450 | return; |
| 5451 | } |
| 5452 | } |
| 5453 | TL.setElaboratedKeywordLoc(Keyword != ETK_None |
| 5454 | ? DS.getTypeSpecTypeLoc() |
| 5455 | : SourceLocation()); |
| 5456 | const CXXScopeSpec& SS = DS.getTypeSpecScope(); |
| 5457 | TL.setQualifierLoc(SS.getWithLocInContext(Context)); |
| 5458 | Visit(TL.getNextTypeLoc().getUnqualifiedLoc()); |
| 5459 | } |
| 5460 | void VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
| 5461 | assert(DS.getTypeSpecType() == TST_typename); |
| 5462 | TypeSourceInfo *TInfo = nullptr; |
| 5463 | Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); |
| 5464 | assert(TInfo); |
| 5465 | TL.copy(TInfo->getTypeLoc().castAs<DependentNameTypeLoc>()); |
| 5466 | } |
| 5467 | void VisitDependentTemplateSpecializationTypeLoc( |
| 5468 | DependentTemplateSpecializationTypeLoc TL) { |
| 5469 | assert(DS.getTypeSpecType() == TST_typename); |
| 5470 | TypeSourceInfo *TInfo = nullptr; |
| 5471 | Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); |
| 5472 | assert(TInfo); |
| 5473 | TL.copy( |
| 5474 | TInfo->getTypeLoc().castAs<DependentTemplateSpecializationTypeLoc>()); |
| 5475 | } |
| 5476 | void VisitTagTypeLoc(TagTypeLoc TL) { |
| 5477 | TL.setNameLoc(DS.getTypeSpecTypeNameLoc()); |
| 5478 | } |
| 5479 | void VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 5480 | |
| 5481 | |
| 5482 | if (DS.getTypeSpecType() == DeclSpec::TST_atomic) { |
| 5483 | TL.setKWLoc(DS.getTypeSpecTypeLoc()); |
| 5484 | TL.setParensRange(DS.getTypeofParensRange()); |
| 5485 | |
| 5486 | TypeSourceInfo *TInfo = nullptr; |
| 5487 | Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); |
| 5488 | assert(TInfo); |
| 5489 | TL.getValueLoc().initializeFullCopy(TInfo->getTypeLoc()); |
| 5490 | } else { |
| 5491 | TL.setKWLoc(DS.getAtomicSpecLoc()); |
| 5492 | |
| 5493 | TL.setParensRange(SourceRange()); |
| 5494 | Visit(TL.getValueLoc()); |
| 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | void VisitPipeTypeLoc(PipeTypeLoc TL) { |
| 5499 | TL.setKWLoc(DS.getTypeSpecTypeLoc()); |
| 5500 | |
| 5501 | TypeSourceInfo *TInfo = nullptr; |
| 5502 | Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo); |
| 5503 | TL.getValueLoc().initializeFullCopy(TInfo->getTypeLoc()); |
| 5504 | } |
| 5505 | |
| 5506 | void VisitTypeLoc(TypeLoc TL) { |
| 5507 | |
| 5508 | TL.initialize(Context, DS.getTypeSpecTypeLoc()); |
| 5509 | } |
| 5510 | }; |
| 5511 | |
| 5512 | class DeclaratorLocFiller : public TypeLocVisitor<DeclaratorLocFiller> { |
| 5513 | ASTContext &Context; |
| 5514 | TypeProcessingState &State; |
| 5515 | const DeclaratorChunk &Chunk; |
| 5516 | |
| 5517 | public: |
| 5518 | DeclaratorLocFiller(ASTContext &Context, TypeProcessingState &State, |
| 5519 | const DeclaratorChunk &Chunk) |
| 5520 | : Context(Context), State(State), Chunk(Chunk) {} |
| 5521 | |
| 5522 | void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 5523 | llvm_unreachable("qualified type locs not expected here!"); |
| 5524 | } |
| 5525 | void VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 5526 | llvm_unreachable("decayed type locs not expected here!"); |
| 5527 | } |
| 5528 | |
| 5529 | void VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 5530 | fillAttributedTypeLoc(TL, State); |
| 5531 | } |
| 5532 | void VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 5533 | |
| 5534 | } |
| 5535 | void VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 5536 | assert(Chunk.Kind == DeclaratorChunk::BlockPointer); |
| 5537 | TL.setCaretLoc(Chunk.Loc); |
| 5538 | } |
| 5539 | void VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 5540 | assert(Chunk.Kind == DeclaratorChunk::Pointer); |
| 5541 | TL.setStarLoc(Chunk.Loc); |
| 5542 | } |
| 5543 | void VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 5544 | assert(Chunk.Kind == DeclaratorChunk::Pointer); |
| 5545 | TL.setStarLoc(Chunk.Loc); |
| 5546 | } |
| 5547 | void VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 5548 | assert(Chunk.Kind == DeclaratorChunk::MemberPointer); |
| 5549 | const CXXScopeSpec& SS = Chunk.Mem.Scope(); |
| 5550 | NestedNameSpecifierLoc NNSLoc = SS.getWithLocInContext(Context); |
| 5551 | |
| 5552 | const Type* ClsTy = TL.getClass(); |
| 5553 | QualType ClsQT = QualType(ClsTy, 0); |
| 5554 | TypeSourceInfo *ClsTInfo = Context.CreateTypeSourceInfo(ClsQT, 0); |
| 5555 | |
| 5556 | TypeLoc ClsTL = ClsTInfo->getTypeLoc(); |
| 5557 | switch (NNSLoc.getNestedNameSpecifier()->getKind()) { |
| 5558 | case NestedNameSpecifier::Identifier: |
| 5559 | (0) . __assert_fail ("isa(ClsTy) && \"Unexpected TypeLoc\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 5559, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<DependentNameType>(ClsTy) && "Unexpected TypeLoc"); |
| 5560 | { |
| 5561 | DependentNameTypeLoc DNTLoc = ClsTL.castAs<DependentNameTypeLoc>(); |
| 5562 | DNTLoc.setElaboratedKeywordLoc(SourceLocation()); |
| 5563 | DNTLoc.setQualifierLoc(NNSLoc.getPrefix()); |
| 5564 | DNTLoc.setNameLoc(NNSLoc.getLocalBeginLoc()); |
| 5565 | } |
| 5566 | break; |
| 5567 | |
| 5568 | case NestedNameSpecifier::TypeSpec: |
| 5569 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 5570 | if (isa<ElaboratedType>(ClsTy)) { |
| 5571 | ElaboratedTypeLoc ETLoc = ClsTL.castAs<ElaboratedTypeLoc>(); |
| 5572 | ETLoc.setElaboratedKeywordLoc(SourceLocation()); |
| 5573 | ETLoc.setQualifierLoc(NNSLoc.getPrefix()); |
| 5574 | TypeLoc NamedTL = ETLoc.getNamedTypeLoc(); |
| 5575 | NamedTL.initializeFullCopy(NNSLoc.getTypeLoc()); |
| 5576 | } else { |
| 5577 | ClsTL.initializeFullCopy(NNSLoc.getTypeLoc()); |
| 5578 | } |
| 5579 | break; |
| 5580 | |
| 5581 | case NestedNameSpecifier::Namespace: |
| 5582 | case NestedNameSpecifier::NamespaceAlias: |
| 5583 | case NestedNameSpecifier::Global: |
| 5584 | case NestedNameSpecifier::Super: |
| 5585 | llvm_unreachable("Nested-name-specifier must name a type"); |
| 5586 | } |
| 5587 | |
| 5588 | |
| 5589 | TL.setStarLoc(Chunk.Loc); |
| 5590 | TL.setClassTInfo(ClsTInfo); |
| 5591 | } |
| 5592 | void VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 5593 | assert(Chunk.Kind == DeclaratorChunk::Reference); |
| 5594 | |
| 5595 | |
| 5596 | TL.setAmpLoc(Chunk.Loc); |
| 5597 | } |
| 5598 | void VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 5599 | assert(Chunk.Kind == DeclaratorChunk::Reference); |
| 5600 | assert(!Chunk.Ref.LValueRef); |
| 5601 | TL.setAmpAmpLoc(Chunk.Loc); |
| 5602 | } |
| 5603 | void VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 5604 | assert(Chunk.Kind == DeclaratorChunk::Array); |
| 5605 | TL.setLBracketLoc(Chunk.Loc); |
| 5606 | TL.setRBracketLoc(Chunk.EndLoc); |
| 5607 | TL.setSizeExpr(static_cast<Expr*>(Chunk.Arr.NumElts)); |
| 5608 | } |
| 5609 | void VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
| 5610 | assert(Chunk.Kind == DeclaratorChunk::Function); |
| 5611 | TL.setLocalRangeBegin(Chunk.Loc); |
| 5612 | TL.setLocalRangeEnd(Chunk.EndLoc); |
| 5613 | |
| 5614 | const DeclaratorChunk::FunctionTypeInfo &FTI = Chunk.Fun; |
| 5615 | TL.setLParenLoc(FTI.getLParenLoc()); |
| 5616 | TL.setRParenLoc(FTI.getRParenLoc()); |
| 5617 | for (unsigned i = 0, e = TL.getNumParams(), tpi = 0; i != e; ++i) { |
| 5618 | ParmVarDecl *Param = cast<ParmVarDecl>(FTI.Params[i].Param); |
| 5619 | TL.setParam(tpi++, Param); |
| 5620 | } |
| 5621 | TL.setExceptionSpecRange(FTI.getExceptionSpecRange()); |
| 5622 | } |
| 5623 | void VisitParenTypeLoc(ParenTypeLoc TL) { |
| 5624 | assert(Chunk.Kind == DeclaratorChunk::Paren); |
| 5625 | TL.setLParenLoc(Chunk.Loc); |
| 5626 | TL.setRParenLoc(Chunk.EndLoc); |
| 5627 | } |
| 5628 | void VisitPipeTypeLoc(PipeTypeLoc TL) { |
| 5629 | assert(Chunk.Kind == DeclaratorChunk::Pipe); |
| 5630 | TL.setKWLoc(Chunk.Loc); |
| 5631 | } |
| 5632 | |
| 5633 | void VisitTypeLoc(TypeLoc TL) { |
| 5634 | llvm_unreachable("unsupported TypeLoc kind in declarator!"); |
| 5635 | } |
| 5636 | }; |
| 5637 | } |
| 5638 | |
| 5639 | static void fillAtomicQualLoc(AtomicTypeLoc ATL, const DeclaratorChunk &Chunk) { |
| 5640 | SourceLocation Loc; |
| 5641 | switch (Chunk.Kind) { |
| 5642 | case DeclaratorChunk::Function: |
| 5643 | case DeclaratorChunk::Array: |
| 5644 | case DeclaratorChunk::Paren: |
| 5645 | case DeclaratorChunk::Pipe: |
| 5646 | llvm_unreachable("cannot be _Atomic qualified"); |
| 5647 | |
| 5648 | case DeclaratorChunk::Pointer: |
| 5649 | Loc = SourceLocation::getFromRawEncoding(Chunk.Ptr.AtomicQualLoc); |
| 5650 | break; |
| 5651 | |
| 5652 | case DeclaratorChunk::BlockPointer: |
| 5653 | case DeclaratorChunk::Reference: |
| 5654 | case DeclaratorChunk::MemberPointer: |
| 5655 | |
| 5656 | break; |
| 5657 | } |
| 5658 | |
| 5659 | ATL.setKWLoc(Loc); |
| 5660 | ATL.setParensRange(SourceRange()); |
| 5661 | } |
| 5662 | |
| 5663 | static void |
| 5664 | fillDependentAddressSpaceTypeLoc(DependentAddressSpaceTypeLoc DASTL, |
| 5665 | const ParsedAttributesView &Attrs) { |
| 5666 | for (const ParsedAttr &AL : Attrs) { |
| 5667 | if (AL.getKind() == ParsedAttr::AT_AddressSpace) { |
| 5668 | DASTL.setAttrNameLoc(AL.getLoc()); |
| 5669 | DASTL.setAttrExprOperand(AL.getArgAsExpr(0)); |
| 5670 | DASTL.setAttrOperandParensRange(SourceRange()); |
| 5671 | return; |
| 5672 | } |
| 5673 | } |
| 5674 | |
| 5675 | llvm_unreachable( |
| 5676 | "no address_space attribute found at the expected location!"); |
| 5677 | } |
| 5678 | |
| 5679 | |
| 5680 | |
| 5681 | |
| 5682 | |
| 5683 | |
| 5684 | |
| 5685 | |
| 5686 | |
| 5687 | static TypeSourceInfo * |
| 5688 | GetTypeSourceInfoForDeclarator(TypeProcessingState &State, |
| 5689 | QualType T, TypeSourceInfo *ReturnTypeInfo) { |
| 5690 | Sema &S = State.getSema(); |
| 5691 | Declarator &D = State.getDeclarator(); |
| 5692 | |
| 5693 | TypeSourceInfo *TInfo = S.Context.CreateTypeSourceInfo(T); |
| 5694 | UnqualTypeLoc CurrTL = TInfo->getTypeLoc().getUnqualifiedLoc(); |
| 5695 | |
| 5696 | |
| 5697 | if (isa<PackExpansionType>(T)) { |
| 5698 | CurrTL.castAs<PackExpansionTypeLoc>().setEllipsisLoc(D.getEllipsisLoc()); |
| 5699 | CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc(); |
| 5700 | } |
| 5701 | |
| 5702 | for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { |
| 5703 | |
| 5704 | |
| 5705 | if (AtomicTypeLoc ATL = CurrTL.getAs<AtomicTypeLoc>()) { |
| 5706 | fillAtomicQualLoc(ATL, D.getTypeObject(i)); |
| 5707 | CurrTL = ATL.getValueLoc().getUnqualifiedLoc(); |
| 5708 | } |
| 5709 | |
| 5710 | while (AttributedTypeLoc TL = CurrTL.getAs<AttributedTypeLoc>()) { |
| 5711 | fillAttributedTypeLoc(TL, State); |
| 5712 | CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc(); |
| 5713 | } |
| 5714 | |
| 5715 | while (DependentAddressSpaceTypeLoc TL = |
| 5716 | CurrTL.getAs<DependentAddressSpaceTypeLoc>()) { |
| 5717 | fillDependentAddressSpaceTypeLoc(TL, D.getTypeObject(i).getAttrs()); |
| 5718 | CurrTL = TL.getPointeeTypeLoc().getUnqualifiedLoc(); |
| 5719 | } |
| 5720 | |
| 5721 | |
| 5722 | while (AdjustedTypeLoc TL = CurrTL.getAs<AdjustedTypeLoc>()) |
| 5723 | CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc(); |
| 5724 | |
| 5725 | DeclaratorLocFiller(S.Context, State, D.getTypeObject(i)).Visit(CurrTL); |
| 5726 | CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc(); |
| 5727 | } |
| 5728 | |
| 5729 | |
| 5730 | |
| 5731 | if (ReturnTypeInfo) { |
| 5732 | TypeLoc TL = ReturnTypeInfo->getTypeLoc(); |
| 5733 | assert(TL.getFullDataSize() == CurrTL.getFullDataSize()); |
| 5734 | memcpy(CurrTL.getOpaqueData(), TL.getOpaqueData(), TL.getFullDataSize()); |
| 5735 | } else { |
| 5736 | TypeSpecLocFiller(S.Context, State, D.getDeclSpec()).Visit(CurrTL); |
| 5737 | } |
| 5738 | |
| 5739 | return TInfo; |
| 5740 | } |
| 5741 | |
| 5742 | |
| 5743 | ParsedType Sema::CreateParsedType(QualType T, TypeSourceInfo *TInfo) { |
| 5744 | |
| 5745 | |
| 5746 | |
| 5747 | LocInfoType *LocT = (LocInfoType*)BumpAlloc.Allocate(sizeof(LocInfoType), |
| 5748 | TypeAlignment); |
| 5749 | new (LocT) LocInfoType(T, TInfo); |
| 5750 | (0) . __assert_fail ("LocT->getTypeClass() != T->getTypeClass() && \"LocInfoType's TypeClass conflicts with an existing Type class\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 5751, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(LocT->getTypeClass() != T->getTypeClass() && |
| 5751 | (0) . __assert_fail ("LocT->getTypeClass() != T->getTypeClass() && \"LocInfoType's TypeClass conflicts with an existing Type class\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 5751, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "LocInfoType's TypeClass conflicts with an existing Type class"); |
| 5752 | return ParsedType::make(QualType(LocT, 0)); |
| 5753 | } |
| 5754 | |
| 5755 | void LocInfoType::getAsStringInternal(std::string &Str, |
| 5756 | const PrintingPolicy &Policy) const { |
| 5757 | llvm_unreachable("LocInfoType leaked into the type system; an opaque TypeTy*" |
| 5758 | " was used directly instead of getting the QualType through" |
| 5759 | " GetTypeFromParser"); |
| 5760 | } |
| 5761 | |
| 5762 | TypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) { |
| 5763 | |
| 5764 | |
| 5765 | (0) . __assert_fail ("D.getIdentifier() == nullptr && \"Type name should have no identifier!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 5766, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D.getIdentifier() == nullptr && |
| 5766 | (0) . __assert_fail ("D.getIdentifier() == nullptr && \"Type name should have no identifier!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 5766, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Type name should have no identifier!"); |
| 5767 | |
| 5768 | TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S); |
| 5769 | QualType T = TInfo->getType(); |
| 5770 | if (D.isInvalidType()) |
| 5771 | return true; |
| 5772 | |
| 5773 | |
| 5774 | |
| 5775 | |
| 5776 | |
| 5777 | |
| 5778 | if (D.getContext() != DeclaratorContext::ObjCParameterContext && |
| 5779 | D.getContext() != DeclaratorContext::AliasDeclContext && |
| 5780 | D.getContext() != DeclaratorContext::AliasTemplateContext) |
| 5781 | checkUnusedDeclAttributes(D); |
| 5782 | |
| 5783 | if (getLangOpts().CPlusPlus) { |
| 5784 | |
| 5785 | CheckExtraCXXDefaultArguments(D); |
| 5786 | } |
| 5787 | |
| 5788 | return CreateParsedType(T, TInfo); |
| 5789 | } |
| 5790 | |
| 5791 | ParsedType Sema::ActOnObjCInstanceType(SourceLocation Loc) { |
| 5792 | QualType T = Context.getObjCInstanceType(); |
| 5793 | TypeSourceInfo *TInfo = Context.getTrivialTypeSourceInfo(T, Loc); |
| 5794 | return CreateParsedType(T, TInfo); |
| 5795 | } |
| 5796 | |
| 5797 | |
| 5798 | |
| 5799 | |
| 5800 | |
| 5801 | |
| 5802 | |
| 5803 | |
| 5804 | static bool BuildAddressSpaceIndex(Sema &S, LangAS &ASIdx, |
| 5805 | const Expr *AddrSpace, |
| 5806 | SourceLocation AttrLoc) { |
| 5807 | if (!AddrSpace->isValueDependent()) { |
| 5808 | llvm::APSInt addrSpace(32); |
| 5809 | if (!AddrSpace->isIntegerConstantExpr(addrSpace, S.Context)) { |
| 5810 | S.Diag(AttrLoc, diag::err_attribute_argument_type) |
| 5811 | << "'address_space'" << AANT_ArgumentIntegerConstant |
| 5812 | << AddrSpace->getSourceRange(); |
| 5813 | return false; |
| 5814 | } |
| 5815 | |
| 5816 | |
| 5817 | if (addrSpace.isSigned()) { |
| 5818 | if (addrSpace.isNegative()) { |
| 5819 | S.Diag(AttrLoc, diag::err_attribute_address_space_negative) |
| 5820 | << AddrSpace->getSourceRange(); |
| 5821 | return false; |
| 5822 | } |
| 5823 | addrSpace.setIsSigned(false); |
| 5824 | } |
| 5825 | |
| 5826 | llvm::APSInt max(addrSpace.getBitWidth()); |
| 5827 | max = |
| 5828 | Qualifiers::MaxAddressSpace - (unsigned)LangAS::FirstTargetAddressSpace; |
| 5829 | if (addrSpace > max) { |
| 5830 | S.Diag(AttrLoc, diag::err_attribute_address_space_too_high) |
| 5831 | << (unsigned)max.getZExtValue() << AddrSpace->getSourceRange(); |
| 5832 | return false; |
| 5833 | } |
| 5834 | |
| 5835 | ASIdx = |
| 5836 | getLangASFromTargetAS(static_cast<unsigned>(addrSpace.getZExtValue())); |
| 5837 | return true; |
| 5838 | } |
| 5839 | |
| 5840 | |
| 5841 | ASIdx = LangAS::Default; |
| 5842 | return true; |
| 5843 | } |
| 5844 | |
| 5845 | |
| 5846 | |
| 5847 | |
| 5848 | |
| 5849 | QualType Sema::BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, |
| 5850 | SourceLocation AttrLoc) { |
| 5851 | if (!AddrSpace->isValueDependent()) { |
| 5852 | if (DiagnoseMultipleAddrSpaceAttributes(*this, T.getAddressSpace(), ASIdx, |
| 5853 | AttrLoc)) |
| 5854 | return QualType(); |
| 5855 | |
| 5856 | return Context.getAddrSpaceQualType(T, ASIdx); |
| 5857 | } |
| 5858 | |
| 5859 | |
| 5860 | |
| 5861 | |
| 5862 | |
| 5863 | |
| 5864 | if (T->getAs<DependentAddressSpaceType>()) { |
| 5865 | Diag(AttrLoc, diag::err_attribute_address_multiple_qualifiers); |
| 5866 | return QualType(); |
| 5867 | } |
| 5868 | |
| 5869 | return Context.getDependentAddressSpaceType(T, AddrSpace, AttrLoc); |
| 5870 | } |
| 5871 | |
| 5872 | QualType Sema::BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
| 5873 | SourceLocation AttrLoc) { |
| 5874 | LangAS ASIdx; |
| 5875 | if (!BuildAddressSpaceIndex(*this, ASIdx, AddrSpace, AttrLoc)) |
| 5876 | return QualType(); |
| 5877 | return BuildAddressSpaceAttr(T, ASIdx, AddrSpace, AttrLoc); |
| 5878 | } |
| 5879 | |
| 5880 | |
| 5881 | |
| 5882 | |
| 5883 | static void HandleAddressSpaceTypeAttribute(QualType &Type, |
| 5884 | const ParsedAttr &Attr, |
| 5885 | TypeProcessingState &State) { |
| 5886 | Sema &S = State.getSema(); |
| 5887 | |
| 5888 | |
| 5889 | |
| 5890 | if (Type->isFunctionType()) { |
| 5891 | S.Diag(Attr.getLoc(), diag::err_attribute_address_function_type); |
| 5892 | Attr.setInvalid(); |
| 5893 | return; |
| 5894 | } |
| 5895 | |
| 5896 | LangAS ASIdx; |
| 5897 | if (Attr.getKind() == ParsedAttr::AT_AddressSpace) { |
| 5898 | |
| 5899 | |
| 5900 | if (Attr.getNumArgs() != 1) { |
| 5901 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr |
| 5902 | << 1; |
| 5903 | Attr.setInvalid(); |
| 5904 | return; |
| 5905 | } |
| 5906 | |
| 5907 | Expr *ASArgExpr; |
| 5908 | if (Attr.isArgIdent(0)) { |
| 5909 | |
| 5910 | CXXScopeSpec SS; |
| 5911 | SourceLocation TemplateKWLoc; |
| 5912 | UnqualifiedId id; |
| 5913 | id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc()); |
| 5914 | |
| 5915 | ExprResult AddrSpace = S.ActOnIdExpression( |
| 5916 | S.getCurScope(), SS, TemplateKWLoc, id, , |
| 5917 | ); |
| 5918 | if (AddrSpace.isInvalid()) |
| 5919 | return; |
| 5920 | |
| 5921 | ASArgExpr = static_cast<Expr *>(AddrSpace.get()); |
| 5922 | } else { |
| 5923 | ASArgExpr = static_cast<Expr *>(Attr.getArgAsExpr(0)); |
| 5924 | } |
| 5925 | |
| 5926 | LangAS ASIdx; |
| 5927 | if (!BuildAddressSpaceIndex(S, ASIdx, ASArgExpr, Attr.getLoc())) { |
| 5928 | Attr.setInvalid(); |
| 5929 | return; |
| 5930 | } |
| 5931 | |
| 5932 | ASTContext &Ctx = S.Context; |
| 5933 | auto *ASAttr = ::new (Ctx) AddressSpaceAttr( |
| 5934 | Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex(), |
| 5935 | static_cast<unsigned>(ASIdx)); |
| 5936 | |
| 5937 | |
| 5938 | |
| 5939 | |
| 5940 | |
| 5941 | |
| 5942 | |
| 5943 | QualType T; |
| 5944 | if (!ASArgExpr->isValueDependent()) { |
| 5945 | QualType EquivType = |
| 5946 | S.BuildAddressSpaceAttr(Type, ASIdx, ASArgExpr, Attr.getLoc()); |
| 5947 | if (EquivType.isNull()) { |
| 5948 | Attr.setInvalid(); |
| 5949 | return; |
| 5950 | } |
| 5951 | T = State.getAttributedType(ASAttr, Type, EquivType); |
| 5952 | } else { |
| 5953 | T = State.getAttributedType(ASAttr, Type, Type); |
| 5954 | T = S.BuildAddressSpaceAttr(T, ASIdx, ASArgExpr, Attr.getLoc()); |
| 5955 | } |
| 5956 | |
| 5957 | if (!T.isNull()) |
| 5958 | Type = T; |
| 5959 | else |
| 5960 | Attr.setInvalid(); |
| 5961 | } else { |
| 5962 | |
| 5963 | ASIdx = Attr.asOpenCLLangAS(); |
| 5964 | if (ASIdx == LangAS::Default) |
| 5965 | llvm_unreachable("Invalid address space"); |
| 5966 | |
| 5967 | if (DiagnoseMultipleAddrSpaceAttributes(S, Type.getAddressSpace(), ASIdx, |
| 5968 | Attr.getLoc())) { |
| 5969 | Attr.setInvalid(); |
| 5970 | return; |
| 5971 | } |
| 5972 | |
| 5973 | Type = S.Context.getAddrSpaceQualType(Type, ASIdx); |
| 5974 | } |
| 5975 | } |
| 5976 | |
| 5977 | |
| 5978 | |
| 5979 | |
| 5980 | static bool hasDirectOwnershipQualifier(QualType type) { |
| 5981 | |
| 5982 | assert(type.getQualifiers().hasObjCLifetime()); |
| 5983 | |
| 5984 | while (true) { |
| 5985 | |
| 5986 | if (const AttributedType *attr = dyn_cast<AttributedType>(type)) { |
| 5987 | if (attr->getAttrKind() == attr::ObjCOwnership) |
| 5988 | return true; |
| 5989 | |
| 5990 | type = attr->getModifiedType(); |
| 5991 | |
| 5992 | |
| 5993 | } else if (const ParenType *paren = dyn_cast<ParenType>(type)) { |
| 5994 | type = paren->getInnerType(); |
| 5995 | |
| 5996 | |
| 5997 | |
| 5998 | |
| 5999 | |
| 6000 | } else { |
| 6001 | |
| 6002 | return false; |
| 6003 | } |
| 6004 | } |
| 6005 | } |
| 6006 | |
| 6007 | |
| 6008 | |
| 6009 | |
| 6010 | |
| 6011 | static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, |
| 6012 | ParsedAttr &attr, QualType &type) { |
| 6013 | bool NonObjCPointer = false; |
| 6014 | |
| 6015 | if (!type->isDependentType() && !type->isUndeducedType()) { |
| 6016 | if (const PointerType *ptr = type->getAs<PointerType>()) { |
| 6017 | QualType pointee = ptr->getPointeeType(); |
| 6018 | if (pointee->isObjCRetainableType() || pointee->isPointerType()) |
| 6019 | return false; |
| 6020 | |
| 6021 | |
| 6022 | |
| 6023 | NonObjCPointer = true; |
| 6024 | } else if (!type->isObjCRetainableType()) { |
| 6025 | return false; |
| 6026 | } |
| 6027 | |
| 6028 | |
| 6029 | |
| 6030 | if (state.isProcessingDeclSpec()) { |
| 6031 | Declarator &D = state.getDeclarator(); |
| 6032 | if (maybeMovePastReturnType(D, D.getNumTypeObjects(), |
| 6033 | )) |
| 6034 | return false; |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | Sema &S = state.getSema(); |
| 6039 | SourceLocation AttrLoc = attr.getLoc(); |
| 6040 | if (AttrLoc.isMacroID()) |
| 6041 | AttrLoc = |
| 6042 | S.getSourceManager().getImmediateExpansionRange(AttrLoc).getBegin(); |
| 6043 | |
| 6044 | if (!attr.isArgIdent(0)) { |
| 6045 | S.Diag(AttrLoc, diag::err_attribute_argument_type) << attr |
| 6046 | << AANT_ArgumentString; |
| 6047 | attr.setInvalid(); |
| 6048 | return true; |
| 6049 | } |
| 6050 | |
| 6051 | IdentifierInfo *II = attr.getArgAsIdent(0)->Ident; |
| 6052 | Qualifiers::ObjCLifetime lifetime; |
| 6053 | if (II->isStr("none")) |
| 6054 | lifetime = Qualifiers::OCL_ExplicitNone; |
| 6055 | else if (II->isStr("strong")) |
| 6056 | lifetime = Qualifiers::OCL_Strong; |
| 6057 | else if (II->isStr("weak")) |
| 6058 | lifetime = Qualifiers::OCL_Weak; |
| 6059 | else if (II->isStr("autoreleasing")) |
| 6060 | lifetime = Qualifiers::OCL_Autoreleasing; |
| 6061 | else { |
| 6062 | S.Diag(AttrLoc, diag::warn_attribute_type_not_supported) |
| 6063 | << attr.getName() << II; |
| 6064 | attr.setInvalid(); |
| 6065 | return true; |
| 6066 | } |
| 6067 | |
| 6068 | |
| 6069 | |
| 6070 | if (!S.getLangOpts().ObjCAutoRefCount && |
| 6071 | lifetime != Qualifiers::OCL_Weak && |
| 6072 | lifetime != Qualifiers::OCL_ExplicitNone) { |
| 6073 | return true; |
| 6074 | } |
| 6075 | |
| 6076 | SplitQualType underlyingType = type.split(); |
| 6077 | |
| 6078 | |
| 6079 | if (Qualifiers::ObjCLifetime previousLifetime |
| 6080 | = type.getQualifiers().getObjCLifetime()) { |
| 6081 | |
| 6082 | if (hasDirectOwnershipQualifier(type)) { |
| 6083 | S.Diag(AttrLoc, diag::err_attr_objc_ownership_redundant) |
| 6084 | << type; |
| 6085 | return true; |
| 6086 | } |
| 6087 | |
| 6088 | |
| 6089 | |
| 6090 | if (previousLifetime != lifetime) { |
| 6091 | |
| 6092 | |
| 6093 | const Type *prevTy = nullptr; |
| 6094 | while (!prevTy || prevTy != underlyingType.Ty) { |
| 6095 | prevTy = underlyingType.Ty; |
| 6096 | underlyingType = underlyingType.getSingleStepDesugaredType(); |
| 6097 | } |
| 6098 | underlyingType.Quals.removeObjCLifetime(); |
| 6099 | } |
| 6100 | } |
| 6101 | |
| 6102 | underlyingType.Quals.addObjCLifetime(lifetime); |
| 6103 | |
| 6104 | if (NonObjCPointer) { |
| 6105 | StringRef name = attr.getName()->getName(); |
| 6106 | switch (lifetime) { |
| 6107 | case Qualifiers::OCL_None: |
| 6108 | case Qualifiers::OCL_ExplicitNone: |
| 6109 | break; |
| 6110 | case Qualifiers::OCL_Strong: name = "__strong"; break; |
| 6111 | case Qualifiers::OCL_Weak: name = "__weak"; break; |
| 6112 | case Qualifiers::OCL_Autoreleasing: name = "__autoreleasing"; break; |
| 6113 | } |
| 6114 | S.Diag(AttrLoc, diag::warn_type_attribute_wrong_type) << name |
| 6115 | << TDS_ObjCObjOrBlock << type; |
| 6116 | } |
| 6117 | |
| 6118 | |
| 6119 | |
| 6120 | |
| 6121 | |
| 6122 | |
| 6123 | |
| 6124 | |
| 6125 | |
| 6126 | |
| 6127 | |
| 6128 | |
| 6129 | if (!S.getLangOpts().ObjCAutoRefCount && |
| 6130 | lifetime == Qualifiers::OCL_ExplicitNone) { |
| 6131 | type = state.getAttributedType( |
| 6132 | createSimpleAttr<ObjCInertUnsafeUnretainedAttr>(S.Context, attr), |
| 6133 | type, type); |
| 6134 | return true; |
| 6135 | } |
| 6136 | |
| 6137 | QualType origType = type; |
| 6138 | if (!NonObjCPointer) |
| 6139 | type = S.Context.getQualifiedType(underlyingType); |
| 6140 | |
| 6141 | |
| 6142 | |
| 6143 | if (AttrLoc.isValid()) { |
| 6144 | type = state.getAttributedType(::new (S.Context) ObjCOwnershipAttr( |
| 6145 | attr.getRange(), S.Context, II, |
| 6146 | attr.getAttributeSpellingListIndex()), |
| 6147 | origType, type); |
| 6148 | } |
| 6149 | |
| 6150 | auto diagnoseOrDelay = [](Sema &S, SourceLocation loc, |
| 6151 | unsigned diagnostic, QualType type) { |
| 6152 | if (S.DelayedDiagnostics.shouldDelayDiagnostics()) { |
| 6153 | S.DelayedDiagnostics.add( |
| 6154 | sema::DelayedDiagnostic::makeForbiddenType( |
| 6155 | S.getSourceManager().getExpansionLoc(loc), |
| 6156 | diagnostic, type, 0)); |
| 6157 | } else { |
| 6158 | S.Diag(loc, diagnostic); |
| 6159 | } |
| 6160 | }; |
| 6161 | |
| 6162 | |
| 6163 | if (lifetime == Qualifiers::OCL_Weak && |
| 6164 | !S.getLangOpts().ObjCWeak && !NonObjCPointer) { |
| 6165 | |
| 6166 | |
| 6167 | unsigned diagnostic = |
| 6168 | (S.getLangOpts().ObjCWeakRuntime ? diag::err_arc_weak_disabled |
| 6169 | : diag::err_arc_weak_no_runtime); |
| 6170 | |
| 6171 | |
| 6172 | diagnoseOrDelay(S, AttrLoc, diagnostic, type); |
| 6173 | |
| 6174 | attr.setInvalid(); |
| 6175 | return true; |
| 6176 | } |
| 6177 | |
| 6178 | |
| 6179 | |
| 6180 | if (lifetime == Qualifiers::OCL_Weak) { |
| 6181 | if (const ObjCObjectPointerType *ObjT = |
| 6182 | type->getAs<ObjCObjectPointerType>()) { |
| 6183 | if (ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl()) { |
| 6184 | if (Class->isArcWeakrefUnavailable()) { |
| 6185 | S.Diag(AttrLoc, diag::err_arc_unsupported_weak_class); |
| 6186 | S.Diag(ObjT->getInterfaceDecl()->getLocation(), |
| 6187 | diag::note_class_declared); |
| 6188 | } |
| 6189 | } |
| 6190 | } |
| 6191 | } |
| 6192 | |
| 6193 | return true; |
| 6194 | } |
| 6195 | |
| 6196 | |
| 6197 | |
| 6198 | |
| 6199 | |
| 6200 | static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr, |
| 6201 | QualType &type) { |
| 6202 | Sema &S = state.getSema(); |
| 6203 | |
| 6204 | |
| 6205 | if (!type->isPointerType() && |
| 6206 | !type->isObjCObjectPointerType() && |
| 6207 | !type->isBlockPointerType()) |
| 6208 | return false; |
| 6209 | |
| 6210 | if (type.getObjCGCAttr() != Qualifiers::GCNone) { |
| 6211 | S.Diag(attr.getLoc(), diag::err_attribute_multiple_objc_gc); |
| 6212 | attr.setInvalid(); |
| 6213 | return true; |
| 6214 | } |
| 6215 | |
| 6216 | |
| 6217 | if (!attr.isArgIdent(0)) { |
| 6218 | S.Diag(attr.getLoc(), diag::err_attribute_argument_type) |
| 6219 | << attr << AANT_ArgumentString; |
| 6220 | attr.setInvalid(); |
| 6221 | return true; |
| 6222 | } |
| 6223 | Qualifiers::GC GCAttr; |
| 6224 | if (attr.getNumArgs() > 1) { |
| 6225 | S.Diag(attr.getLoc(), diag::err_attribute_wrong_number_arguments) << attr |
| 6226 | << 1; |
| 6227 | attr.setInvalid(); |
| 6228 | return true; |
| 6229 | } |
| 6230 | |
| 6231 | IdentifierInfo *II = attr.getArgAsIdent(0)->Ident; |
| 6232 | if (II->isStr("weak")) |
| 6233 | GCAttr = Qualifiers::Weak; |
| 6234 | else if (II->isStr("strong")) |
| 6235 | GCAttr = Qualifiers::Strong; |
| 6236 | else { |
| 6237 | S.Diag(attr.getLoc(), diag::warn_attribute_type_not_supported) |
| 6238 | << attr.getName() << II; |
| 6239 | attr.setInvalid(); |
| 6240 | return true; |
| 6241 | } |
| 6242 | |
| 6243 | QualType origType = type; |
| 6244 | type = S.Context.getObjCGCQualType(origType, GCAttr); |
| 6245 | |
| 6246 | |
| 6247 | if (attr.getLoc().isValid()) |
| 6248 | type = state.getAttributedType( |
| 6249 | ::new (S.Context) ObjCGCAttr(attr.getRange(), S.Context, II, |
| 6250 | attr.getAttributeSpellingListIndex()), |
| 6251 | origType, type); |
| 6252 | |
| 6253 | return true; |
| 6254 | } |
| 6255 | |
| 6256 | namespace { |
| 6257 | |
| 6258 | |
| 6259 | |
| 6260 | |
| 6261 | |
| 6262 | |
| 6263 | |
| 6264 | |
| 6265 | |
| 6266 | |
| 6267 | struct FunctionTypeUnwrapper { |
| 6268 | enum WrapKind { |
| 6269 | Desugar, |
| 6270 | Attributed, |
| 6271 | Parens, |
| 6272 | Pointer, |
| 6273 | BlockPointer, |
| 6274 | Reference, |
| 6275 | MemberPointer |
| 6276 | }; |
| 6277 | |
| 6278 | QualType Original; |
| 6279 | const FunctionType *Fn; |
| 6280 | SmallVector<unsigned char , 8> Stack; |
| 6281 | |
| 6282 | FunctionTypeUnwrapper(Sema &S, QualType T) : Original(T) { |
| 6283 | while (true) { |
| 6284 | const Type *Ty = T.getTypePtr(); |
| 6285 | if (isa<FunctionType>(Ty)) { |
| 6286 | Fn = cast<FunctionType>(Ty); |
| 6287 | return; |
| 6288 | } else if (isa<ParenType>(Ty)) { |
| 6289 | T = cast<ParenType>(Ty)->getInnerType(); |
| 6290 | Stack.push_back(Parens); |
| 6291 | } else if (isa<PointerType>(Ty)) { |
| 6292 | T = cast<PointerType>(Ty)->getPointeeType(); |
| 6293 | Stack.push_back(Pointer); |
| 6294 | } else if (isa<BlockPointerType>(Ty)) { |
| 6295 | T = cast<BlockPointerType>(Ty)->getPointeeType(); |
| 6296 | Stack.push_back(BlockPointer); |
| 6297 | } else if (isa<MemberPointerType>(Ty)) { |
| 6298 | T = cast<MemberPointerType>(Ty)->getPointeeType(); |
| 6299 | Stack.push_back(MemberPointer); |
| 6300 | } else if (isa<ReferenceType>(Ty)) { |
| 6301 | T = cast<ReferenceType>(Ty)->getPointeeType(); |
| 6302 | Stack.push_back(Reference); |
| 6303 | } else if (isa<AttributedType>(Ty)) { |
| 6304 | T = cast<AttributedType>(Ty)->getEquivalentType(); |
| 6305 | Stack.push_back(Attributed); |
| 6306 | } else { |
| 6307 | const Type *DTy = Ty->getUnqualifiedDesugaredType(); |
| 6308 | if (Ty == DTy) { |
| 6309 | Fn = nullptr; |
| 6310 | return; |
| 6311 | } |
| 6312 | |
| 6313 | T = QualType(DTy, 0); |
| 6314 | Stack.push_back(Desugar); |
| 6315 | } |
| 6316 | } |
| 6317 | } |
| 6318 | |
| 6319 | bool isFunctionType() const { return (Fn != nullptr); } |
| 6320 | const FunctionType *get() const { return Fn; } |
| 6321 | |
| 6322 | QualType wrap(Sema &S, const FunctionType *New) { |
| 6323 | |
| 6324 | if (New == get()) return Original; |
| 6325 | |
| 6326 | Fn = New; |
| 6327 | return wrap(S.Context, Original, 0); |
| 6328 | } |
| 6329 | |
| 6330 | private: |
| 6331 | QualType wrap(ASTContext &C, QualType Old, unsigned I) { |
| 6332 | if (I == Stack.size()) |
| 6333 | return C.getQualifiedType(Fn, Old.getQualifiers()); |
| 6334 | |
| 6335 | |
| 6336 | |
| 6337 | SplitQualType SplitOld = Old.split(); |
| 6338 | |
| 6339 | |
| 6340 | if (SplitOld.Quals.empty()) |
| 6341 | return wrap(C, SplitOld.Ty, I); |
| 6342 | return C.getQualifiedType(wrap(C, SplitOld.Ty, I), SplitOld.Quals); |
| 6343 | } |
| 6344 | |
| 6345 | QualType wrap(ASTContext &C, const Type *Old, unsigned I) { |
| 6346 | if (I == Stack.size()) return QualType(Fn, 0); |
| 6347 | |
| 6348 | switch (static_cast<WrapKind>(Stack[I++])) { |
| 6349 | case Desugar: |
| 6350 | |
| 6351 | |
| 6352 | return wrap(C, Old->getUnqualifiedDesugaredType(), I); |
| 6353 | |
| 6354 | case Attributed: |
| 6355 | return wrap(C, cast<AttributedType>(Old)->getEquivalentType(), I); |
| 6356 | |
| 6357 | case Parens: { |
| 6358 | QualType New = wrap(C, cast<ParenType>(Old)->getInnerType(), I); |
| 6359 | return C.getParenType(New); |
| 6360 | } |
| 6361 | |
| 6362 | case Pointer: { |
| 6363 | QualType New = wrap(C, cast<PointerType>(Old)->getPointeeType(), I); |
| 6364 | return C.getPointerType(New); |
| 6365 | } |
| 6366 | |
| 6367 | case BlockPointer: { |
| 6368 | QualType New = wrap(C, cast<BlockPointerType>(Old)->getPointeeType(),I); |
| 6369 | return C.getBlockPointerType(New); |
| 6370 | } |
| 6371 | |
| 6372 | case MemberPointer: { |
| 6373 | const MemberPointerType *OldMPT = cast<MemberPointerType>(Old); |
| 6374 | QualType New = wrap(C, OldMPT->getPointeeType(), I); |
| 6375 | return C.getMemberPointerType(New, OldMPT->getClass()); |
| 6376 | } |
| 6377 | |
| 6378 | case Reference: { |
| 6379 | const ReferenceType *OldRef = cast<ReferenceType>(Old); |
| 6380 | QualType New = wrap(C, OldRef->getPointeeType(), I); |
| 6381 | if (isa<LValueReferenceType>(OldRef)) |
| 6382 | return C.getLValueReferenceType(New, OldRef->isSpelledAsLValue()); |
| 6383 | else |
| 6384 | return C.getRValueReferenceType(New); |
| 6385 | } |
| 6386 | } |
| 6387 | |
| 6388 | llvm_unreachable("unknown wrapping kind"); |
| 6389 | } |
| 6390 | }; |
| 6391 | } |
| 6392 | |
| 6393 | static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &State, |
| 6394 | ParsedAttr &PAttr, QualType &Type) { |
| 6395 | Sema &S = State.getSema(); |
| 6396 | |
| 6397 | Attr *A; |
| 6398 | switch (PAttr.getKind()) { |
| 6399 | default: llvm_unreachable("Unknown attribute kind"); |
| 6400 | case ParsedAttr::AT_Ptr32: |
| 6401 | A = createSimpleAttr<Ptr32Attr>(S.Context, PAttr); |
| 6402 | break; |
| 6403 | case ParsedAttr::AT_Ptr64: |
| 6404 | A = createSimpleAttr<Ptr64Attr>(S.Context, PAttr); |
| 6405 | break; |
| 6406 | case ParsedAttr::AT_SPtr: |
| 6407 | A = createSimpleAttr<SPtrAttr>(S.Context, PAttr); |
| 6408 | break; |
| 6409 | case ParsedAttr::AT_UPtr: |
| 6410 | A = createSimpleAttr<UPtrAttr>(S.Context, PAttr); |
| 6411 | break; |
| 6412 | } |
| 6413 | |
| 6414 | attr::Kind NewAttrKind = A->getKind(); |
| 6415 | QualType Desugared = Type; |
| 6416 | const AttributedType *AT = dyn_cast<AttributedType>(Type); |
| 6417 | while (AT) { |
| 6418 | attr::Kind CurAttrKind = AT->getAttrKind(); |
| 6419 | |
| 6420 | |
| 6421 | |
| 6422 | if (NewAttrKind == CurAttrKind) { |
| 6423 | S.Diag(PAttr.getLoc(), diag::warn_duplicate_attribute_exact) |
| 6424 | << PAttr.getName(); |
| 6425 | return true; |
| 6426 | } |
| 6427 | |
| 6428 | |
| 6429 | |
| 6430 | if ((CurAttrKind == attr::Ptr32 && NewAttrKind == attr::Ptr64) || |
| 6431 | (CurAttrKind == attr::Ptr64 && NewAttrKind == attr::Ptr32)) { |
| 6432 | S.Diag(PAttr.getLoc(), diag::err_attributes_are_not_compatible) |
| 6433 | << "'__ptr32'" << "'__ptr64'"; |
| 6434 | return true; |
| 6435 | } else if ((CurAttrKind == attr::SPtr && NewAttrKind == attr::UPtr) || |
| 6436 | (CurAttrKind == attr::UPtr && NewAttrKind == attr::SPtr)) { |
| 6437 | S.Diag(PAttr.getLoc(), diag::err_attributes_are_not_compatible) |
| 6438 | << "'__sptr'" << "'__uptr'"; |
| 6439 | return true; |
| 6440 | } |
| 6441 | |
| 6442 | Desugared = AT->getEquivalentType(); |
| 6443 | AT = dyn_cast<AttributedType>(Desugared); |
| 6444 | } |
| 6445 | |
| 6446 | |
| 6447 | |
| 6448 | |
| 6449 | |
| 6450 | |
| 6451 | |
| 6452 | |
| 6453 | if (!isa<PointerType>(Desugared)) { |
| 6454 | if (Type->isMemberPointerType()) |
| 6455 | S.Diag(PAttr.getLoc(), diag::err_attribute_no_member_pointers) << PAttr; |
| 6456 | else |
| 6457 | S.Diag(PAttr.getLoc(), diag::err_attribute_pointers_only) << PAttr << 0; |
| 6458 | return true; |
| 6459 | } |
| 6460 | |
| 6461 | Type = State.getAttributedType(A, Type, Type); |
| 6462 | return false; |
| 6463 | } |
| 6464 | |
| 6465 | |
| 6466 | static NullabilityKind mapNullabilityAttrKind(ParsedAttr::Kind kind) { |
| 6467 | switch (kind) { |
| 6468 | case ParsedAttr::AT_TypeNonNull: |
| 6469 | return NullabilityKind::NonNull; |
| 6470 | |
| 6471 | case ParsedAttr::AT_TypeNullable: |
| 6472 | return NullabilityKind::Nullable; |
| 6473 | |
| 6474 | case ParsedAttr::AT_TypeNullUnspecified: |
| 6475 | return NullabilityKind::Unspecified; |
| 6476 | |
| 6477 | default: |
| 6478 | llvm_unreachable("not a nullability attribute kind"); |
| 6479 | } |
| 6480 | } |
| 6481 | |
| 6482 | |
| 6483 | |
| 6484 | |
| 6485 | |
| 6486 | |
| 6487 | |
| 6488 | |
| 6489 | |
| 6490 | |
| 6491 | |
| 6492 | |
| 6493 | |
| 6494 | |
| 6495 | static bool checkNullabilityTypeSpecifier(TypeProcessingState &state, |
| 6496 | QualType &type, |
| 6497 | ParsedAttr &attr, |
| 6498 | bool allowOnArrayType) { |
| 6499 | Sema &S = state.getSema(); |
| 6500 | |
| 6501 | NullabilityKind nullability = mapNullabilityAttrKind(attr.getKind()); |
| 6502 | SourceLocation nullabilityLoc = attr.getLoc(); |
| 6503 | bool isContextSensitive = attr.isContextSensitiveKeywordAttribute(); |
| 6504 | |
| 6505 | recordNullabilitySeen(S, nullabilityLoc); |
| 6506 | |
| 6507 | |
| 6508 | QualType desugared = type; |
| 6509 | while (auto attributed = dyn_cast<AttributedType>(desugared.getTypePtr())) { |
| 6510 | |
| 6511 | if (auto existingNullability = attributed->getImmediateNullability()) { |
| 6512 | |
| 6513 | if (nullability == *existingNullability) { |
| 6514 | S.Diag(nullabilityLoc, diag::warn_nullability_duplicate) |
| 6515 | << DiagNullabilityKind(nullability, isContextSensitive) |
| 6516 | << FixItHint::CreateRemoval(nullabilityLoc); |
| 6517 | |
| 6518 | break; |
| 6519 | } |
| 6520 | |
| 6521 | |
| 6522 | S.Diag(nullabilityLoc, diag::err_nullability_conflicting) |
| 6523 | << DiagNullabilityKind(nullability, isContextSensitive) |
| 6524 | << DiagNullabilityKind(*existingNullability, false); |
| 6525 | return true; |
| 6526 | } |
| 6527 | |
| 6528 | desugared = attributed->getModifiedType(); |
| 6529 | } |
| 6530 | |
| 6531 | |
| 6532 | |
| 6533 | |
| 6534 | |
| 6535 | if (auto existingNullability = desugared->getNullability(S.Context)) { |
| 6536 | if (nullability != *existingNullability) { |
| 6537 | S.Diag(nullabilityLoc, diag::err_nullability_conflicting) |
| 6538 | << DiagNullabilityKind(nullability, isContextSensitive) |
| 6539 | << DiagNullabilityKind(*existingNullability, false); |
| 6540 | |
| 6541 | |
| 6542 | if (auto typedefType = desugared->getAs<TypedefType>()) { |
| 6543 | TypedefNameDecl *typedefDecl = typedefType->getDecl(); |
| 6544 | QualType underlyingType = typedefDecl->getUnderlyingType(); |
| 6545 | if (auto typedefNullability |
| 6546 | = AttributedType::stripOuterNullability(underlyingType)) { |
| 6547 | if (*typedefNullability == *existingNullability) { |
| 6548 | S.Diag(typedefDecl->getLocation(), diag::note_nullability_here) |
| 6549 | << DiagNullabilityKind(*existingNullability, false); |
| 6550 | } |
| 6551 | } |
| 6552 | } |
| 6553 | |
| 6554 | return true; |
| 6555 | } |
| 6556 | } |
| 6557 | |
| 6558 | |
| 6559 | if (!desugared->canHaveNullability() && |
| 6560 | !(allowOnArrayType && desugared->isArrayType())) { |
| 6561 | S.Diag(nullabilityLoc, diag::err_nullability_nonpointer) |
| 6562 | << DiagNullabilityKind(nullability, isContextSensitive) << type; |
| 6563 | return true; |
| 6564 | } |
| 6565 | |
| 6566 | |
| 6567 | |
| 6568 | if (isContextSensitive) { |
| 6569 | |
| 6570 | const Type *pointeeType; |
| 6571 | if (desugared->isArrayType()) |
| 6572 | pointeeType = desugared->getArrayElementTypeNoTypeQual(); |
| 6573 | else |
| 6574 | pointeeType = desugared->getPointeeType().getTypePtr(); |
| 6575 | |
| 6576 | if (pointeeType->isAnyPointerType() || |
| 6577 | pointeeType->isObjCObjectPointerType() || |
| 6578 | pointeeType->isMemberPointerType()) { |
| 6579 | S.Diag(nullabilityLoc, diag::err_nullability_cs_multilevel) |
| 6580 | << DiagNullabilityKind(nullability, true) |
| 6581 | << type; |
| 6582 | S.Diag(nullabilityLoc, diag::note_nullability_type_specifier) |
| 6583 | << DiagNullabilityKind(nullability, false) |
| 6584 | << type |
| 6585 | << FixItHint::CreateReplacement(nullabilityLoc, |
| 6586 | getNullabilitySpelling(nullability)); |
| 6587 | return true; |
| 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | |
| 6592 | type = state.getAttributedType( |
| 6593 | createNullabilityAttr(S.Context, attr, nullability), type, type); |
| 6594 | return false; |
| 6595 | } |
| 6596 | |
| 6597 | |
| 6598 | |
| 6599 | static bool checkObjCKindOfType(TypeProcessingState &state, QualType &type, |
| 6600 | ParsedAttr &attr) { |
| 6601 | Sema &S = state.getSema(); |
| 6602 | |
| 6603 | if (isa<ObjCTypeParamType>(type)) { |
| 6604 | |
| 6605 | type = state.getAttributedType( |
| 6606 | createSimpleAttr<ObjCKindOfAttr>(S.Context, attr), type, type); |
| 6607 | return false; |
| 6608 | } |
| 6609 | |
| 6610 | |
| 6611 | const ObjCObjectPointerType *ptrType = type->getAs<ObjCObjectPointerType>(); |
| 6612 | const ObjCObjectType *objType = ptrType ? ptrType->getObjectType() |
| 6613 | : type->getAs<ObjCObjectType>(); |
| 6614 | |
| 6615 | |
| 6616 | if (!objType) { |
| 6617 | |
| 6618 | S.Diag(attr.getLoc(), diag::err_objc_kindof_nonobject) |
| 6619 | << type; |
| 6620 | return true; |
| 6621 | } |
| 6622 | |
| 6623 | |
| 6624 | |
| 6625 | |
| 6626 | QualType equivType = S.Context.getObjCObjectType( |
| 6627 | objType->getBaseType(), objType->getTypeArgsAsWritten(), |
| 6628 | objType->getProtocols(), |
| 6629 | ->isObjCUnqualifiedId() ? false : true); |
| 6630 | |
| 6631 | |
| 6632 | if (ptrType) { |
| 6633 | equivType = S.Context.getObjCObjectPointerType(equivType); |
| 6634 | if (auto nullability = type->getNullability(S.Context)) { |
| 6635 | |
| 6636 | |
| 6637 | (0) . __assert_fail ("attr.getAttributeSpellingListIndex() == 0 && \"multiple spellings for __kindof?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 6638, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(attr.getAttributeSpellingListIndex() == 0 && |
| 6638 | (0) . __assert_fail ("attr.getAttributeSpellingListIndex() == 0 && \"multiple spellings for __kindof?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 6638, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "multiple spellings for __kindof?"); |
| 6639 | Attr *A = createNullabilityAttr(S.Context, attr, *nullability); |
| 6640 | A->setImplicit(true); |
| 6641 | equivType = state.getAttributedType(A, equivType, equivType); |
| 6642 | } |
| 6643 | } |
| 6644 | |
| 6645 | |
| 6646 | type = state.getAttributedType( |
| 6647 | createSimpleAttr<ObjCKindOfAttr>(S.Context, attr), type, equivType); |
| 6648 | return false; |
| 6649 | } |
| 6650 | |
| 6651 | |
| 6652 | |
| 6653 | |
| 6654 | |
| 6655 | |
| 6656 | |
| 6657 | static bool distributeNullabilityTypeAttr(TypeProcessingState &state, |
| 6658 | QualType type, ParsedAttr &attr) { |
| 6659 | Declarator &declarator = state.getDeclarator(); |
| 6660 | |
| 6661 | |
| 6662 | auto moveToChunk = [&](DeclaratorChunk &chunk, bool inFunction) -> bool { |
| 6663 | |
| 6664 | |
| 6665 | if (hasNullabilityAttr(chunk.getAttrs())) |
| 6666 | return false; |
| 6667 | |
| 6668 | |
| 6669 | |
| 6670 | enum { |
| 6671 | PK_Pointer, |
| 6672 | PK_BlockPointer, |
| 6673 | PK_MemberPointer, |
| 6674 | PK_FunctionPointer, |
| 6675 | PK_MemberFunctionPointer, |
| 6676 | } pointerKind |
| 6677 | = chunk.Kind == DeclaratorChunk::Pointer ? (inFunction ? PK_FunctionPointer |
| 6678 | : PK_Pointer) |
| 6679 | : chunk.Kind == DeclaratorChunk::BlockPointer ? PK_BlockPointer |
| 6680 | : inFunction? PK_MemberFunctionPointer : PK_MemberPointer; |
| 6681 | |
| 6682 | auto diag = state.getSema().Diag(attr.getLoc(), |
| 6683 | diag::warn_nullability_declspec) |
| 6684 | << DiagNullabilityKind(mapNullabilityAttrKind(attr.getKind()), |
| 6685 | attr.isContextSensitiveKeywordAttribute()) |
| 6686 | << type |
| 6687 | << static_cast<unsigned>(pointerKind); |
| 6688 | |
| 6689 | |
| 6690 | if (chunk.Kind != DeclaratorChunk::MemberPointer) { |
| 6691 | diag << FixItHint::CreateRemoval(attr.getLoc()) |
| 6692 | << FixItHint::CreateInsertion( |
| 6693 | state.getSema().getPreprocessor() |
| 6694 | .getLocForEndOfToken(chunk.Loc), |
| 6695 | " " + attr.getName()->getName().str() + " "); |
| 6696 | } |
| 6697 | |
| 6698 | moveAttrFromListToList(attr, state.getCurrentAttributes(), |
| 6699 | chunk.getAttrs()); |
| 6700 | return true; |
| 6701 | }; |
| 6702 | |
| 6703 | |
| 6704 | |
| 6705 | for (unsigned i = state.getCurrentChunkIndex(); i != 0; --i) { |
| 6706 | DeclaratorChunk &chunk = declarator.getTypeObject(i-1); |
| 6707 | switch (chunk.Kind) { |
| 6708 | case DeclaratorChunk::Pointer: |
| 6709 | case DeclaratorChunk::BlockPointer: |
| 6710 | case DeclaratorChunk::MemberPointer: |
| 6711 | return moveToChunk(chunk, false); |
| 6712 | |
| 6713 | case DeclaratorChunk::Paren: |
| 6714 | case DeclaratorChunk::Array: |
| 6715 | continue; |
| 6716 | |
| 6717 | case DeclaratorChunk::Function: |
| 6718 | |
| 6719 | |
| 6720 | if (DeclaratorChunk *dest = maybeMovePastReturnType( |
| 6721 | declarator, i, |
| 6722 | )) { |
| 6723 | return moveToChunk(*dest, true); |
| 6724 | } |
| 6725 | |
| 6726 | return false; |
| 6727 | |
| 6728 | |
| 6729 | case DeclaratorChunk::Reference: |
| 6730 | case DeclaratorChunk::Pipe: |
| 6731 | return false; |
| 6732 | } |
| 6733 | } |
| 6734 | |
| 6735 | return false; |
| 6736 | } |
| 6737 | |
| 6738 | static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) { |
| 6739 | assert(!Attr.isInvalid()); |
| 6740 | switch (Attr.getKind()) { |
| 6741 | default: |
| 6742 | llvm_unreachable("not a calling convention attribute"); |
| 6743 | case ParsedAttr::AT_CDecl: |
| 6744 | return createSimpleAttr<CDeclAttr>(Ctx, Attr); |
| 6745 | case ParsedAttr::AT_FastCall: |
| 6746 | return createSimpleAttr<FastCallAttr>(Ctx, Attr); |
| 6747 | case ParsedAttr::AT_StdCall: |
| 6748 | return createSimpleAttr<StdCallAttr>(Ctx, Attr); |
| 6749 | case ParsedAttr::AT_ThisCall: |
| 6750 | return createSimpleAttr<ThisCallAttr>(Ctx, Attr); |
| 6751 | case ParsedAttr::AT_RegCall: |
| 6752 | return createSimpleAttr<RegCallAttr>(Ctx, Attr); |
| 6753 | case ParsedAttr::AT_Pascal: |
| 6754 | return createSimpleAttr<PascalAttr>(Ctx, Attr); |
| 6755 | case ParsedAttr::AT_SwiftCall: |
| 6756 | return createSimpleAttr<SwiftCallAttr>(Ctx, Attr); |
| 6757 | case ParsedAttr::AT_VectorCall: |
| 6758 | return createSimpleAttr<VectorCallAttr>(Ctx, Attr); |
| 6759 | case ParsedAttr::AT_AArch64VectorPcs: |
| 6760 | return createSimpleAttr<AArch64VectorPcsAttr>(Ctx, Attr); |
| 6761 | case ParsedAttr::AT_Pcs: { |
| 6762 | |
| 6763 | |
| 6764 | |
| 6765 | StringRef Str; |
| 6766 | if (Attr.isArgExpr(0)) |
| 6767 | Str = cast<StringLiteral>(Attr.getArgAsExpr(0))->getString(); |
| 6768 | else |
| 6769 | Str = Attr.getArgAsIdent(0)->Ident->getName(); |
| 6770 | PcsAttr::PCSType Type; |
| 6771 | if (!PcsAttr::ConvertStrToPCSType(Str, Type)) |
| 6772 | llvm_unreachable("already validated the attribute"); |
| 6773 | return ::new (Ctx) PcsAttr(Attr.getRange(), Ctx, Type, |
| 6774 | Attr.getAttributeSpellingListIndex()); |
| 6775 | } |
| 6776 | case ParsedAttr::AT_IntelOclBicc: |
| 6777 | return createSimpleAttr<IntelOclBiccAttr>(Ctx, Attr); |
| 6778 | case ParsedAttr::AT_MSABI: |
| 6779 | return createSimpleAttr<MSABIAttr>(Ctx, Attr); |
| 6780 | case ParsedAttr::AT_SysVABI: |
| 6781 | return createSimpleAttr<SysVABIAttr>(Ctx, Attr); |
| 6782 | case ParsedAttr::AT_PreserveMost: |
| 6783 | return createSimpleAttr<PreserveMostAttr>(Ctx, Attr); |
| 6784 | case ParsedAttr::AT_PreserveAll: |
| 6785 | return createSimpleAttr<PreserveAllAttr>(Ctx, Attr); |
| 6786 | } |
| 6787 | llvm_unreachable("unexpected attribute kind!"); |
| 6788 | } |
| 6789 | |
| 6790 | |
| 6791 | |
| 6792 | static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr, |
| 6793 | QualType &type) { |
| 6794 | Sema &S = state.getSema(); |
| 6795 | |
| 6796 | FunctionTypeUnwrapper unwrapped(S, type); |
| 6797 | |
| 6798 | if (attr.getKind() == ParsedAttr::AT_NoReturn) { |
| 6799 | if (S.CheckAttrNoArgs(attr)) |
| 6800 | return true; |
| 6801 | |
| 6802 | |
| 6803 | if (!unwrapped.isFunctionType()) |
| 6804 | return false; |
| 6805 | |
| 6806 | |
| 6807 | FunctionType::ExtInfo EI = unwrapped.get()->getExtInfo().withNoReturn(true); |
| 6808 | type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); |
| 6809 | return true; |
| 6810 | } |
| 6811 | |
| 6812 | |
| 6813 | |
| 6814 | if (attr.getKind() == ParsedAttr::AT_NSReturnsRetained) { |
| 6815 | if (attr.getNumArgs()) return true; |
| 6816 | |
| 6817 | |
| 6818 | if (!unwrapped.isFunctionType()) |
| 6819 | return false; |
| 6820 | |
| 6821 | |
| 6822 | if (S.checkNSReturnsRetainedReturnType(attr.getLoc(), |
| 6823 | unwrapped.get()->getReturnType())) |
| 6824 | return true; |
| 6825 | |
| 6826 | |
| 6827 | QualType origType = type; |
| 6828 | if (state.getSema().getLangOpts().ObjCAutoRefCount) { |
| 6829 | FunctionType::ExtInfo EI |
| 6830 | = unwrapped.get()->getExtInfo().withProducesResult(true); |
| 6831 | type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); |
| 6832 | } |
| 6833 | type = state.getAttributedType( |
| 6834 | createSimpleAttr<NSReturnsRetainedAttr>(S.Context, attr), |
| 6835 | origType, type); |
| 6836 | return true; |
| 6837 | } |
| 6838 | |
| 6839 | if (attr.getKind() == ParsedAttr::AT_AnyX86NoCallerSavedRegisters) { |
| 6840 | if (S.CheckAttrTarget(attr) || S.CheckAttrNoArgs(attr)) |
| 6841 | return true; |
| 6842 | |
| 6843 | |
| 6844 | if (!unwrapped.isFunctionType()) |
| 6845 | return false; |
| 6846 | |
| 6847 | FunctionType::ExtInfo EI = |
| 6848 | unwrapped.get()->getExtInfo().withNoCallerSavedRegs(true); |
| 6849 | type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); |
| 6850 | return true; |
| 6851 | } |
| 6852 | |
| 6853 | if (attr.getKind() == ParsedAttr::AT_AnyX86NoCfCheck) { |
| 6854 | if (!S.getLangOpts().CFProtectionBranch) { |
| 6855 | S.Diag(attr.getLoc(), diag::warn_nocf_check_attribute_ignored); |
| 6856 | attr.setInvalid(); |
| 6857 | return true; |
| 6858 | } |
| 6859 | |
| 6860 | if (S.CheckAttrTarget(attr) || S.CheckAttrNoArgs(attr)) |
| 6861 | return true; |
| 6862 | |
| 6863 | |
| 6864 | |
| 6865 | if (!unwrapped.isFunctionType()) |
| 6866 | return true; |
| 6867 | |
| 6868 | FunctionType::ExtInfo EI = |
| 6869 | unwrapped.get()->getExtInfo().withNoCfCheck(true); |
| 6870 | type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); |
| 6871 | return true; |
| 6872 | } |
| 6873 | |
| 6874 | if (attr.getKind() == ParsedAttr::AT_Regparm) { |
| 6875 | unsigned value; |
| 6876 | if (S.CheckRegparmAttr(attr, value)) |
| 6877 | return true; |
| 6878 | |
| 6879 | |
| 6880 | if (!unwrapped.isFunctionType()) |
| 6881 | return false; |
| 6882 | |
| 6883 | |
| 6884 | const FunctionType *fn = unwrapped.get(); |
| 6885 | CallingConv CC = fn->getCallConv(); |
| 6886 | if (CC == CC_X86FastCall) { |
| 6887 | S.Diag(attr.getLoc(), diag::err_attributes_are_not_compatible) |
| 6888 | << FunctionType::getNameForCallConv(CC) |
| 6889 | << "regparm"; |
| 6890 | attr.setInvalid(); |
| 6891 | return true; |
| 6892 | } |
| 6893 | |
| 6894 | FunctionType::ExtInfo EI = |
| 6895 | unwrapped.get()->getExtInfo().withRegParm(value); |
| 6896 | type = unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); |
| 6897 | return true; |
| 6898 | } |
| 6899 | |
| 6900 | |
| 6901 | if (!unwrapped.isFunctionType()) return false; |
| 6902 | |
| 6903 | |
| 6904 | CallingConv CC; |
| 6905 | if (S.CheckCallingConvAttr(attr, CC)) |
| 6906 | return true; |
| 6907 | |
| 6908 | const FunctionType *fn = unwrapped.get(); |
| 6909 | CallingConv CCOld = fn->getCallConv(); |
| 6910 | Attr *CCAttr = getCCTypeAttr(S.Context, attr); |
| 6911 | |
| 6912 | if (CCOld != CC) { |
| 6913 | |
| 6914 | |
| 6915 | if (S.getCallingConvAttributedType(type)) { |
| 6916 | S.Diag(attr.getLoc(), diag::err_attributes_are_not_compatible) |
| 6917 | << FunctionType::getNameForCallConv(CC) |
| 6918 | << FunctionType::getNameForCallConv(CCOld); |
| 6919 | attr.setInvalid(); |
| 6920 | return true; |
| 6921 | } |
| 6922 | } |
| 6923 | |
| 6924 | |
| 6925 | |
| 6926 | |
| 6927 | |
| 6928 | |
| 6929 | |
| 6930 | |
| 6931 | if (!supportsVariadicCall(CC)) { |
| 6932 | const FunctionProtoType *FnP = dyn_cast<FunctionProtoType>(fn); |
| 6933 | if (FnP && FnP->isVariadic()) { |
| 6934 | |
| 6935 | |
| 6936 | if (CC == CC_X86StdCall || CC == CC_X86FastCall) |
| 6937 | return S.Diag(attr.getLoc(), diag::warn_cconv_ignored) |
| 6938 | << FunctionType::getNameForCallConv(CC) |
| 6939 | << (int)Sema::CallingConventionIgnoredReason::VariadicFunction; |
| 6940 | |
| 6941 | attr.setInvalid(); |
| 6942 | return S.Diag(attr.getLoc(), diag::err_cconv_varargs) |
| 6943 | << FunctionType::getNameForCallConv(CC); |
| 6944 | } |
| 6945 | } |
| 6946 | |
| 6947 | |
| 6948 | if (CC == CC_X86FastCall && fn->getHasRegParm()) { |
| 6949 | S.Diag(attr.getLoc(), diag::err_attributes_are_not_compatible) |
| 6950 | << "regparm" << FunctionType::getNameForCallConv(CC_X86FastCall); |
| 6951 | attr.setInvalid(); |
| 6952 | return true; |
| 6953 | } |
| 6954 | |
| 6955 | |
| 6956 | |
| 6957 | |
| 6958 | QualType Equivalent; |
| 6959 | if (CCOld == CC) { |
| 6960 | Equivalent = type; |
| 6961 | } else { |
| 6962 | auto EI = unwrapped.get()->getExtInfo().withCallingConv(CC); |
| 6963 | Equivalent = |
| 6964 | unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI)); |
| 6965 | } |
| 6966 | type = state.getAttributedType(CCAttr, type, Equivalent); |
| 6967 | return true; |
| 6968 | } |
| 6969 | |
| 6970 | bool Sema::hasExplicitCallingConv(QualType &T) { |
| 6971 | QualType R = T.IgnoreParens(); |
| 6972 | while (const AttributedType *AT = dyn_cast<AttributedType>(R)) { |
| 6973 | if (AT->isCallingConv()) |
| 6974 | return true; |
| 6975 | R = AT->getModifiedType().IgnoreParens(); |
| 6976 | } |
| 6977 | return false; |
| 6978 | } |
| 6979 | |
| 6980 | void Sema::adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, |
| 6981 | SourceLocation Loc) { |
| 6982 | FunctionTypeUnwrapper Unwrapped(*this, T); |
| 6983 | const FunctionType *FT = Unwrapped.get(); |
| 6984 | bool IsVariadic = (isa<FunctionProtoType>(FT) && |
| 6985 | cast<FunctionProtoType>(FT)->isVariadic()); |
| 6986 | CallingConv CurCC = FT->getCallConv(); |
| 6987 | CallingConv ToCC = Context.getDefaultCallingConvention(IsVariadic, !IsStatic); |
| 6988 | |
| 6989 | if (CurCC == ToCC) |
| 6990 | return; |
| 6991 | |
| 6992 | |
| 6993 | |
| 6994 | if (Context.getTargetInfo().getCXXABI().isMicrosoft() && IsCtorOrDtor) { |
| 6995 | |
| 6996 | |
| 6997 | if (CurCC != CC_X86StdCall) |
| 6998 | Diag(Loc, diag::warn_cconv_ignored) |
| 6999 | << FunctionType::getNameForCallConv(CurCC) |
| 7000 | << (int)Sema::CallingConventionIgnoredReason::ConstructorDestructor; |
| 7001 | |
| 7002 | } else { |
| 7003 | |
| 7004 | |
| 7005 | |
| 7006 | CallingConv DefaultCC = |
| 7007 | Context.getDefaultCallingConvention(IsVariadic, IsStatic); |
| 7008 | |
| 7009 | if (CurCC != DefaultCC || DefaultCC == ToCC) |
| 7010 | return; |
| 7011 | |
| 7012 | if (hasExplicitCallingConv(T)) |
| 7013 | return; |
| 7014 | } |
| 7015 | |
| 7016 | FT = Context.adjustFunctionType(FT, FT->getExtInfo().withCallingConv(ToCC)); |
| 7017 | QualType Wrapped = Unwrapped.wrap(*this, FT); |
| 7018 | T = Context.getAdjustedType(T, Wrapped); |
| 7019 | } |
| 7020 | |
| 7021 | |
| 7022 | |
| 7023 | |
| 7024 | |
| 7025 | |
| 7026 | |
| 7027 | |
| 7028 | static void HandleVectorSizeAttr(QualType &CurType, const ParsedAttr &Attr, |
| 7029 | Sema &S) { |
| 7030 | |
| 7031 | if (Attr.getNumArgs() != 1) { |
| 7032 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr |
| 7033 | << 1; |
| 7034 | Attr.setInvalid(); |
| 7035 | return; |
| 7036 | } |
| 7037 | |
| 7038 | Expr *SizeExpr; |
| 7039 | |
| 7040 | if (Attr.isArgIdent(0)) { |
| 7041 | CXXScopeSpec SS; |
| 7042 | SourceLocation TemplateKWLoc; |
| 7043 | UnqualifiedId Id; |
| 7044 | Id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc()); |
| 7045 | |
| 7046 | ExprResult Size = S.ActOnIdExpression(S.getCurScope(), SS, TemplateKWLoc, |
| 7047 | Id, , |
| 7048 | ); |
| 7049 | |
| 7050 | if (Size.isInvalid()) |
| 7051 | return; |
| 7052 | SizeExpr = Size.get(); |
| 7053 | } else { |
| 7054 | SizeExpr = Attr.getArgAsExpr(0); |
| 7055 | } |
| 7056 | |
| 7057 | QualType T = S.BuildVectorType(CurType, SizeExpr, Attr.getLoc()); |
| 7058 | if (!T.isNull()) |
| 7059 | CurType = T; |
| 7060 | else |
| 7061 | Attr.setInvalid(); |
| 7062 | } |
| 7063 | |
| 7064 | |
| 7065 | |
| 7066 | static void HandleExtVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr, |
| 7067 | Sema &S) { |
| 7068 | |
| 7069 | if (Attr.getNumArgs() != 1) { |
| 7070 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr |
| 7071 | << 1; |
| 7072 | return; |
| 7073 | } |
| 7074 | |
| 7075 | Expr *sizeExpr; |
| 7076 | |
| 7077 | |
| 7078 | if (Attr.isArgIdent(0)) { |
| 7079 | CXXScopeSpec SS; |
| 7080 | SourceLocation TemplateKWLoc; |
| 7081 | UnqualifiedId id; |
| 7082 | id.setIdentifier(Attr.getArgAsIdent(0)->Ident, Attr.getLoc()); |
| 7083 | |
| 7084 | ExprResult Size = S.ActOnIdExpression(S.getCurScope(), SS, TemplateKWLoc, |
| 7085 | id, , |
| 7086 | ); |
| 7087 | if (Size.isInvalid()) |
| 7088 | return; |
| 7089 | |
| 7090 | sizeExpr = Size.get(); |
| 7091 | } else { |
| 7092 | sizeExpr = Attr.getArgAsExpr(0); |
| 7093 | } |
| 7094 | |
| 7095 | |
| 7096 | QualType T = S.BuildExtVectorType(CurType, sizeExpr, Attr.getLoc()); |
| 7097 | if (!T.isNull()) |
| 7098 | CurType = T; |
| 7099 | } |
| 7100 | |
| 7101 | static bool isPermittedNeonBaseType(QualType &Ty, |
| 7102 | VectorType::VectorKind VecKind, Sema &S) { |
| 7103 | const BuiltinType *BTy = Ty->getAs<BuiltinType>(); |
| 7104 | if (!BTy) |
| 7105 | return false; |
| 7106 | |
| 7107 | llvm::Triple Triple = S.Context.getTargetInfo().getTriple(); |
| 7108 | |
| 7109 | |
| 7110 | |
| 7111 | bool IsPolyUnsigned = Triple.getArch() == llvm::Triple::aarch64 || |
| 7112 | Triple.getArch() == llvm::Triple::aarch64_be; |
| 7113 | if (VecKind == VectorType::NeonPolyVector) { |
| 7114 | if (IsPolyUnsigned) { |
| 7115 | |
| 7116 | return BTy->getKind() == BuiltinType::UChar || |
| 7117 | BTy->getKind() == BuiltinType::UShort || |
| 7118 | BTy->getKind() == BuiltinType::ULong || |
| 7119 | BTy->getKind() == BuiltinType::ULongLong; |
| 7120 | } else { |
| 7121 | |
| 7122 | return BTy->getKind() == BuiltinType::SChar || |
| 7123 | BTy->getKind() == BuiltinType::Short; |
| 7124 | } |
| 7125 | } |
| 7126 | |
| 7127 | |
| 7128 | |
| 7129 | bool Is64Bit = Triple.getArch() == llvm::Triple::aarch64 || |
| 7130 | Triple.getArch() == llvm::Triple::aarch64_be; |
| 7131 | |
| 7132 | if (Is64Bit && BTy->getKind() == BuiltinType::Double) |
| 7133 | return true; |
| 7134 | |
| 7135 | return BTy->getKind() == BuiltinType::SChar || |
| 7136 | BTy->getKind() == BuiltinType::UChar || |
| 7137 | BTy->getKind() == BuiltinType::Short || |
| 7138 | BTy->getKind() == BuiltinType::UShort || |
| 7139 | BTy->getKind() == BuiltinType::Int || |
| 7140 | BTy->getKind() == BuiltinType::UInt || |
| 7141 | BTy->getKind() == BuiltinType::Long || |
| 7142 | BTy->getKind() == BuiltinType::ULong || |
| 7143 | BTy->getKind() == BuiltinType::LongLong || |
| 7144 | BTy->getKind() == BuiltinType::ULongLong || |
| 7145 | BTy->getKind() == BuiltinType::Float || |
| 7146 | BTy->getKind() == BuiltinType::Half; |
| 7147 | } |
| 7148 | |
| 7149 | |
| 7150 | |
| 7151 | |
| 7152 | |
| 7153 | |
| 7154 | |
| 7155 | |
| 7156 | static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr, |
| 7157 | Sema &S, VectorType::VectorKind VecKind) { |
| 7158 | |
| 7159 | if (!S.Context.getTargetInfo().hasFeature("neon")) { |
| 7160 | S.Diag(Attr.getLoc(), diag::err_attribute_unsupported) << Attr; |
| 7161 | Attr.setInvalid(); |
| 7162 | return; |
| 7163 | } |
| 7164 | |
| 7165 | if (Attr.getNumArgs() != 1) { |
| 7166 | S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr |
| 7167 | << 1; |
| 7168 | Attr.setInvalid(); |
| 7169 | return; |
| 7170 | } |
| 7171 | |
| 7172 | Expr *numEltsExpr = static_cast<Expr *>(Attr.getArgAsExpr(0)); |
| 7173 | llvm::APSInt numEltsInt(32); |
| 7174 | if (numEltsExpr->isTypeDependent() || numEltsExpr->isValueDependent() || |
| 7175 | !numEltsExpr->isIntegerConstantExpr(numEltsInt, S.Context)) { |
| 7176 | S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) |
| 7177 | << Attr << AANT_ArgumentIntegerConstant |
| 7178 | << numEltsExpr->getSourceRange(); |
| 7179 | Attr.setInvalid(); |
| 7180 | return; |
| 7181 | } |
| 7182 | |
| 7183 | if (!isPermittedNeonBaseType(CurType, VecKind, S)) { |
| 7184 | S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) << CurType; |
| 7185 | Attr.setInvalid(); |
| 7186 | return; |
| 7187 | } |
| 7188 | |
| 7189 | |
| 7190 | unsigned typeSize = static_cast<unsigned>(S.Context.getTypeSize(CurType)); |
| 7191 | unsigned numElts = static_cast<unsigned>(numEltsInt.getZExtValue()); |
| 7192 | unsigned vecSize = typeSize * numElts; |
| 7193 | if (vecSize != 64 && vecSize != 128) { |
| 7194 | S.Diag(Attr.getLoc(), diag::err_attribute_bad_neon_vector_size) << CurType; |
| 7195 | Attr.setInvalid(); |
| 7196 | return; |
| 7197 | } |
| 7198 | |
| 7199 | CurType = S.Context.getVectorType(CurType, numElts, VecKind); |
| 7200 | } |
| 7201 | |
| 7202 | |
| 7203 | static void HandleOpenCLAccessAttr(QualType &CurType, const ParsedAttr &Attr, |
| 7204 | Sema &S) { |
| 7205 | |
| 7206 | if (!(CurType->isImageType() || CurType->isPipeType())) { |
| 7207 | S.Diag(Attr.getLoc(), diag::err_opencl_invalid_access_qualifier); |
| 7208 | Attr.setInvalid(); |
| 7209 | return; |
| 7210 | } |
| 7211 | |
| 7212 | if (const TypedefType* TypedefTy = CurType->getAs<TypedefType>()) { |
| 7213 | QualType BaseTy = TypedefTy->desugar(); |
| 7214 | |
| 7215 | std::string PrevAccessQual; |
| 7216 | if (BaseTy->isPipeType()) { |
| 7217 | if (TypedefTy->getDecl()->hasAttr<OpenCLAccessAttr>()) { |
| 7218 | OpenCLAccessAttr *Attr = |
| 7219 | TypedefTy->getDecl()->getAttr<OpenCLAccessAttr>(); |
| 7220 | PrevAccessQual = Attr->getSpelling(); |
| 7221 | } else { |
| 7222 | PrevAccessQual = "read_only"; |
| 7223 | } |
| 7224 | } else if (const BuiltinType* ImgType = BaseTy->getAs<BuiltinType>()) { |
| 7225 | |
| 7226 | switch (ImgType->getKind()) { |
| 7227 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 7228 | case BuiltinType::Id: \ |
| 7229 | PrevAccessQual = #Access; \ |
| 7230 | break; |
| 7231 | #include "clang/Basic/OpenCLImageTypes.def" |
| 7232 | default: |
| 7233 | llvm_unreachable("Unable to find corresponding image type."); |
| 7234 | } |
| 7235 | } else { |
| 7236 | llvm_unreachable("unexpected type"); |
| 7237 | } |
| 7238 | StringRef AttrName = Attr.getName()->getName(); |
| 7239 | if (PrevAccessQual == AttrName.ltrim("_")) { |
| 7240 | |
| 7241 | S.Diag(Attr.getLoc(), diag::warn_duplicate_declspec) |
| 7242 | << AttrName << Attr.getRange(); |
| 7243 | } else { |
| 7244 | |
| 7245 | S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers); |
| 7246 | } |
| 7247 | |
| 7248 | S.Diag(TypedefTy->getDecl()->getBeginLoc(), |
| 7249 | diag::note_opencl_typedef_access_qualifier) << PrevAccessQual; |
| 7250 | } else if (CurType->isPipeType()) { |
| 7251 | if (Attr.getSemanticSpelling() == OpenCLAccessAttr::Keyword_write_only) { |
| 7252 | QualType ElemType = CurType->getAs<PipeType>()->getElementType(); |
| 7253 | CurType = S.Context.getWritePipeType(ElemType); |
| 7254 | } |
| 7255 | } |
| 7256 | } |
| 7257 | |
| 7258 | static void deduceOpenCLImplicitAddrSpace(TypeProcessingState &State, |
| 7259 | QualType &T, TypeAttrLocation TAL) { |
| 7260 | Declarator &D = State.getDeclarator(); |
| 7261 | |
| 7262 | |
| 7263 | |
| 7264 | |
| 7265 | |
| 7266 | |
| 7267 | |
| 7268 | |
| 7269 | |
| 7270 | |
| 7271 | |
| 7272 | |
| 7273 | |
| 7274 | |
| 7275 | |
| 7276 | |
| 7277 | |
| 7278 | |
| 7279 | |
| 7280 | |
| 7281 | auto ChunkIndex = State.getCurrentChunkIndex(); |
| 7282 | bool IsPointee = |
| 7283 | ChunkIndex > 0 && |
| 7284 | (D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Pointer || |
| 7285 | D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer || |
| 7286 | D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference); |
| 7287 | bool IsFuncReturnType = |
| 7288 | ChunkIndex > 0 && |
| 7289 | D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Function; |
| 7290 | bool IsFuncType = |
| 7291 | ChunkIndex < D.getNumTypeObjects() && |
| 7292 | D.getTypeObject(ChunkIndex).Kind == DeclaratorChunk::Function; |
| 7293 | if ( |
| 7294 | |
| 7295 | IsFuncReturnType || IsFuncType || |
| 7296 | |
| 7297 | |
| 7298 | (D.getContext() == DeclaratorContext::MemberContext && !IsPointee) || |
| 7299 | |
| 7300 | |
| 7301 | |
| 7302 | (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef && |
| 7303 | !IsPointee) || |
| 7304 | |
| 7305 | |
| 7306 | (T->isVoidType() && !IsPointee) || |
| 7307 | |
| 7308 | |
| 7309 | T->isDependentType() || |
| 7310 | |
| 7311 | |
| 7312 | T->isDecltypeType()) |
| 7313 | return; |
| 7314 | |
| 7315 | LangAS ImpAddr = LangAS::Default; |
| 7316 | |
| 7317 | |
| 7318 | |
| 7319 | |
| 7320 | |
| 7321 | if (State.getSema().getLangOpts().OpenCLVersion <= 120 && |
| 7322 | !State.getSema().getLangOpts().OpenCLCPlusPlus) { |
| 7323 | ImpAddr = LangAS::opencl_private; |
| 7324 | } else { |
| 7325 | |
| 7326 | |
| 7327 | |
| 7328 | |
| 7329 | |
| 7330 | |
| 7331 | |
| 7332 | |
| 7333 | |
| 7334 | if (IsPointee) { |
| 7335 | ImpAddr = LangAS::opencl_generic; |
| 7336 | } else { |
| 7337 | if (D.getContext() == DeclaratorContext::TemplateArgContext) { |
| 7338 | |
| 7339 | } else if (D.getContext() == DeclaratorContext::FileContext) { |
| 7340 | ImpAddr = LangAS::opencl_global; |
| 7341 | } else { |
| 7342 | if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static || |
| 7343 | D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern) { |
| 7344 | ImpAddr = LangAS::opencl_global; |
| 7345 | } else { |
| 7346 | ImpAddr = LangAS::opencl_private; |
| 7347 | } |
| 7348 | } |
| 7349 | } |
| 7350 | } |
| 7351 | T = State.getSema().Context.getAddrSpaceQualType(T, ImpAddr); |
| 7352 | } |
| 7353 | |
| 7354 | static void HandleLifetimeBoundAttr(TypeProcessingState &State, |
| 7355 | QualType &CurType, |
| 7356 | ParsedAttr &Attr) { |
| 7357 | if (State.getDeclarator().isDeclarationOfFunction()) { |
| 7358 | CurType = State.getAttributedType( |
| 7359 | createSimpleAttr<LifetimeBoundAttr>(State.getSema().Context, Attr), |
| 7360 | CurType, CurType); |
| 7361 | } else { |
| 7362 | Attr.diagnoseAppertainsTo(State.getSema(), nullptr); |
| 7363 | } |
| 7364 | } |
| 7365 | |
| 7366 | |
| 7367 | static void processTypeAttrs(TypeProcessingState &state, QualType &type, |
| 7368 | TypeAttrLocation TAL, |
| 7369 | ParsedAttributesView &attrs) { |
| 7370 | |
| 7371 | |
| 7372 | |
| 7373 | |
| 7374 | |
| 7375 | |
| 7376 | |
| 7377 | |
| 7378 | ParsedAttributesView AttrsCopy{attrs}; |
| 7379 | |
| 7380 | state.setParsedNoDeref(false); |
| 7381 | |
| 7382 | for (ParsedAttr &attr : AttrsCopy) { |
| 7383 | |
| 7384 | |
| 7385 | if (attr.isInvalid()) |
| 7386 | continue; |
| 7387 | |
| 7388 | if (attr.isCXX11Attribute()) { |
| 7389 | |
| 7390 | |
| 7391 | |
| 7392 | |
| 7393 | if (attr.isGNUScope()) { |
| 7394 | bool IsTypeAttr = attr.isTypeAttr(); |
| 7395 | if (TAL == TAL_DeclChunk) { |
| 7396 | state.getSema().Diag(attr.getLoc(), |
| 7397 | IsTypeAttr |
| 7398 | ? diag::warn_gcc_ignores_type_attr |
| 7399 | : diag::warn_cxx11_gnu_attribute_on_type) |
| 7400 | << attr.getName(); |
| 7401 | if (!IsTypeAttr) |
| 7402 | continue; |
| 7403 | } |
| 7404 | } else if (TAL != TAL_DeclChunk && |
| 7405 | attr.getKind() != ParsedAttr::AT_AddressSpace) { |
| 7406 | |
| 7407 | |
| 7408 | |
| 7409 | continue; |
| 7410 | } |
| 7411 | } |
| 7412 | |
| 7413 | |
| 7414 | |
| 7415 | switch (attr.getKind()) { |
| 7416 | default: |
| 7417 | |
| 7418 | if (attr.isCXX11Attribute() && TAL == TAL_DeclChunk) { |
| 7419 | state.getSema().Diag(attr.getLoc(), diag::err_attribute_not_type_attr) |
| 7420 | << attr; |
| 7421 | attr.setUsedAsTypeAttr(); |
| 7422 | } |
| 7423 | break; |
| 7424 | |
| 7425 | case ParsedAttr::UnknownAttribute: |
| 7426 | if (attr.isCXX11Attribute() && TAL == TAL_DeclChunk) |
| 7427 | state.getSema().Diag(attr.getLoc(), |
| 7428 | diag::warn_unknown_attribute_ignored) |
| 7429 | << attr.getName(); |
| 7430 | break; |
| 7431 | |
| 7432 | case ParsedAttr::IgnoredAttribute: |
| 7433 | break; |
| 7434 | |
| 7435 | case ParsedAttr::AT_MayAlias: |
| 7436 | |
| 7437 | |
| 7438 | attr.setUsedAsTypeAttr(); |
| 7439 | break; |
| 7440 | case ParsedAttr::AT_OpenCLPrivateAddressSpace: |
| 7441 | case ParsedAttr::AT_OpenCLGlobalAddressSpace: |
| 7442 | case ParsedAttr::AT_OpenCLLocalAddressSpace: |
| 7443 | case ParsedAttr::AT_OpenCLConstantAddressSpace: |
| 7444 | case ParsedAttr::AT_OpenCLGenericAddressSpace: |
| 7445 | case ParsedAttr::AT_AddressSpace: |
| 7446 | HandleAddressSpaceTypeAttribute(type, attr, state); |
| 7447 | attr.setUsedAsTypeAttr(); |
| 7448 | break; |
| 7449 | OBJC_POINTER_TYPE_ATTRS_CASELIST: |
| 7450 | if (!handleObjCPointerTypeAttr(state, attr, type)) |
| 7451 | distributeObjCPointerTypeAttr(state, attr, type); |
| 7452 | attr.setUsedAsTypeAttr(); |
| 7453 | break; |
| 7454 | case ParsedAttr::AT_VectorSize: |
| 7455 | HandleVectorSizeAttr(type, attr, state.getSema()); |
| 7456 | attr.setUsedAsTypeAttr(); |
| 7457 | break; |
| 7458 | case ParsedAttr::AT_ExtVectorType: |
| 7459 | HandleExtVectorTypeAttr(type, attr, state.getSema()); |
| 7460 | attr.setUsedAsTypeAttr(); |
| 7461 | break; |
| 7462 | case ParsedAttr::AT_NeonVectorType: |
| 7463 | HandleNeonVectorTypeAttr(type, attr, state.getSema(), |
| 7464 | VectorType::NeonVector); |
| 7465 | attr.setUsedAsTypeAttr(); |
| 7466 | break; |
| 7467 | case ParsedAttr::AT_NeonPolyVectorType: |
| 7468 | HandleNeonVectorTypeAttr(type, attr, state.getSema(), |
| 7469 | VectorType::NeonPolyVector); |
| 7470 | attr.setUsedAsTypeAttr(); |
| 7471 | break; |
| 7472 | case ParsedAttr::AT_OpenCLAccess: |
| 7473 | HandleOpenCLAccessAttr(type, attr, state.getSema()); |
| 7474 | attr.setUsedAsTypeAttr(); |
| 7475 | break; |
| 7476 | case ParsedAttr::AT_LifetimeBound: |
| 7477 | if (TAL == TAL_DeclChunk) |
| 7478 | HandleLifetimeBoundAttr(state, type, attr); |
| 7479 | break; |
| 7480 | |
| 7481 | case ParsedAttr::AT_NoDeref: { |
| 7482 | ASTContext &Ctx = state.getSema().Context; |
| 7483 | type = state.getAttributedType(createSimpleAttr<NoDerefAttr>(Ctx, attr), |
| 7484 | type, type); |
| 7485 | attr.setUsedAsTypeAttr(); |
| 7486 | state.setParsedNoDeref(true); |
| 7487 | break; |
| 7488 | } |
| 7489 | |
| 7490 | MS_TYPE_ATTRS_CASELIST: |
| 7491 | if (!handleMSPointerTypeQualifierAttr(state, attr, type)) |
| 7492 | attr.setUsedAsTypeAttr(); |
| 7493 | break; |
| 7494 | |
| 7495 | |
| 7496 | NULLABILITY_TYPE_ATTRS_CASELIST: |
| 7497 | |
| 7498 | |
| 7499 | |
| 7500 | if (type->canHaveNullability() || type->isDependentType() || |
| 7501 | type->isArrayType() || |
| 7502 | !distributeNullabilityTypeAttr(state, type, attr)) { |
| 7503 | unsigned endIndex; |
| 7504 | if (TAL == TAL_DeclChunk) |
| 7505 | endIndex = state.getCurrentChunkIndex(); |
| 7506 | else |
| 7507 | endIndex = state.getDeclarator().getNumTypeObjects(); |
| 7508 | bool allowOnArrayType = |
| 7509 | state.getDeclarator().isPrototypeContext() && |
| 7510 | !hasOuterPointerLikeChunk(state.getDeclarator(), endIndex); |
| 7511 | if (checkNullabilityTypeSpecifier( |
| 7512 | state, |
| 7513 | type, |
| 7514 | attr, |
| 7515 | allowOnArrayType)) { |
| 7516 | attr.setInvalid(); |
| 7517 | } |
| 7518 | |
| 7519 | attr.setUsedAsTypeAttr(); |
| 7520 | } |
| 7521 | break; |
| 7522 | |
| 7523 | case ParsedAttr::AT_ObjCKindOf: |
| 7524 | |
| 7525 | switch (TAL) { |
| 7526 | case TAL_DeclSpec: |
| 7527 | break; |
| 7528 | |
| 7529 | case TAL_DeclChunk: |
| 7530 | case TAL_DeclName: |
| 7531 | state.getSema().Diag(attr.getLoc(), |
| 7532 | diag::err_objc_kindof_wrong_position) |
| 7533 | << FixItHint::CreateRemoval(attr.getLoc()) |
| 7534 | << FixItHint::CreateInsertion( |
| 7535 | state.getDeclarator().getDeclSpec().getBeginLoc(), |
| 7536 | "__kindof "); |
| 7537 | break; |
| 7538 | } |
| 7539 | |
| 7540 | |
| 7541 | if (checkObjCKindOfType(state, type, attr)) |
| 7542 | attr.setInvalid(); |
| 7543 | break; |
| 7544 | |
| 7545 | FUNCTION_TYPE_ATTRS_CASELIST: |
| 7546 | attr.setUsedAsTypeAttr(); |
| 7547 | |
| 7548 | |
| 7549 | |
| 7550 | if (TAL == TAL_DeclSpec) |
| 7551 | distributeFunctionTypeAttrFromDeclSpec(state, attr, type); |
| 7552 | |
| 7553 | |
| 7554 | else if (!handleFunctionTypeAttr(state, attr, type)) |
| 7555 | distributeFunctionTypeAttr(state, attr, type); |
| 7556 | break; |
| 7557 | } |
| 7558 | } |
| 7559 | |
| 7560 | if (!state.getSema().getLangOpts().OpenCL || |
| 7561 | type.getAddressSpace() != LangAS::Default) |
| 7562 | return; |
| 7563 | |
| 7564 | deduceOpenCLImplicitAddrSpace(state, type, TAL); |
| 7565 | } |
| 7566 | |
| 7567 | void Sema::completeExprArrayBound(Expr *E) { |
| 7568 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParens())) { |
| 7569 | if (VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 7570 | if (isTemplateInstantiation(Var->getTemplateSpecializationKind())) { |
| 7571 | auto *Def = Var->getDefinition(); |
| 7572 | if (!Def) { |
| 7573 | SourceLocation PointOfInstantiation = E->getExprLoc(); |
| 7574 | InstantiateVariableDefinition(PointOfInstantiation, Var); |
| 7575 | Def = Var->getDefinition(); |
| 7576 | |
| 7577 | |
| 7578 | |
| 7579 | |
| 7580 | |
| 7581 | |
| 7582 | if (Var->getPointOfInstantiation().isInvalid() && Def) { |
| 7583 | (0) . __assert_fail ("Var->getTemplateSpecializationKind() == TSK_ImplicitInstantiation && \"explicit instantiation with no point of instantiation\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 7585, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Var->getTemplateSpecializationKind() == |
| 7584 | (0) . __assert_fail ("Var->getTemplateSpecializationKind() == TSK_ImplicitInstantiation && \"explicit instantiation with no point of instantiation\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 7585, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> TSK_ImplicitInstantiation && |
| 7585 | (0) . __assert_fail ("Var->getTemplateSpecializationKind() == TSK_ImplicitInstantiation && \"explicit instantiation with no point of instantiation\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 7585, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "explicit instantiation with no point of instantiation"); |
| 7586 | Var->setTemplateSpecializationKind( |
| 7587 | Var->getTemplateSpecializationKind(), PointOfInstantiation); |
| 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | |
| 7592 | |
| 7593 | if (Def) { |
| 7594 | DRE->setDecl(Def); |
| 7595 | QualType T = Def->getType(); |
| 7596 | DRE->setType(T); |
| 7597 | |
| 7598 | E->setType(T); |
| 7599 | } |
| 7600 | |
| 7601 | |
| 7602 | |
| 7603 | |
| 7604 | } |
| 7605 | } |
| 7606 | } |
| 7607 | } |
| 7608 | |
| 7609 | |
| 7610 | |
| 7611 | |
| 7612 | |
| 7613 | |
| 7614 | |
| 7615 | |
| 7616 | |
| 7617 | |
| 7618 | |
| 7619 | |
| 7620 | |
| 7621 | |
| 7622 | |
| 7623 | bool Sema::RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser) { |
| 7624 | QualType T = E->getType(); |
| 7625 | |
| 7626 | |
| 7627 | |
| 7628 | |
| 7629 | |
| 7630 | if (T->isIncompleteArrayType()) { |
| 7631 | completeExprArrayBound(E); |
| 7632 | T = E->getType(); |
| 7633 | } |
| 7634 | |
| 7635 | |
| 7636 | |
| 7637 | |
| 7638 | return RequireCompleteType(E->getExprLoc(), T, Diagnoser); |
| 7639 | } |
| 7640 | |
| 7641 | bool Sema::RequireCompleteExprType(Expr *E, unsigned DiagID) { |
| 7642 | BoundTypeDiagnoser<> Diagnoser(DiagID); |
| 7643 | return RequireCompleteExprType(E, Diagnoser); |
| 7644 | } |
| 7645 | |
| 7646 | |
| 7647 | |
| 7648 | |
| 7649 | |
| 7650 | |
| 7651 | |
| 7652 | |
| 7653 | |
| 7654 | |
| 7655 | |
| 7656 | |
| 7657 | |
| 7658 | |
| 7659 | |
| 7660 | |
| 7661 | |
| 7662 | |
| 7663 | bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, |
| 7664 | TypeDiagnoser &Diagnoser) { |
| 7665 | if (RequireCompleteTypeImpl(Loc, T, &Diagnoser)) |
| 7666 | return true; |
| 7667 | if (const TagType *Tag = T->getAs<TagType>()) { |
| 7668 | if (!Tag->getDecl()->isCompleteDefinitionRequired()) { |
| 7669 | Tag->getDecl()->setCompleteDefinitionRequired(); |
| 7670 | Consumer.HandleTagDeclRequiredDefinition(Tag->getDecl()); |
| 7671 | } |
| 7672 | } |
| 7673 | return false; |
| 7674 | } |
| 7675 | |
| 7676 | bool Sema::hasStructuralCompatLayout(Decl *D, Decl *Suggested) { |
| 7677 | llvm::DenseSet<std::pair<Decl *, Decl *>> NonEquivalentDecls; |
| 7678 | if (!Suggested) |
| 7679 | return false; |
| 7680 | |
| 7681 | |
| 7682 | |
| 7683 | StructuralEquivalenceContext Ctx( |
| 7684 | D->getASTContext(), Suggested->getASTContext(), NonEquivalentDecls, |
| 7685 | StructuralEquivalenceKind::Default, |
| 7686 | false , true , |
| 7687 | true ); |
| 7688 | return Ctx.IsEquivalent(D, Suggested); |
| 7689 | } |
| 7690 | |
| 7691 | |
| 7692 | |
| 7693 | |
| 7694 | |
| 7695 | |
| 7696 | |
| 7697 | |
| 7698 | |
| 7699 | |
| 7700 | bool Sema::hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
| 7701 | bool OnlyNeedComplete) { |
| 7702 | |
| 7703 | if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility) |
| 7704 | return true; |
| 7705 | |
| 7706 | |
| 7707 | |
| 7708 | if (isa<TagDecl>(D) && cast<TagDecl>(D)->isBeingDefined()) { |
| 7709 | |
| 7710 | |
| 7711 | return true; |
| 7712 | } else if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 7713 | if (auto *Pattern = RD->getTemplateInstantiationPattern()) |
| 7714 | RD = Pattern; |
| 7715 | D = RD->getDefinition(); |
| 7716 | } else if (auto *ED = dyn_cast<EnumDecl>(D)) { |
| 7717 | if (auto *Pattern = ED->getTemplateInstantiationPattern()) |
| 7718 | ED = Pattern; |
| 7719 | if (OnlyNeedComplete && ED->isFixed()) { |
| 7720 | |
| 7721 | |
| 7722 | |
| 7723 | *Suggested = nullptr; |
| 7724 | for (auto *Redecl : ED->redecls()) { |
| 7725 | if (isVisible(Redecl)) |
| 7726 | return true; |
| 7727 | if (Redecl->isThisDeclarationADefinition() || |
| 7728 | (Redecl->isCanonicalDecl() && !*Suggested)) |
| 7729 | *Suggested = Redecl; |
| 7730 | } |
| 7731 | return false; |
| 7732 | } |
| 7733 | D = ED->getDefinition(); |
| 7734 | } else if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| 7735 | if (auto *Pattern = FD->getTemplateInstantiationPattern()) |
| 7736 | FD = Pattern; |
| 7737 | D = FD->getDefinition(); |
| 7738 | } else if (auto *VD = dyn_cast<VarDecl>(D)) { |
| 7739 | if (auto *Pattern = VD->getTemplateInstantiationPattern()) |
| 7740 | VD = Pattern; |
| 7741 | D = VD->getDefinition(); |
| 7742 | } |
| 7743 | (0) . __assert_fail ("D && \"missing definition for pattern of instantiated definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 7743, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D && "missing definition for pattern of instantiated definition"); |
| 7744 | |
| 7745 | *Suggested = D; |
| 7746 | |
| 7747 | auto DefinitionIsVisible = [&] { |
| 7748 | |
| 7749 | if (isVisible(D)) |
| 7750 | return true; |
| 7751 | |
| 7752 | |
| 7753 | if (D->isModulePrivate() ? hasMergedDefinitionInCurrentModule(D) |
| 7754 | : hasVisibleMergedDefinition(D)) { |
| 7755 | if (CodeSynthesisContexts.empty() && |
| 7756 | !getLangOpts().ModulesLocalVisibility) { |
| 7757 | |
| 7758 | |
| 7759 | D->setVisibleDespiteOwningModule(); |
| 7760 | } |
| 7761 | return true; |
| 7762 | } |
| 7763 | |
| 7764 | return false; |
| 7765 | }; |
| 7766 | |
| 7767 | if (DefinitionIsVisible()) |
| 7768 | return true; |
| 7769 | |
| 7770 | |
| 7771 | |
| 7772 | if (auto *Source = Context.getExternalSource()) { |
| 7773 | Source->CompleteRedeclChain(D); |
| 7774 | return DefinitionIsVisible(); |
| 7775 | } |
| 7776 | |
| 7777 | return false; |
| 7778 | } |
| 7779 | |
| 7780 | |
| 7781 | static void assignInheritanceModel(Sema &S, CXXRecordDecl *RD) { |
| 7782 | RD = RD->getMostRecentNonInjectedDecl(); |
| 7783 | if (!RD->hasAttr<MSInheritanceAttr>()) { |
| 7784 | MSInheritanceAttr::Spelling IM; |
| 7785 | |
| 7786 | switch (S.MSPointerToMemberRepresentationMethod) { |
| 7787 | case LangOptions::PPTMK_BestCase: |
| 7788 | IM = RD->calculateInheritanceModel(); |
| 7789 | break; |
| 7790 | case LangOptions::PPTMK_FullGeneralitySingleInheritance: |
| 7791 | IM = MSInheritanceAttr::Keyword_single_inheritance; |
| 7792 | break; |
| 7793 | case LangOptions::PPTMK_FullGeneralityMultipleInheritance: |
| 7794 | IM = MSInheritanceAttr::Keyword_multiple_inheritance; |
| 7795 | break; |
| 7796 | case LangOptions::PPTMK_FullGeneralityVirtualInheritance: |
| 7797 | IM = MSInheritanceAttr::Keyword_unspecified_inheritance; |
| 7798 | break; |
| 7799 | } |
| 7800 | |
| 7801 | RD->addAttr(MSInheritanceAttr::CreateImplicit( |
| 7802 | S.getASTContext(), IM, |
| 7803 | S.MSPointerToMemberRepresentationMethod == |
| 7804 | LangOptions::PPTMK_BestCase, |
| 7805 | S.ImplicitMSInheritanceAttrLoc.isValid() |
| 7806 | ? S.ImplicitMSInheritanceAttrLoc |
| 7807 | : RD->getSourceRange())); |
| 7808 | S.Consumer.AssignInheritanceModel(RD); |
| 7809 | } |
| 7810 | } |
| 7811 | |
| 7812 | |
| 7813 | bool Sema::RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
| 7814 | TypeDiagnoser *Diagnoser) { |
| 7815 | |
| 7816 | |
| 7817 | |
| 7818 | |
| 7819 | |
| 7820 | |
| 7821 | |
| 7822 | |
| 7823 | if (const MemberPointerType *MPTy = T->getAs<MemberPointerType>()) { |
| 7824 | if (!MPTy->getClass()->isDependentType()) { |
| 7825 | if (getLangOpts().CompleteMemberPointers && |
| 7826 | !MPTy->getClass()->getAsCXXRecordDecl()->isBeingDefined() && |
| 7827 | RequireCompleteType(Loc, QualType(MPTy->getClass(), 0), |
| 7828 | diag::err_memptr_incomplete)) |
| 7829 | return true; |
| 7830 | |
| 7831 | |
| 7832 | |
| 7833 | if (Context.getTargetInfo().getCXXABI().isMicrosoft()) { |
| 7834 | (void)isCompleteType(Loc, QualType(MPTy->getClass(), 0)); |
| 7835 | assignInheritanceModel(*this, MPTy->getMostRecentCXXRecordDecl()); |
| 7836 | } |
| 7837 | } |
| 7838 | } |
| 7839 | |
| 7840 | NamedDecl *Def = nullptr; |
| 7841 | bool Incomplete = T->isIncompleteType(&Def); |
| 7842 | |
| 7843 | |
| 7844 | |
| 7845 | if (Def && !isa<EnumDecl>(Def)) |
| 7846 | checkSpecializationVisibility(Loc, Def); |
| 7847 | |
| 7848 | |
| 7849 | if (!Incomplete) { |
| 7850 | |
| 7851 | NamedDecl *SuggestedDef = nullptr; |
| 7852 | if (Def && |
| 7853 | !hasVisibleDefinition(Def, &SuggestedDef, )) { |
| 7854 | |
| 7855 | |
| 7856 | bool TreatAsComplete = Diagnoser && !isSFINAEContext(); |
| 7857 | if (Diagnoser && SuggestedDef) |
| 7858 | diagnoseMissingImport(Loc, SuggestedDef, MissingImportKind::Definition, |
| 7859 | ); |
| 7860 | return !TreatAsComplete; |
| 7861 | } else if (Def && !TemplateInstCallbacks.empty()) { |
| 7862 | CodeSynthesisContext TempInst; |
| 7863 | TempInst.Kind = CodeSynthesisContext::Memoization; |
| 7864 | TempInst.Template = Def; |
| 7865 | TempInst.Entity = Def; |
| 7866 | TempInst.PointOfInstantiation = Loc; |
| 7867 | atTemplateBegin(TemplateInstCallbacks, *this, TempInst); |
| 7868 | atTemplateEnd(TemplateInstCallbacks, *this, TempInst); |
| 7869 | } |
| 7870 | |
| 7871 | return false; |
| 7872 | } |
| 7873 | |
| 7874 | TagDecl *Tag = dyn_cast_or_null<TagDecl>(Def); |
| 7875 | ObjCInterfaceDecl *IFace = dyn_cast_or_null<ObjCInterfaceDecl>(Def); |
| 7876 | |
| 7877 | |
| 7878 | |
| 7879 | |
| 7880 | |
| 7881 | if (Tag || IFace) { |
| 7882 | |
| 7883 | if (Def->isInvalidDecl()) |
| 7884 | return true; |
| 7885 | |
| 7886 | |
| 7887 | if (auto *Source = Context.getExternalSource()) { |
| 7888 | if (Tag && Tag->hasExternalLexicalStorage()) |
| 7889 | Source->CompleteType(Tag); |
| 7890 | if (IFace && IFace->hasExternalLexicalStorage()) |
| 7891 | Source->CompleteType(IFace); |
| 7892 | |
| 7893 | |
| 7894 | if (!T->isIncompleteType()) |
| 7895 | return RequireCompleteTypeImpl(Loc, T, Diagnoser); |
| 7896 | } |
| 7897 | } |
| 7898 | |
| 7899 | |
| 7900 | |
| 7901 | |
| 7902 | if (auto *RD = dyn_cast_or_null<CXXRecordDecl>(Tag)) { |
| 7903 | bool Instantiated = false; |
| 7904 | bool Diagnosed = false; |
| 7905 | if (RD->isDependentContext()) { |
| 7906 | |
| 7907 | |
| 7908 | |
| 7909 | } else if (auto *ClassTemplateSpec = |
| 7910 | dyn_cast<ClassTemplateSpecializationDecl>(RD)) { |
| 7911 | if (ClassTemplateSpec->getSpecializationKind() == TSK_Undeclared) { |
| 7912 | Diagnosed = InstantiateClassTemplateSpecialization( |
| 7913 | Loc, ClassTemplateSpec, TSK_ImplicitInstantiation, |
| 7914 | Diagnoser); |
| 7915 | Instantiated = true; |
| 7916 | } |
| 7917 | } else { |
| 7918 | CXXRecordDecl *Pattern = RD->getInstantiatedFromMemberClass(); |
| 7919 | if (!RD->isBeingDefined() && Pattern) { |
| 7920 | MemberSpecializationInfo *MSI = RD->getMemberSpecializationInfo(); |
| 7921 | (0) . __assert_fail ("MSI && \"Missing member specialization information?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 7921, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(MSI && "Missing member specialization information?"); |
| 7922 | |
| 7923 | if (MSI->getTemplateSpecializationKind() != |
| 7924 | TSK_ExplicitSpecialization) { |
| 7925 | Diagnosed = InstantiateClass(Loc, RD, Pattern, |
| 7926 | getTemplateInstantiationArgs(RD), |
| 7927 | TSK_ImplicitInstantiation, |
| 7928 | Diagnoser); |
| 7929 | Instantiated = true; |
| 7930 | } |
| 7931 | } |
| 7932 | } |
| 7933 | |
| 7934 | if (Instantiated) { |
| 7935 | |
| 7936 | |
| 7937 | if (Diagnoser && Diagnosed) |
| 7938 | return true; |
| 7939 | |
| 7940 | |
| 7941 | |
| 7942 | if (!T->isIncompleteType()) |
| 7943 | return RequireCompleteTypeImpl(Loc, T, Diagnoser); |
| 7944 | } |
| 7945 | } |
| 7946 | |
| 7947 | |
| 7948 | |
| 7949 | |
| 7950 | if (!Diagnoser) |
| 7951 | return true; |
| 7952 | |
| 7953 | Diagnoser->diagnose(*this, Loc, T); |
| 7954 | |
| 7955 | |
| 7956 | |
| 7957 | if (Tag && !Tag->isInvalidDecl()) |
| 7958 | Diag(Tag->getLocation(), |
| 7959 | Tag->isBeingDefined() ? diag::note_type_being_defined |
| 7960 | : diag::note_forward_declaration) |
| 7961 | << Context.getTagDeclType(Tag); |
| 7962 | |
| 7963 | |
| 7964 | if (IFace && !IFace->isInvalidDecl()) |
| 7965 | Diag(IFace->getLocation(), diag::note_forward_class); |
| 7966 | |
| 7967 | |
| 7968 | |
| 7969 | if (ExternalSource) |
| 7970 | ExternalSource->MaybeDiagnoseMissingCompleteType(Loc, T); |
| 7971 | |
| 7972 | return true; |
| 7973 | } |
| 7974 | |
| 7975 | bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, |
| 7976 | unsigned DiagID) { |
| 7977 | BoundTypeDiagnoser<> Diagnoser(DiagID); |
| 7978 | return RequireCompleteType(Loc, T, Diagnoser); |
| 7979 | } |
| 7980 | |
| 7981 | |
| 7982 | |
| 7983 | |
| 7984 | |
| 7985 | |
| 7986 | static unsigned getLiteralDiagFromTagKind(TagTypeKind Tag) { |
| 7987 | switch (Tag) { |
| 7988 | case TTK_Struct: return 0; |
| 7989 | case TTK_Interface: return 1; |
| 7990 | case TTK_Class: return 2; |
| 7991 | default: llvm_unreachable("Invalid tag kind for literal type diagnostic!"); |
| 7992 | } |
| 7993 | } |
| 7994 | |
| 7995 | |
| 7996 | |
| 7997 | |
| 7998 | |
| 7999 | |
| 8000 | |
| 8001 | |
| 8002 | |
| 8003 | |
| 8004 | |
| 8005 | |
| 8006 | |
| 8007 | |
| 8008 | |
| 8009 | |
| 8010 | |
| 8011 | |
| 8012 | |
| 8013 | bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, |
| 8014 | TypeDiagnoser &Diagnoser) { |
| 8015 | (0) . __assert_fail ("!T->isDependentType() && \"type should not be dependent\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 8015, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!T->isDependentType() && "type should not be dependent"); |
| 8016 | |
| 8017 | QualType ElemType = Context.getBaseElementType(T); |
| 8018 | if ((isCompleteType(Loc, ElemType) || ElemType->isVoidType()) && |
| 8019 | T->isLiteralType(Context)) |
| 8020 | return false; |
| 8021 | |
| 8022 | Diagnoser.diagnose(*this, Loc, T); |
| 8023 | |
| 8024 | if (T->isVariableArrayType()) |
| 8025 | return true; |
| 8026 | |
| 8027 | const RecordType *RT = ElemType->getAs<RecordType>(); |
| 8028 | if (!RT) |
| 8029 | return true; |
| 8030 | |
| 8031 | const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); |
| 8032 | |
| 8033 | |
| 8034 | |
| 8035 | |
| 8036 | if (RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T)) |
| 8037 | return true; |
| 8038 | |
| 8039 | |
| 8040 | |
| 8041 | if (RD->isLambda() && !getLangOpts().CPlusPlus17) { |
| 8042 | Diag(RD->getLocation(), diag::note_non_literal_lambda); |
| 8043 | return true; |
| 8044 | } |
| 8045 | |
| 8046 | |
| 8047 | |
| 8048 | |
| 8049 | |
| 8050 | if (RD->getNumVBases()) { |
| 8051 | Diag(RD->getLocation(), diag::note_non_literal_virtual_base) |
| 8052 | << getLiteralDiagFromTagKind(RD->getTagKind()) << RD->getNumVBases(); |
| 8053 | for (const auto &I : RD->vbases()) |
| 8054 | Diag(I.getBeginLoc(), diag::note_constexpr_virtual_base_here) |
| 8055 | << I.getSourceRange(); |
| 8056 | } else if (!RD->isAggregate() && !RD->hasConstexprNonCopyMoveConstructor() && |
| 8057 | !RD->hasTrivialDefaultConstructor()) { |
| 8058 | Diag(RD->getLocation(), diag::note_non_literal_no_constexpr_ctors) << RD; |
| 8059 | } else if (RD->hasNonLiteralTypeFieldsOrBases()) { |
| 8060 | for (const auto &I : RD->bases()) { |
| 8061 | if (!I.getType()->isLiteralType(Context)) { |
| 8062 | Diag(I.getBeginLoc(), diag::note_non_literal_base_class) |
| 8063 | << RD << I.getType() << I.getSourceRange(); |
| 8064 | return true; |
| 8065 | } |
| 8066 | } |
| 8067 | for (const auto *I : RD->fields()) { |
| 8068 | if (!I->getType()->isLiteralType(Context) || |
| 8069 | I->getType().isVolatileQualified()) { |
| 8070 | Diag(I->getLocation(), diag::note_non_literal_field) |
| 8071 | << RD << I << I->getType() |
| 8072 | << I->getType().isVolatileQualified(); |
| 8073 | return true; |
| 8074 | } |
| 8075 | } |
| 8076 | } else if (!RD->hasTrivialDestructor()) { |
| 8077 | |
| 8078 | |
| 8079 | CXXDestructorDecl *Dtor = RD->getDestructor(); |
| 8080 | (0) . __assert_fail ("Dtor && \"class has literal fields and bases but no dtor?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 8080, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Dtor && "class has literal fields and bases but no dtor?"); |
| 8081 | if (!Dtor) |
| 8082 | return true; |
| 8083 | |
| 8084 | Diag(Dtor->getLocation(), Dtor->isUserProvided() ? |
| 8085 | diag::note_non_literal_user_provided_dtor : |
| 8086 | diag::note_non_literal_nontrivial_dtor) << RD; |
| 8087 | if (!Dtor->isUserProvided()) |
| 8088 | SpecialMemberIsTrivial(Dtor, CXXDestructor, TAH_IgnoreTrivialABI, |
| 8089 | ); |
| 8090 | } |
| 8091 | |
| 8092 | return true; |
| 8093 | } |
| 8094 | |
| 8095 | bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID) { |
| 8096 | BoundTypeDiagnoser<> Diagnoser(DiagID); |
| 8097 | return RequireLiteralType(Loc, T, Diagnoser); |
| 8098 | } |
| 8099 | |
| 8100 | |
| 8101 | |
| 8102 | |
| 8103 | QualType Sema::getElaboratedType(ElaboratedTypeKeyword Keyword, |
| 8104 | const CXXScopeSpec &SS, QualType T, |
| 8105 | TagDecl *OwnedTagDecl) { |
| 8106 | if (T.isNull()) |
| 8107 | return T; |
| 8108 | NestedNameSpecifier *NNS; |
| 8109 | if (SS.isValid()) |
| 8110 | NNS = SS.getScopeRep(); |
| 8111 | else { |
| 8112 | if (Keyword == ETK_None) |
| 8113 | return T; |
| 8114 | NNS = nullptr; |
| 8115 | } |
| 8116 | return Context.getElaboratedType(Keyword, NNS, T, OwnedTagDecl); |
| 8117 | } |
| 8118 | |
| 8119 | QualType Sema::BuildTypeofExprType(Expr *E, SourceLocation Loc) { |
| 8120 | (0) . __assert_fail ("!E->hasPlaceholderType() && \"unexpected placeholder\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 8120, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!E->hasPlaceholderType() && "unexpected placeholder"); |
| 8121 | |
| 8122 | if (!getLangOpts().CPlusPlus && E->refersToBitField()) |
| 8123 | Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 2; |
| 8124 | |
| 8125 | if (!E->isTypeDependent()) { |
| 8126 | QualType T = E->getType(); |
| 8127 | if (const TagType *TT = T->getAs<TagType>()) |
| 8128 | DiagnoseUseOfDecl(TT->getDecl(), E->getExprLoc()); |
| 8129 | } |
| 8130 | return Context.getTypeOfExprType(E); |
| 8131 | } |
| 8132 | |
| 8133 | |
| 8134 | |
| 8135 | |
| 8136 | static QualType getDecltypeForExpr(Sema &S, Expr *E) { |
| 8137 | if (E->isTypeDependent()) |
| 8138 | return S.Context.DependentTy; |
| 8139 | |
| 8140 | |
| 8141 | |
| 8142 | |
| 8143 | |
| 8144 | |
| 8145 | |
| 8146 | |
| 8147 | |
| 8148 | |
| 8149 | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) { |
| 8150 | const ValueDecl *VD = DRE->getDecl(); |
| 8151 | return VD->getType(); |
| 8152 | } else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) { |
| 8153 | if (const ValueDecl *VD = ME->getMemberDecl()) |
| 8154 | if (isa<FieldDecl>(VD) || isa<VarDecl>(VD)) |
| 8155 | return VD->getType(); |
| 8156 | } else if (const ObjCIvarRefExpr *IR = dyn_cast<ObjCIvarRefExpr>(E)) { |
| 8157 | return IR->getDecl()->getType(); |
| 8158 | } else if (const ObjCPropertyRefExpr *PR = dyn_cast<ObjCPropertyRefExpr>(E)) { |
| 8159 | if (PR->isExplicitProperty()) |
| 8160 | return PR->getExplicitProperty()->getType(); |
| 8161 | } else if (auto *PE = dyn_cast<PredefinedExpr>(E)) { |
| 8162 | return PE->getType(); |
| 8163 | } |
| 8164 | |
| 8165 | |
| 8166 | |
| 8167 | |
| 8168 | |
| 8169 | |
| 8170 | |
| 8171 | |
| 8172 | using namespace sema; |
| 8173 | if (S.getCurLambda()) { |
| 8174 | if (isa<ParenExpr>(E)) { |
| 8175 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParens())) { |
| 8176 | if (VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 8177 | QualType T = S.getCapturedDeclRefType(Var, DRE->getLocation()); |
| 8178 | if (!T.isNull()) |
| 8179 | return S.Context.getLValueReferenceType(T); |
| 8180 | } |
| 8181 | } |
| 8182 | } |
| 8183 | } |
| 8184 | |
| 8185 | |
| 8186 | |
| 8187 | |
| 8188 | QualType T = E->getType(); |
| 8189 | switch (E->getValueKind()) { |
| 8190 | |
| 8191 | |
| 8192 | case VK_XValue: T = S.Context.getRValueReferenceType(T); break; |
| 8193 | |
| 8194 | |
| 8195 | case VK_LValue: T = S.Context.getLValueReferenceType(T); break; |
| 8196 | |
| 8197 | case VK_RValue: break; |
| 8198 | } |
| 8199 | |
| 8200 | return T; |
| 8201 | } |
| 8202 | |
| 8203 | QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc, |
| 8204 | bool AsUnevaluated) { |
| 8205 | (0) . __assert_fail ("!E->hasPlaceholderType() && \"unexpected placeholder\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 8205, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!E->hasPlaceholderType() && "unexpected placeholder"); |
| 8206 | |
| 8207 | if (AsUnevaluated && CodeSynthesisContexts.empty() && |
| 8208 | E->HasSideEffects(Context, false)) { |
| 8209 | |
| 8210 | |
| 8211 | Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context); |
| 8212 | } |
| 8213 | |
| 8214 | return Context.getDecltypeType(E, getDecltypeForExpr(*this, E)); |
| 8215 | } |
| 8216 | |
| 8217 | QualType Sema::BuildUnaryTransformType(QualType BaseType, |
| 8218 | UnaryTransformType::UTTKind UKind, |
| 8219 | SourceLocation Loc) { |
| 8220 | switch (UKind) { |
| 8221 | case UnaryTransformType::EnumUnderlyingType: |
| 8222 | if (!BaseType->isDependentType() && !BaseType->isEnumeralType()) { |
| 8223 | Diag(Loc, diag::err_only_enums_have_underlying_types); |
| 8224 | return QualType(); |
| 8225 | } else { |
| 8226 | QualType Underlying = BaseType; |
| 8227 | if (!BaseType->isDependentType()) { |
| 8228 | |
| 8229 | |
| 8230 | NamedDecl *FwdDecl = nullptr; |
| 8231 | if (BaseType->isIncompleteType(&FwdDecl)) { |
| 8232 | Diag(Loc, diag::err_underlying_type_of_incomplete_enum) << BaseType; |
| 8233 | Diag(FwdDecl->getLocation(), diag::note_forward_declaration) << FwdDecl; |
| 8234 | return QualType(); |
| 8235 | } |
| 8236 | |
| 8237 | EnumDecl *ED = BaseType->getAs<EnumType>()->getDecl(); |
| 8238 | (0) . __assert_fail ("ED && \"EnumType has no EnumDecl\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaType.cpp", 8238, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ED && "EnumType has no EnumDecl"); |
| 8239 | |
| 8240 | DiagnoseUseOfDecl(ED, Loc); |
| 8241 | |
| 8242 | Underlying = ED->getIntegerType(); |
| 8243 | assert(!Underlying.isNull()); |
| 8244 | } |
| 8245 | return Context.getUnaryTransformType(BaseType, Underlying, |
| 8246 | UnaryTransformType::EnumUnderlyingType); |
| 8247 | } |
| 8248 | } |
| 8249 | llvm_unreachable("unknown unary transform type"); |
| 8250 | } |
| 8251 | |
| 8252 | QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) { |
| 8253 | if (!T->isDependentType()) { |
| 8254 | |
| 8255 | |
| 8256 | if (RequireCompleteType(Loc, T, diag::err_atomic_specifier_bad_type, 0)) |
| 8257 | return QualType(); |
| 8258 | |
| 8259 | int DisallowedKind = -1; |
| 8260 | if (T->isArrayType()) |
| 8261 | DisallowedKind = 1; |
| 8262 | else if (T->isFunctionType()) |
| 8263 | DisallowedKind = 2; |
| 8264 | else if (T->isReferenceType()) |
| 8265 | DisallowedKind = 3; |
| 8266 | else if (T->isAtomicType()) |
| 8267 | DisallowedKind = 4; |
| 8268 | else if (T.hasQualifiers()) |
| 8269 | DisallowedKind = 5; |
| 8270 | else if (!T.isTriviallyCopyableType(Context)) |
| 8271 | |
| 8272 | DisallowedKind = 6; |
| 8273 | |
| 8274 | if (DisallowedKind != -1) { |
| 8275 | Diag(Loc, diag::err_atomic_specifier_bad_type) << DisallowedKind << T; |
| 8276 | return QualType(); |
| 8277 | } |
| 8278 | |
| 8279 | |
| 8280 | } |
| 8281 | |
| 8282 | |
| 8283 | return Context.getAtomicType(T); |
| 8284 | } |
| 8285 | |