Deleted Added
full compact
SemaInit.cpp (195099) SemaInit.cpp (195341)
1//===--- SemaInit.cpp - Semantic Analysis for Initializers ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 329 unchanged lines hidden (view full) ---

338 "Should not have void type");
339 SourceLocation Loc = ILE->getSourceRange().getBegin();
340 if (ILE->getSyntacticForm())
341 Loc = ILE->getSyntacticForm()->getSourceRange().getBegin();
342
343 if (const RecordType *RType = ILE->getType()->getAsRecordType()) {
344 unsigned Init = 0, NumInits = ILE->getNumInits();
345 for (RecordDecl::field_iterator
1//===--- SemaInit.cpp - Semantic Analysis for Initializers ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 329 unchanged lines hidden (view full) ---

338 "Should not have void type");
339 SourceLocation Loc = ILE->getSourceRange().getBegin();
340 if (ILE->getSyntacticForm())
341 Loc = ILE->getSyntacticForm()->getSourceRange().getBegin();
342
343 if (const RecordType *RType = ILE->getType()->getAsRecordType()) {
344 unsigned Init = 0, NumInits = ILE->getNumInits();
345 for (RecordDecl::field_iterator
346 Field = RType->getDecl()->field_begin(SemaRef.Context),
347 FieldEnd = RType->getDecl()->field_end(SemaRef.Context);
346 Field = RType->getDecl()->field_begin(),
347 FieldEnd = RType->getDecl()->field_end();
348 Field != FieldEnd; ++Field) {
349 if (Field->isUnnamedBitfield())
350 continue;
351
352 if (Init >= NumInits || !ILE->getInit(Init)) {
353 if (Field->getType()->isReferenceType()) {
354 // C++ [dcl.init.aggr]p9:
355 // If an incomplete or empty initializer-list leaves a

--- 88 unchanged lines hidden (view full) ---

444 }
445 return maxElements;
446}
447
448int InitListChecker::numStructUnionElements(QualType DeclType) {
449 RecordDecl *structDecl = DeclType->getAsRecordType()->getDecl();
450 int InitializableMembers = 0;
451 for (RecordDecl::field_iterator
348 Field != FieldEnd; ++Field) {
349 if (Field->isUnnamedBitfield())
350 continue;
351
352 if (Init >= NumInits || !ILE->getInit(Init)) {
353 if (Field->getType()->isReferenceType()) {
354 // C++ [dcl.init.aggr]p9:
355 // If an incomplete or empty initializer-list leaves a

--- 88 unchanged lines hidden (view full) ---

444 }
445 return maxElements;
446}
447
448int InitListChecker::numStructUnionElements(QualType DeclType) {
449 RecordDecl *structDecl = DeclType->getAsRecordType()->getDecl();
450 int InitializableMembers = 0;
451 for (RecordDecl::field_iterator
452 Field = structDecl->field_begin(SemaRef.Context),
453 FieldEnd = structDecl->field_end(SemaRef.Context);
452 Field = structDecl->field_begin(),
453 FieldEnd = structDecl->field_end();
454 Field != FieldEnd; ++Field) {
455 if ((*Field)->getIdentifier() || !(*Field)->isBitField())
456 ++InitializableMembers;
457 }
458 if (structDecl->isUnion())
459 return std::min(InitializableMembers, 1);
460 return InitializableMembers - structDecl->hasFlexibleArrayMember();
461}

--- 113 unchanged lines hidden (view full) ---

575 bool TopLevelObject) {
576 if (DeclType->isScalarType()) {
577 CheckScalarType(IList, DeclType, Index, StructuredList, StructuredIndex);
578 } else if (DeclType->isVectorType()) {
579 CheckVectorType(IList, DeclType, Index, StructuredList, StructuredIndex);
580 } else if (DeclType->isAggregateType()) {
581 if (DeclType->isRecordType()) {
582 RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
454 Field != FieldEnd; ++Field) {
455 if ((*Field)->getIdentifier() || !(*Field)->isBitField())
456 ++InitializableMembers;
457 }
458 if (structDecl->isUnion())
459 return std::min(InitializableMembers, 1);
460 return InitializableMembers - structDecl->hasFlexibleArrayMember();
461}

--- 113 unchanged lines hidden (view full) ---

575 bool TopLevelObject) {
576 if (DeclType->isScalarType()) {
577 CheckScalarType(IList, DeclType, Index, StructuredList, StructuredIndex);
578 } else if (DeclType->isVectorType()) {
579 CheckVectorType(IList, DeclType, Index, StructuredList, StructuredIndex);
580 } else if (DeclType->isAggregateType()) {
581 if (DeclType->isRecordType()) {
582 RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
583 CheckStructUnionTypes(IList, DeclType, RD->field_begin(SemaRef.Context),
583 CheckStructUnionTypes(IList, DeclType, RD->field_begin(),
584 SubobjectIsDesignatorContext, Index,
585 StructuredList, StructuredIndex,
586 TopLevelObject);
587 } else if (DeclType->isArrayType()) {
588 llvm::APSInt Zero(
589 SemaRef.Context.getTypeSize(SemaRef.Context.getSizeType()),
590 false);
591 CheckArrayType(IList, DeclType, Zero, SubobjectIsDesignatorContext, Index,

--- 349 unchanged lines hidden (view full) ---

941 if (structDecl->isInvalidDecl()) {
942 hadError = true;
943 return;
944 }
945
946 if (DeclType->isUnionType() && IList->getNumInits() == 0) {
947 // Value-initialize the first named member of the union.
948 RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
584 SubobjectIsDesignatorContext, Index,
585 StructuredList, StructuredIndex,
586 TopLevelObject);
587 } else if (DeclType->isArrayType()) {
588 llvm::APSInt Zero(
589 SemaRef.Context.getTypeSize(SemaRef.Context.getSizeType()),
590 false);
591 CheckArrayType(IList, DeclType, Zero, SubobjectIsDesignatorContext, Index,

--- 349 unchanged lines hidden (view full) ---

941 if (structDecl->isInvalidDecl()) {
942 hadError = true;
943 return;
944 }
945
946 if (DeclType->isUnionType() && IList->getNumInits() == 0) {
947 // Value-initialize the first named member of the union.
948 RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
949 for (RecordDecl::field_iterator FieldEnd = RD->field_end(SemaRef.Context);
949 for (RecordDecl::field_iterator FieldEnd = RD->field_end();
950 Field != FieldEnd; ++Field) {
951 if (Field->getDeclName()) {
952 StructuredList->setInitializedFieldInUnion(*Field);
953 break;
954 }
955 }
956 return;
957 }
958
959 // If structDecl is a forward declaration, this loop won't do
960 // anything except look at designated initializers; That's okay,
961 // because an error should get printed out elsewhere. It might be
962 // worthwhile to skip over the rest of the initializer, though.
963 RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
950 Field != FieldEnd; ++Field) {
951 if (Field->getDeclName()) {
952 StructuredList->setInitializedFieldInUnion(*Field);
953 break;
954 }
955 }
956 return;
957 }
958
959 // If structDecl is a forward declaration, this loop won't do
960 // anything except look at designated initializers; That's okay,
961 // because an error should get printed out elsewhere. It might be
962 // worthwhile to skip over the rest of the initializer, though.
963 RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
964 RecordDecl::field_iterator FieldEnd = RD->field_end(SemaRef.Context);
964 RecordDecl::field_iterator FieldEnd = RD->field_end();
965 bool InitializedSomething = false;
966 while (Index < IList->getNumInits()) {
967 Expr *Init = IList->getInit(Index);
968
969 if (DesignatedInitExpr *DIE = dyn_cast<DesignatedInitExpr>(Init)) {
970 // If we're not the subobject that matches up with the '{' for
971 // the designator, we shouldn't be handling the
972 // designator. Return immediately.

--- 112 unchanged lines hidden (view full) ---

1085 // Expand the current designator into the set of replacement
1086 // designators, so we have a full subobject path down to where the
1087 // member of the anonymous struct/union is actually stored.
1088 DIE->ExpandDesignator(DesigIdx, &Replacements[0],
1089 &Replacements[0] + Replacements.size());
1090
1091 // Update FieldIter/FieldIndex;
1092 RecordDecl *Record = cast<RecordDecl>(Path.back()->getDeclContext());
965 bool InitializedSomething = false;
966 while (Index < IList->getNumInits()) {
967 Expr *Init = IList->getInit(Index);
968
969 if (DesignatedInitExpr *DIE = dyn_cast<DesignatedInitExpr>(Init)) {
970 // If we're not the subobject that matches up with the '{' for
971 // the designator, we shouldn't be handling the
972 // designator. Return immediately.

--- 112 unchanged lines hidden (view full) ---

1085 // Expand the current designator into the set of replacement
1086 // designators, so we have a full subobject path down to where the
1087 // member of the anonymous struct/union is actually stored.
1088 DIE->ExpandDesignator(DesigIdx, &Replacements[0],
1089 &Replacements[0] + Replacements.size());
1090
1091 // Update FieldIter/FieldIndex;
1092 RecordDecl *Record = cast<RecordDecl>(Path.back()->getDeclContext());
1093 FieldIter = Record->field_begin(SemaRef.Context);
1093 FieldIter = Record->field_begin();
1094 FieldIndex = 0;
1094 FieldIndex = 0;
1095 for (RecordDecl::field_iterator FEnd = Record->field_end(SemaRef.Context);
1095 for (RecordDecl::field_iterator FEnd = Record->field_end();
1096 FieldIter != FEnd; ++FieldIter) {
1097 if (FieldIter->isUnnamedBitfield())
1098 continue;
1099
1100 if (*FieldIter == Path.back())
1101 return;
1102
1103 ++FieldIndex;

--- 108 unchanged lines hidden (view full) ---

1212
1213 // Note: we perform a linear search of the fields here, despite
1214 // the fact that we have a faster lookup method, because we always
1215 // need to compute the field's index.
1216 FieldDecl *KnownField = D->getField();
1217 IdentifierInfo *FieldName = D->getFieldName();
1218 unsigned FieldIndex = 0;
1219 RecordDecl::field_iterator
1096 FieldIter != FEnd; ++FieldIter) {
1097 if (FieldIter->isUnnamedBitfield())
1098 continue;
1099
1100 if (*FieldIter == Path.back())
1101 return;
1102
1103 ++FieldIndex;

--- 108 unchanged lines hidden (view full) ---

1212
1213 // Note: we perform a linear search of the fields here, despite
1214 // the fact that we have a faster lookup method, because we always
1215 // need to compute the field's index.
1216 FieldDecl *KnownField = D->getField();
1217 IdentifierInfo *FieldName = D->getFieldName();
1218 unsigned FieldIndex = 0;
1219 RecordDecl::field_iterator
1220 Field = RT->getDecl()->field_begin(SemaRef.Context),
1221 FieldEnd = RT->getDecl()->field_end(SemaRef.Context);
1220 Field = RT->getDecl()->field_begin(),
1221 FieldEnd = RT->getDecl()->field_end();
1222 for (; Field != FieldEnd; ++Field) {
1223 if (Field->isUnnamedBitfield())
1224 continue;
1225
1226 if (KnownField == *Field || Field->getIdentifier() == FieldName)
1227 break;
1228
1229 ++FieldIndex;
1230 }
1231
1232 if (Field == FieldEnd) {
1233 // There was no normal field in the struct with the designated
1234 // name. Perform another lookup for this name, which may find
1235 // something that we can't designate (e.g., a member function),
1236 // may find nothing, or may find a member of an anonymous
1237 // struct/union.
1222 for (; Field != FieldEnd; ++Field) {
1223 if (Field->isUnnamedBitfield())
1224 continue;
1225
1226 if (KnownField == *Field || Field->getIdentifier() == FieldName)
1227 break;
1228
1229 ++FieldIndex;
1230 }
1231
1232 if (Field == FieldEnd) {
1233 // There was no normal field in the struct with the designated
1234 // name. Perform another lookup for this name, which may find
1235 // something that we can't designate (e.g., a member function),
1236 // may find nothing, or may find a member of an anonymous
1237 // struct/union.
1238 DeclContext::lookup_result Lookup
1239 = RT->getDecl()->lookup(SemaRef.Context, FieldName);
1238 DeclContext::lookup_result Lookup = RT->getDecl()->lookup(FieldName);
1240 if (Lookup.first == Lookup.second) {
1241 // Name lookup didn't find anything.
1242 SemaRef.Diag(D->getFieldLoc(), diag::err_field_designator_unknown)
1243 << FieldName << CurrentObjectType;
1244 ++Index;
1245 return true;
1246 } else if (!KnownField && isa<FieldDecl>(*Lookup.first) &&
1247 cast<RecordDecl>((*Lookup.first)->getDeclContext())

--- 312 unchanged lines hidden (view full) ---

1560 }
1561 } else if (const VectorType *VType = CurrentObjectType->getAsVectorType())
1562 NumElements = VType->getNumElements();
1563 else if (const RecordType *RType = CurrentObjectType->getAsRecordType()) {
1564 RecordDecl *RDecl = RType->getDecl();
1565 if (RDecl->isUnion())
1566 NumElements = 1;
1567 else
1239 if (Lookup.first == Lookup.second) {
1240 // Name lookup didn't find anything.
1241 SemaRef.Diag(D->getFieldLoc(), diag::err_field_designator_unknown)
1242 << FieldName << CurrentObjectType;
1243 ++Index;
1244 return true;
1245 } else if (!KnownField && isa<FieldDecl>(*Lookup.first) &&
1246 cast<RecordDecl>((*Lookup.first)->getDeclContext())

--- 312 unchanged lines hidden (view full) ---

1559 }
1560 } else if (const VectorType *VType = CurrentObjectType->getAsVectorType())
1561 NumElements = VType->getNumElements();
1562 else if (const RecordType *RType = CurrentObjectType->getAsRecordType()) {
1563 RecordDecl *RDecl = RType->getDecl();
1564 if (RDecl->isUnion())
1565 NumElements = 1;
1566 else
1568 NumElements = std::distance(RDecl->field_begin(SemaRef.Context),
1569 RDecl->field_end(SemaRef.Context));
1567 NumElements = std::distance(RDecl->field_begin(),
1568 RDecl->field_end());
1570 }
1571
1572 if (NumElements < NumInits)
1573 NumElements = IList->getNumInits();
1574
1575 Result->reserveInits(NumElements);
1576
1577 // Link this new initializer list into the structured initializer

--- 206 unchanged lines hidden ---
1569 }
1570
1571 if (NumElements < NumInits)
1572 NumElements = IList->getNumInits();
1573
1574 Result->reserveInits(NumElements);
1575
1576 // Link this new initializer list into the structured initializer

--- 206 unchanged lines hidden ---